aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-05-31 13:28:37 +0800
committerGitHub <noreply@github.com>2018-05-31 13:28:37 +0800
commitae47da3801634a17eb25e658272f60528cc06ead (patch)
tree803e4cbaf892092ad9c62e4d4539fc6fcf85c085 /packages/contracts
parent5b31d0aa3635ea524fb42d73cd6c713887dfef6a (diff)
parenta6d669453f9af7993bdd132862fa5d2da18a62f7 (diff)
downloaddexon-sol-tools-ae47da3801634a17eb25e658272f60528cc06ead.tar
dexon-sol-tools-ae47da3801634a17eb25e658272f60528cc06ead.tar.gz
dexon-sol-tools-ae47da3801634a17eb25e658272f60528cc06ead.tar.bz2
dexon-sol-tools-ae47da3801634a17eb25e658272f60528cc06ead.tar.lz
dexon-sol-tools-ae47da3801634a17eb25e658272f60528cc06ead.tar.xz
dexon-sol-tools-ae47da3801634a17eb25e658272f60528cc06ead.tar.zst
dexon-sol-tools-ae47da3801634a17eb25e658272f60528cc06ead.zip
Merge pull request #640 from 0xProject/await-transaction-success
Add awaitTransactionSuccess where needed
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/utils/token_registry_wrapper.ts14
-rw-r--r--packages/contracts/test/asset_proxy_owner.ts10
-rw-r--r--packages/contracts/test/ether_token.ts5
-rw-r--r--packages/contracts/test/token_registry.ts2
-rw-r--r--packages/contracts/test/unlimited_allowance_token.ts58
5 files changed, 64 insertions, 25 deletions
diff --git a/packages/contracts/src/utils/token_registry_wrapper.ts b/packages/contracts/src/utils/token_registry_wrapper.ts
index 86daeca62..6e3abb26b 100644
--- a/packages/contracts/src/utils/token_registry_wrapper.ts
+++ b/packages/contracts/src/utils/token_registry_wrapper.ts
@@ -1,16 +1,21 @@
-import * as Web3 from 'web3';
+import { Provider } from '@0xproject/types';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { TokenRegistryContract } from '../contract_wrappers/generated/token_registry';
import { Token } from './types';
+import { constants } from './constants';
+
export class TokenRegWrapper {
private _tokenReg: TokenRegistryContract;
- constructor(tokenRegContract: TokenRegistryContract) {
+ private _web3Wrapper: Web3Wrapper;
+ constructor(tokenRegContract: TokenRegistryContract, provider: Provider) {
this._tokenReg = tokenRegContract;
+ this._web3Wrapper = new Web3Wrapper(provider);
}
public async addTokenAsync(token: Token, from: string): Promise<string> {
- const tx = this._tokenReg.addToken.sendTransactionAsync(
+ const txHash = await this._tokenReg.addToken.sendTransactionAsync(
token.address as string,
token.name,
token.symbol,
@@ -19,7 +24,8 @@ export class TokenRegWrapper {
token.swarmHash,
{ from },
);
- return tx;
+ await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
+ return txHash;
}
public async getTokenMetaDataAsync(tokenAddress: string): Promise<Token> {
const data = await this._tokenReg.getTokenMetaData.callAsync(tokenAddress);
diff --git a/packages/contracts/test/asset_proxy_owner.ts b/packages/contracts/test/asset_proxy_owner.ts
index 43c5da512..f95679e20 100644
--- a/packages/contracts/test/asset_proxy_owner.ts
+++ b/packages/contracts/test/asset_proxy_owner.ts
@@ -66,8 +66,14 @@ describe('AssetProxyOwner', () => {
SECONDS_TIME_LOCKED,
);
multiSigWrapper = new MultiSigWrapper(multiSig, provider);
- await erc20Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner });
- await erc721Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner });
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts
index 10dd635fe..4e52b658f 100644
--- a/packages/contracts/test/ether_token.ts
+++ b/packages/contracts/test/ether_token.ts
@@ -83,7 +83,10 @@ describe('EtherToken', () => {
it('should convert ether tokens to ether with sufficient balance', async () => {
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
- await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit });
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
const initEthTokenBalance = await etherToken.balanceOf.callAsync(account);
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethTokensToWithdraw = initEthTokenBalance;
diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts
index 7980977c8..64caac387 100644
--- a/packages/contracts/test/token_registry.ts
+++ b/packages/contracts/test/token_registry.ts
@@ -35,7 +35,7 @@ describe('TokenRegistry', () => {
owner = accounts[0];
notOwner = accounts[1];
tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, txDefaults);
- tokenRegWrapper = new TokenRegWrapper(tokenReg);
+ tokenRegWrapper = new TokenRegWrapper(tokenReg, provider);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts
index c68d8bdcf..b2acdebaa 100644
--- a/packages/contracts/test/unlimited_allowance_token.ts
+++ b/packages/contracts/test/unlimited_allowance_token.ts
@@ -64,7 +64,10 @@ describe('UnlimitedAllowanceToken', () => {
const receiver = spender;
const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = new BigNumber(1);
- await token.transfer.sendTransactionAsync(receiver, amountToTransfer, { from: owner });
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.transfer.sendTransactionAsync(receiver, amountToTransfer, { from: owner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
const finalOwnerBalance = await token.balanceOf.callAsync(owner);
const finalReceiverBalance = await token.balanceOf.callAsync(receiver);
@@ -86,7 +89,10 @@ describe('UnlimitedAllowanceToken', () => {
it('should throw if owner has insufficient balance', async () => {
const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance.plus(1);
- await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner });
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
return expect(
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
@@ -121,11 +127,17 @@ describe('UnlimitedAllowanceToken', () => {
const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
- await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner });
- await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
- from: spender,
- gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
- });
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
+ from: spender,
+ gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
const newSpenderAllowance = await token.allowance.callAsync(owner, spender);
expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
@@ -135,11 +147,17 @@ describe('UnlimitedAllowanceToken', () => {
const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
- await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner });
- await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
- from: spender,
- gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
- });
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
+ from: spender,
+ gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
const newOwnerBalance = await token.balanceOf.callAsync(owner);
const newSpenderBalance = await token.balanceOf.callAsync(spender);
@@ -152,11 +170,17 @@ describe('UnlimitedAllowanceToken', () => {
const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
- await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner });
- await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
- from: spender,
- gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
- });
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
+ from: spender,
+ gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
const newSpenderAllowance = await token.allowance.callAsync(owner, spender);
expect(newSpenderAllowance).to.be.bignumber.equal(0);