From 839db68571037f6fff8273aaade6ea0bd14ea8a5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 16 May 2018 14:59:10 +0200 Subject: Fix TSLint rules --- packages/contracts/test/exchange/helpers.ts | 8 ++++---- packages/contracts/test/unlimited_allowance_token.ts | 4 ++-- packages/contracts/test/zrx_token.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 441c1bc28..3ee54ce4d 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -123,21 +123,21 @@ describe('Exchange', () => { }); it('should return true with a valid signature', async () => { - const success = await exchangeWrapper.isValidSignatureAsync(signedOrder); + const isValidSignatureForContract = await exchangeWrapper.isValidSignatureAsync(signedOrder); const orderHashHex = ZeroEx.getOrderHashHex(signedOrder); const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker); expect(isValidSignature).to.be.true(); - expect(success).to.be.true(); + expect(isValidSignatureForContract).to.be.true(); }); it('should return false with an invalid signature', async () => { signedOrder.ecSignature.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR')); signedOrder.ecSignature.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS')); - const success = await exchangeWrapper.isValidSignatureAsync(signedOrder); + const isValidSignatureForContract = await exchangeWrapper.isValidSignatureAsync(signedOrder); const orderHashHex = ZeroEx.getOrderHashHex(signedOrder); const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker); expect(isValidSignature).to.be.false(); - expect(success).to.be.false(); + expect(isValidSignatureForContract).to.be.false(); }); }); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index da2e5fb5b..754efd256 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -99,8 +99,8 @@ describe('UnlimitedAllowanceToken', () => { const amountToTransfer = ownerBalance; const spenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); - const spenderAllowanceIsInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; - expect(spenderAllowanceIsInsufficient).to.be.true(); + const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; + expect(isSpenderAllowanceInsufficient).to.be.true(); return expect( token.transferFrom.callAsync(owner, spender, amountToTransfer, { diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index 0056ed4b5..33132487f 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -117,8 +117,8 @@ describe('ZRXToken', () => { const amountToTransfer = ownerBalance; const spenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); - const spenderAllowanceIsInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; - expect(spenderAllowanceIsInsufficient).to.be.true(); + const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; + expect(isSpenderAllowanceInsufficient).to.be.true(); const didReturnTrue = await zrx.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender }); expect(didReturnTrue).to.be.false(); -- cgit v1.2.3 From 4ca8903a21d5a78ace5bff3fc5bbc917e369cbfe Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 21 May 2018 16:09:07 -0700 Subject: Add missing blockchainLifecycle calls to contracts tests --- packages/contracts/test/asset_proxy/authorizable.ts | 6 ++++++ packages/contracts/test/asset_proxy/proxies.ts | 6 ++++++ packages/contracts/test/ether_token.ts | 7 +++++++ packages/contracts/test/exchange/core.ts | 6 ++++++ packages/contracts/test/exchange/dispatcher.ts | 6 ++++++ packages/contracts/test/exchange/libs.ts | 6 ++++++ packages/contracts/test/exchange/signature_validator.ts | 6 ++++++ packages/contracts/test/exchange/transactions.ts | 6 ++++++ packages/contracts/test/exchange/wrapper.ts | 6 ++++++ packages/contracts/test/libraries/lib_bytes.ts | 6 ++++++ packages/contracts/test/multi_sig_with_time_lock.ts | 12 ++++++++++++ packages/contracts/test/token_registry.ts | 6 ++++++ packages/contracts/test/unlimited_allowance_token.ts | 6 ++++++ packages/contracts/test/zrx_token.ts | 6 ++++++ 14 files changed, 91 insertions(+) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 636b9096b..bbdcfb742 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -19,6 +19,12 @@ describe('Authorizable', () => { let notOwner: string; let address: string; let authorizable: MixinAuthorizableContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = address = accounts[0]; diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index e7ef9a0d3..e64482c8f 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -39,6 +39,12 @@ describe('Asset Transfer Proxies', () => { let zeroEx: ZeroEx; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, notAuthorized, exchangeAddress, makerAddress, takerAddress] = accounts); diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 418fbc45e..4c647bbc7 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -20,6 +20,13 @@ describe('EtherToken', () => { const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9); let zeroEx: ZeroEx; let etherTokenAddress: string; + + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index be3252800..f4d83d07d 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -61,6 +61,12 @@ describe('Exchange core', () => { let zeroEx: ZeroEx; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index db2f18ddc..5713a0b4f 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -36,6 +36,12 @@ describe('AssetProxyDispatcher', () => { let erc20Wrapper: ERC20Wrapper; let erc721Wrapper: ERC721Wrapper; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { // Setup accounts & addresses const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index 1036cb815..883de7a12 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -25,6 +25,12 @@ describe('Exchange libs', () => { let orderFactory: OrderFactory; let libs: TestLibsContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index 489ed32c5..b918cef60 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -25,6 +25,12 @@ describe('MixinSignatureValidator', () => { let orderFactory: OrderFactory; let signatureValidator: TestSignatureValidatorContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 482475554..c98a3dee5 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -61,6 +61,12 @@ describe('Exchange transactions', () => { let zeroEx: ZeroEx; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 0b79308dd..099f6b656 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -56,6 +56,12 @@ describe('Exchange wrappers', () => { let zeroEx: ZeroEx; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 5ed5c356f..a468255e9 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -32,6 +32,12 @@ describe('LibBytes', () => { const testBytes32 = '0x102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f01020'; const testUint256 = new BigNumber(testBytes32, 16); + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { // Setup accounts & addresses const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 8e58006ac..784f41d24 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -45,6 +45,12 @@ describe('MultiSigWalletWithTimeLock', () => { describe('changeTimeLock', () => { describe('initially non-time-locked', async () => { + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before('deploy a wallet', async () => { multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLock, @@ -140,6 +146,12 @@ describe('MultiSigWalletWithTimeLock', () => { }); }); describe('initially time-locked', async () => { + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before('deploy a wallet', async () => { multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLock, diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 9e4f7ca3b..c14f64184 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -24,6 +24,12 @@ describe('TokenRegistry', () => { let notOwner: string; let tokenReg: TokenRegistryContract; let tokenRegWrapper: TokenRegWrapper; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 8851a04ef..6b79301bb 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -27,6 +27,12 @@ describe('UnlimitedAllowanceToken', () => { let tokenAddress: string; let token: DummyERC20TokenContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index 7a72f85dc..52322983f 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -26,6 +26,12 @@ describe('ZRXToken', () => { let zrxToken: ZRXTokenContract; let zrxAddress: string; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; -- cgit v1.2.3 From 2c496a92adaef4132f6b0a135e61bad7b26b18bd Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 21 May 2018 16:39:07 -0700 Subject: Add awaitTransactionMinedAsync after every sent transaction --- .../contracts/test/asset_proxy/authorizable.ts | 47 ++++-- packages/contracts/test/asset_proxy/proxies.ts | 85 +++++++---- packages/contracts/test/exchange/core.ts | 54 ++++--- packages/contracts/test/exchange/dispatcher.ts | 163 +++++++++++++-------- packages/contracts/test/exchange/transactions.ts | 5 +- packages/contracts/test/exchange/wrapper.ts | 54 ++++--- .../contracts/test/multi_sig_with_time_lock.ts | 12 +- packages/contracts/test/token_registry.ts | 23 ++- .../contracts/test/unlimited_allowance_token.ts | 5 +- 9 files changed, 293 insertions(+), 155 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index bbdcfb742..52e9ea87f 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -48,12 +48,18 @@ describe('Authorizable', () => { ).to.be.rejectedWith(constants.REVERT); }); it('should allow owner to add an authorized address', async () => { - await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); + await web3Wrapper.awaitTransactionMinedAsync( + await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const isAuthorized = await authorizable.authorized.callAsync(address); expect(isAuthorized).to.be.true(); }); it('should throw if owner attempts to authorize a duplicate address', async () => { - await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); + await web3Wrapper.awaitTransactionMinedAsync( + await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); return expect( authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), ).to.be.rejectedWith(constants.REVERT); @@ -62,7 +68,10 @@ describe('Authorizable', () => { describe('removeAuthorizedAddress', () => { it('should throw if not called by owner', async () => { - await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); + await web3Wrapper.awaitTransactionMinedAsync( + await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); return expect( authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: notOwner, @@ -71,10 +80,16 @@ describe('Authorizable', () => { }); it('should allow owner to remove an authorized address', async () => { - await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); - await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionMinedAsync( + await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const isAuthorized = await authorizable.authorized.callAsync(address); expect(isAuthorized).to.be.false(); }); @@ -92,16 +107,22 @@ describe('Authorizable', () => { it('should return all authorized addresses', async () => { const initial = await authorizable.getAuthorizedAddresses.callAsync(); expect(initial).to.have.length(0); - await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const afterAdd = await authorizable.getAuthorizedAddresses.callAsync(); expect(afterAdd).to.have.length(1); expect(afterAdd).to.include(address); - await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const afterRemove = await authorizable.getAuthorizedAddresses.callAsync(); expect(afterRemove).to.have.length(0); }); diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index e64482c8f..27b7f3049 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -55,18 +55,24 @@ describe('Asset Transfer Proxies', () => { [zrxToken] = await erc20Wrapper.deployDummyTokensAsync(); erc20Proxy = await erc20Wrapper.deployProxyAsync(); await erc20Wrapper.setBalancesAndAllowancesAsync(); - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); [erc721Token] = await erc721Wrapper.deployDummyTokensAsync(); erc721Proxy = await erc721Wrapper.deployProxyAsync(); await erc721Wrapper.setBalancesAndAllowancesAsync(); const erc721Balances = await erc721Wrapper.getBalancesAsync(); erc721MakerTokenId = erc721Balances[makerAddress][erc721Token.address][0]; - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID, @@ -86,12 +92,15 @@ describe('Asset Transfer Proxies', () => { // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(10); - await erc20Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, - makerAddress, - takerAddress, - amount, - { from: exchangeAddress }, + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.transferFrom.sendTransactionAsync( + encodedProxyMetadata, + makerAddress, + takerAddress, + amount, + { from: exchangeAddress }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); // Verify transfer was successful const newBalances = await erc20Wrapper.getBalancesAsync(); @@ -109,12 +118,15 @@ describe('Asset Transfer Proxies', () => { // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(0); - await erc20Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, - makerAddress, - takerAddress, - amount, - { from: exchangeAddress }, + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.transferFrom.sendTransactionAsync( + encodedProxyMetadata, + makerAddress, + takerAddress, + amount, + { from: exchangeAddress }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); // Verify transfer was successful const newBalances = await erc20Wrapper.getBalancesAsync(); @@ -132,9 +144,12 @@ describe('Asset Transfer Proxies', () => { // Create allowance less than transfer amount. Set allowance on proxy. const allowance = new BigNumber(0); const transferAmount = new BigNumber(10); - await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, allowance, { - from: makerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, allowance, { + from: makerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); // Perform a transfer; expect this to fail. return expect( erc20Proxy.transferFrom.sendTransactionAsync( @@ -185,7 +200,7 @@ describe('Asset Transfer Proxies', () => { amounts, { from: exchangeAddress }, ); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const newBalances = await erc20Wrapper.getBalancesAsync(); expect(res.logs.length).to.equal(numTransfers); @@ -238,12 +253,15 @@ describe('Asset Transfer Proxies', () => { // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(1); - await erc721Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, - makerAddress, - takerAddress, - amount, - { from: exchangeAddress }, + await web3Wrapper.awaitTransactionMinedAsync( + await erc721Proxy.transferFrom.sendTransactionAsync( + encodedProxyMetadata, + makerAddress, + takerAddress, + amount, + { from: exchangeAddress }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); // Verify transfer was successful const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); @@ -303,9 +321,12 @@ describe('Asset Transfer Proxies', () => { erc721MakerTokenId, ); // Remove transfer approval for makerAddress. - await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, false, { - from: makerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, false, { + from: makerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); // Perform a transfer; expect this to fail. const amount = new BigNumber(1); return expect( @@ -362,7 +383,7 @@ describe('Asset Transfer Proxies', () => { amounts, { from: exchangeAddress }, ); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); expect(res.logs.length).to.equal(numTransfers); const newOwnerMakerAssetA = await erc721Token.ownerOf.callAsync(makerTokenIdA); diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index f4d83d07d..3b40ed652 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -99,12 +99,18 @@ describe('Exchange core', () => { await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }); - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionMinedAsync( + await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); defaultMakerAssetAddress = erc20TokenA.address; defaultTakerAssetAddress = erc20TokenB.address; @@ -526,23 +532,35 @@ describe('Exchange core', () => { }); it('should throw if maker allowances are too low to fill order', async () => { - await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { - from: makerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { + from: makerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT); - await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { - from: makerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { + from: makerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); }); it('should throw if taker allowances are too low to fill order', async () => { - await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { - from: takerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { + from: takerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT); - await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { - from: takerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { + from: takerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); }); it('should not change erc20Balances if an order is expired', async () => { diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index 5713a0b4f..a1c37d8c8 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -62,12 +62,18 @@ describe('AssetProxyDispatcher', () => { provider, txDefaults, ); - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, { - from: owner, - }); - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionMinedAsync( + await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -78,11 +84,14 @@ describe('AssetProxyDispatcher', () => { describe('registerAssetProxy', () => { it('should record proxy upon registration', async () => { const prevProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - erc20Proxy.address, - prevProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + erc20Proxy.address, + prevProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); @@ -91,21 +100,27 @@ describe('AssetProxyDispatcher', () => { it('should be able to record multiple proxies', async () => { // Record first proxy const prevERC20ProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - erc20Proxy.address, - prevERC20ProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + erc20Proxy.address, + prevERC20ProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); // Record another proxy const prevERC721ProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC721, - erc721Proxy.address, - prevERC721ProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC721, + erc721Proxy.address, + prevERC721ProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC721); expect(proxyAddress).to.be.equal(erc721Proxy.address); @@ -114,11 +129,14 @@ describe('AssetProxyDispatcher', () => { it('should replace proxy address upon re-registration', async () => { // Initial registration const prevProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - erc20Proxy.address, - prevProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + erc20Proxy.address, + prevProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); @@ -131,11 +149,14 @@ describe('AssetProxyDispatcher', () => { // Register new ERC20 Transfer Proxy contract const newAddress = newErc20TransferProxy.address; const currentAddress = erc20Proxy.address; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - newAddress, - currentAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + newAddress, + currentAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); // Verify new asset proxy has replaced initial version proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); @@ -145,11 +166,14 @@ describe('AssetProxyDispatcher', () => { it('should throw if registering with incorrect "currentAssetProxyAddress" field', async () => { // Initial registration const prevProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - erc20Proxy.address, - prevProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + erc20Proxy.address, + prevProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); @@ -167,21 +191,27 @@ describe('AssetProxyDispatcher', () => { it('should be able to reset proxy address to NULL', async () => { // Initial registration const prevProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - erc20Proxy.address, - prevProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + erc20Proxy.address, + prevProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); // The following transaction will reset the proxy address const newProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - newProxyAddress, - erc20Proxy.address, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + newProxyAddress, + erc20Proxy.address, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); const finalProxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(finalProxyAddress).to.be.equal(newProxyAddress); @@ -215,11 +245,14 @@ describe('AssetProxyDispatcher', () => { describe('getAssetProxy', () => { it('should return correct address of registered proxy', async () => { const prevProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - erc20Proxy.address, - prevProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + erc20Proxy.address, + prevProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); @@ -235,23 +268,29 @@ describe('AssetProxyDispatcher', () => { it('should dispatch transfer to registered proxy', async () => { // Register ERC20 proxy const prevProxyAddress = ZeroEx.NULL_ADDRESS; - await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( - AssetProxyId.ERC20, - erc20Proxy.address, - prevProxyAddress, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( + AssetProxyId.ERC20, + erc20Proxy.address, + prevProxyAddress, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); // Construct metadata for ERC20 proxy const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(10); - await assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync( - encodedProxyMetadata, - makerAddress, - takerAddress, - amount, - { from: owner }, + await web3Wrapper.awaitTransactionMinedAsync( + await assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync( + encodedProxyMetadata, + makerAddress, + takerAddress, + amount, + { from: owner }, + ), + constants.AWAIT_TRANSACTION_MINED_MS, ); // Verify transfer was successful const newBalances = await erc20Wrapper.getBalancesAsync(); diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index c98a3dee5..798c8283b 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -90,7 +90,10 @@ describe('Exchange transactions', () => { exchangeWrapper = new ExchangeWrapper(exchange, zeroEx); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); defaultMakerTokenAddress = erc20TokenA.address; defaultTakerTokenAddress = erc20TokenB.address; diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 099f6b656..caaceb460 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -94,12 +94,18 @@ describe('Exchange wrappers', () => { await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }); - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionMinedAsync( + await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); defaultMakerAssetAddress = erc20TokenA.address; defaultTakerAssetAddress = erc20TokenB.address; @@ -257,13 +263,19 @@ describe('Exchange wrappers', () => { it('should not change erc20Balances if maker allowances are too low to fill order', async () => { const signedOrder = orderFactory.newSignedOrder(); - await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { - from: makerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { + from: makerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); - await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { - from: makerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { + from: makerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const newBalances = await erc20Wrapper.getBalancesAsync(); expect(newBalances).to.be.deep.equal(erc20Balances); @@ -271,13 +283,19 @@ describe('Exchange wrappers', () => { it('should not change erc20Balances if taker allowances are too low to fill order', async () => { const signedOrder = orderFactory.newSignedOrder(); - await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { - from: takerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { + from: takerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); - await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { - from: takerAddress, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { + from: takerAddress, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const newBalances = await erc20Wrapper.getBalancesAsync(); expect(newBalances).to.be.deep.equal(erc20Balances); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 784f41d24..e467df0d7 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -107,7 +107,7 @@ describe('MultiSigWalletWithTimeLock', () => { txId = log.args.transactionId; txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] }); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); expect(res.logs).to.have.length(2); const blockNum = await web3Wrapper.getBlockNumberAsync(); @@ -134,10 +134,12 @@ describe('MultiSigWalletWithTimeLock', () => { txId = log.args.transactionId; txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] }); + await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); expect(initialSecondsTimeLocked).to.be.equal(0); txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); + await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const res = await zeroEx.awaitTransactionMinedAsync(txHash); expect(res.logs).to.have.length(2); @@ -181,7 +183,8 @@ describe('MultiSigWalletWithTimeLock', () => { txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1], }); - const confRes = await zeroEx.awaitTransactionMinedAsync(txHash); + await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + const confRes = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); expect(confRes.logs).to.have.length(2); }); const newSecondsTimeLocked = 0; @@ -193,7 +196,10 @@ describe('MultiSigWalletWithTimeLock', () => { it('should execute if it has enough confirmations and is past the time lock', async () => { await web3Wrapper.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber()); - await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); + await web3Wrapper.awaitTransactionMinedAsync( + await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync()); expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked); diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index c14f64184..308dee8e6 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -143,9 +143,12 @@ describe('TokenRegistry', () => { }); it('should change the token name when called by owner', async () => { - await tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const [newData, oldData] = await Promise.all([ tokenRegWrapper.getTokenByNameAsync(token2.name), tokenRegWrapper.getTokenByNameAsync(token1.name), @@ -182,7 +185,10 @@ describe('TokenRegistry', () => { }); it('should change the token symbol when called by owner', async () => { - await tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, { from: owner }); + await web3Wrapper.awaitTransactionMinedAsync( + await tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const [newData, oldData] = await Promise.all([ tokenRegWrapper.getTokenBySymbolAsync(token2.symbol), tokenRegWrapper.getTokenBySymbolAsync(token1.symbol), @@ -223,9 +229,12 @@ describe('TokenRegistry', () => { it('should remove token metadata when called by owner', async () => { const index = new BigNumber(0); - await tokenReg.removeToken.sendTransactionAsync(token1.address, index, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await tokenReg.removeToken.sendTransactionAsync(token1.address, index, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const tokenData = await tokenRegWrapper.getTokenMetaDataAsync(token1.address); expect(tokenData).to.be.deep.equal(nullToken); }); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 6b79301bb..dfca09175 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -46,7 +46,10 @@ describe('UnlimitedAllowanceToken', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); - await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner }); + await web3Wrapper.awaitTransactionMinedAsync( + await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); tokenAddress = token.address; }); beforeEach(async () => { -- cgit v1.2.3 From 4fa57f55e640d94099a9047cb23b5a003dc69068 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 21 May 2018 16:51:43 -0700 Subject: Fix some unhandled promise rejections --- packages/contracts/test/asset_proxy/proxies.ts | 4 ++-- packages/contracts/test/exchange/core.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index 27b7f3049..0f3080c99 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -221,7 +221,7 @@ describe('Asset Transfer Proxies', () => { const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => amount); - expect( + return expect( erc20Proxy.batchTransferFrom.sendTransactionAsync( assetMetadata, fromAddresses, @@ -405,7 +405,7 @@ describe('Asset Transfer Proxies', () => { const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => new BigNumber(1)); - expect( + return expect( erc721Proxy.batchTransferFrom.sendTransactionAsync( assetMetadata, fromAddresses, diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 3b40ed652..1edd44aff 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -538,7 +538,9 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); - expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT); + await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( + constants.REVERT, + ); await web3Wrapper.awaitTransactionMinedAsync( await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { from: makerAddress, @@ -554,7 +556,9 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); - expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT); + await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( + constants.REVERT, + ); await web3Wrapper.awaitTransactionMinedAsync( await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { from: takerAddress, -- cgit v1.2.3 From a5d315ee2adac392875439f4902491559ad98c8b Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 21 May 2018 16:58:29 -0700 Subject: Apply changes to test/exchange/match_orders.ts --- packages/contracts/test/exchange/match_orders.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 94cdf4598..b08b9e763 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -78,6 +78,12 @@ describe('matchOrders', () => { let zeroEx: ZeroEx; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { // Create accounts const accounts = await web3Wrapper.getAvailableAddressesAsync(); @@ -119,12 +125,18 @@ describe('matchOrders', () => { await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); // Authorize ERC20 and ERC721 trades by exchange - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }); - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }); + await web3Wrapper.awaitTransactionMinedAsync( + await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionMinedAsync( + await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); // Set default addresses defaultERC20MakerAssetAddress = erc20TokenA.address; defaultERC20TakerAssetAddress = erc20TokenB.address; -- cgit v1.2.3 From 1dad14f8ea0e463a699d5b2d5f8ccd9532b2ef19 Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Tue, 22 May 2018 13:50:07 +0200 Subject: Add missing return types --- packages/contracts/test/utils/match_order_tester.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/utils/match_order_tester.ts b/packages/contracts/test/utils/match_order_tester.ts index 14930de08..da311e6ea 100644 --- a/packages/contracts/test/utils/match_order_tester.ts +++ b/packages/contracts/test/utils/match_order_tester.ts @@ -55,7 +55,7 @@ export class MatchOrderTester { realERC20BalancesByOwner: ERC20BalancesByOwner, expectedNewERC721TokenIdsByOwner: ERC721TokenIdsByOwner, realERC721TokenIdsByOwner: ERC721TokenIdsByOwner, - ) { + ): boolean { // ERC20 Balances const erc20BalancesMatch = _.isEqual(expectedNewERC20BalancesByOwner, realERC20BalancesByOwner); if (!erc20BalancesMatch) { -- cgit v1.2.3 From 187fa71526148bbfb7a16229ef88c5d7726a2e0d Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 22 May 2018 10:53:46 -0700 Subject: Remove extra awaitTransactionMinedAsync calls --- packages/contracts/test/multi_sig_with_time_lock.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index e467df0d7..8e7589afd 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -127,7 +127,7 @@ describe('MultiSigWalletWithTimeLock', () => { args: [SECONDS_TIME_LOCKED.toNumber()], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); + const subRes = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; @@ -139,8 +139,7 @@ describe('MultiSigWalletWithTimeLock', () => { expect(initialSecondsTimeLocked).to.be.equal(0); txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); - await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); expect(res.logs).to.have.length(2); const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync()); @@ -183,7 +182,6 @@ describe('MultiSigWalletWithTimeLock', () => { txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1], }); - await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const confRes = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); expect(confRes.logs).to.have.length(2); }); -- cgit v1.2.3 From e26c0c58aeb435e4fbec1b111b77d51b67dacdbe Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 22 May 2018 11:02:29 -0700 Subject: Rename some variables in multi_sig_with_time_lock.ts --- packages/contracts/test/multi_sig_with_time_lock.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 8e7589afd..3f61005e7 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -80,8 +80,8 @@ describe('MultiSigWalletWithTimeLock', () => { args: [SECONDS_TIME_LOCKED.toNumber()], }; const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); - const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< + const txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash); + const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; @@ -100,8 +100,8 @@ describe('MultiSigWalletWithTimeLock', () => { args: [SECONDS_TIME_LOCKED.toNumber()], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); - const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< + const txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash); + const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; @@ -127,8 +127,8 @@ describe('MultiSigWalletWithTimeLock', () => { args: [SECONDS_TIME_LOCKED.toNumber()], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); - const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< + const txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; @@ -174,16 +174,16 @@ describe('MultiSigWalletWithTimeLock', () => { args: [newSecondsTimeLocked], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); - const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< + let txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash); + const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; txId = log.args.transactionId; txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1], }); - const confRes = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); - expect(confRes.logs).to.have.length(2); + txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + expect(txReceipt.logs).to.have.length(2); }); const newSecondsTimeLocked = 0; it('should throw if it has enough confirmations but is not past the time lock', async () => { -- cgit v1.2.3 From a682b5d90e4c651e4e5d5d7c700237a9b6fe22bf Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 11:18:50 -0700 Subject: Remove 0x.js dep from contracts --- packages/contracts/test/asset_proxy/proxies.ts | 11 +- packages/contracts/test/ether_token.ts | 7 +- packages/contracts/test/exchange/core.ts | 51 +++---- packages/contracts/test/exchange/dispatcher.ts | 29 ++-- packages/contracts/test/exchange/libs.ts | 2 - packages/contracts/test/exchange/match_orders.ts | 163 ++++++++++----------- .../contracts/test/exchange/signature_validator.ts | 2 - packages/contracts/test/exchange/transactions.ts | 12 +- packages/contracts/test/exchange/wrapper.ts | 37 ++--- packages/contracts/test/libraries/lib_bytes.ts | 2 +- .../contracts/test/multi_sig_with_time_lock.ts | 17 +-- packages/contracts/test/token_registry.ts | 3 +- packages/contracts/test/tutorials/arbitrage.ts | 4 +- .../contracts/test/unlimited_allowance_token.ts | 50 +++---- .../contracts/test/utils/match_order_tester.ts | 2 +- packages/contracts/test/zrx_token.ts | 56 +++---- 16 files changed, 208 insertions(+), 240 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index e7ef9a0d3..3c72968d3 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -1,4 +1,3 @@ -import { ZeroEx } from '0x.js'; import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -37,8 +36,6 @@ describe('Asset Transfer Proxies', () => { let erc721Wrapper: ERC721Wrapper; let erc721MakerTokenId: BigNumber; - let zeroEx: ZeroEx; - before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, notAuthorized, exchangeAddress, makerAddress, takerAddress] = accounts); @@ -61,10 +58,6 @@ describe('Asset Transfer Proxies', () => { await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, { from: owner, }); - - zeroEx = new ZeroEx(provider, { - networkId: constants.TESTRPC_NETWORK_ID, - }); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -179,7 +172,7 @@ describe('Asset Transfer Proxies', () => { amounts, { from: exchangeAddress }, ); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); const newBalances = await erc20Wrapper.getBalancesAsync(); expect(res.logs.length).to.equal(numTransfers); @@ -356,7 +349,7 @@ describe('Asset Transfer Proxies', () => { amounts, { from: exchangeAddress }, ); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); expect(res.logs.length).to.equal(numTransfers); const newOwnerMakerAssetA = await erc721Token.ownerOf.callAsync(makerTokenIdA); diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 418fbc45e..a71d96cb8 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -1,7 +1,8 @@ -import { ContractWrappersError, ZeroEx } from '0x.js'; +import { ContractWrappersError } from '@0xproject/contract-wrappers'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Web3Wrapper } from '@0xproject/web3_wrapper'; import * as chai from 'chai'; import 'make-promises-safe'; @@ -17,7 +18,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('EtherToken', () => { let account: string; - const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9); + const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); let zeroEx: ZeroEx; let etherTokenAddress: string; before(async () => { @@ -103,7 +104,7 @@ describe('EtherToken', () => { const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); + const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18); const txHash = await web3Wrapper.sendTransactionAsync({ from: account, diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index be3252800..a8a402555 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -1,6 +1,7 @@ -import { LogWithDecodedArgs, ZeroEx } from '0x.js'; import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web-wrapper'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import 'make-promises-safe'; @@ -89,7 +90,7 @@ describe('Exchange core', () => { exchangeContractAddress: exchange.address, networkId: constants.TESTRPC_NETWORK_ID, }); - exchangeWrapper = new ExchangeWrapper(exchange, zeroEx); + exchangeWrapper = new ExchangeWrapper(exchange); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); @@ -166,8 +167,8 @@ describe('Exchange core', () => { it('should transfer the correct amounts when makerAssetAmount === takerAssetAmount', async () => { signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), }); const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync( @@ -219,8 +220,8 @@ describe('Exchange core', () => { it('should transfer the correct amounts when makerAssetAmount > takerAssetAmount', async () => { signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), }); const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync( @@ -272,8 +273,8 @@ describe('Exchange core', () => { it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount', async () => { signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), }); const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync( @@ -326,8 +327,8 @@ describe('Exchange core', () => { it('should transfer the correct amounts when taker is specified and order is claimed by taker', async () => { signedOrder = orderFactory.newSignedOrder({ takerAddress, - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), }); const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync( @@ -445,8 +446,8 @@ describe('Exchange core', () => { it('should throw when taker is specified and order is claimed by other', async () => { signedOrder = orderFactory.newSignedOrder({ takerAddress: feeRecipientAddress, - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), }); return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( constants.REVERT, @@ -455,7 +456,7 @@ describe('Exchange core', () => { it('should throw if signature is invalid', async () => { signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), }); const invalidR = ethUtil.sha3('invalidR'); @@ -501,7 +502,7 @@ describe('Exchange core', () => { it('should throw if maker erc20Balances are too low to fill order', async () => { signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( @@ -511,7 +512,7 @@ describe('Exchange core', () => { it('should throw if taker erc20Balances are too low to fill order', async () => { signedOrder = orderFactory.newSignedOrder({ - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( @@ -681,23 +682,23 @@ describe('Exchange core', () => { erc20Balances = await erc20Wrapper.getBalancesAsync(); const signedOrders = await Promise.all([ orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(9), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(9), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(9), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(9), 18), salt: new BigNumber(0), }), orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(79), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(79), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(79), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(79), 18), salt: new BigNumber(1), }), orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(979), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(979), 18), salt: new BigNumber(2), }), orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(7979), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(7979), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(7979), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(7979), 18), salt: new BigNumber(3), }), ]); @@ -873,7 +874,7 @@ describe('Exchange core', () => { const makerAssetId = erc721MakerAssetIds[0]; signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerAssetAddress), }); @@ -913,7 +914,7 @@ describe('Exchange core', () => { const takerAssetId = erc721TakerAssetIds[0]; signedOrder = orderFactory.newSignedOrder({ takerAssetAmount: new BigNumber(1), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerAssetAddress), }); diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index db2f18ddc..3a09eb122 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -1,4 +1,3 @@ -import { ZeroEx } from '0x.js'; import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -71,7 +70,7 @@ describe('AssetProxyDispatcher', () => { }); describe('registerAssetProxy', () => { it('should record proxy upon registration', async () => { - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, @@ -84,7 +83,7 @@ describe('AssetProxyDispatcher', () => { it('should be able to record multiple proxies', async () => { // Record first proxy - const prevERC20ProxyAddress = ZeroEx.NULL_ADDRESS; + const prevERC20ProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, @@ -94,7 +93,7 @@ describe('AssetProxyDispatcher', () => { let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); // Record another proxy - const prevERC721ProxyAddress = ZeroEx.NULL_ADDRESS; + const prevERC721ProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC721, erc721Proxy.address, @@ -107,7 +106,7 @@ describe('AssetProxyDispatcher', () => { it('should replace proxy address upon re-registration', async () => { // Initial registration - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, @@ -138,7 +137,7 @@ describe('AssetProxyDispatcher', () => { it('should throw if registering with incorrect "currentAssetProxyAddress" field', async () => { // Initial registration - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, @@ -147,12 +146,12 @@ describe('AssetProxyDispatcher', () => { ); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); - // The following transaction will throw because the currentAddress is no longer ZeroEx.NULL_ADDRESS + // The following transaction will throw because the currentAddress is no longer constants.NULL_ADDRESS return expect( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, - ZeroEx.NULL_ADDRESS, + constants.NULL_ADDRESS, { from: owner }, ), ).to.be.rejectedWith(constants.REVERT); @@ -160,7 +159,7 @@ describe('AssetProxyDispatcher', () => { it('should be able to reset proxy address to NULL', async () => { // Initial registration - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, @@ -170,7 +169,7 @@ describe('AssetProxyDispatcher', () => { const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); // The following transaction will reset the proxy address - const newProxyAddress = ZeroEx.NULL_ADDRESS; + const newProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, newProxyAddress, @@ -182,7 +181,7 @@ describe('AssetProxyDispatcher', () => { }); it('should throw if requesting address is not owner', async () => { - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; return expect( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, @@ -194,7 +193,7 @@ describe('AssetProxyDispatcher', () => { }); it('should throw if attempting to register a proxy to the incorrect id', async () => { - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; return expect( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC721, @@ -208,7 +207,7 @@ describe('AssetProxyDispatcher', () => { describe('getAssetProxy', () => { it('should return correct address of registered proxy', async () => { - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, @@ -221,14 +220,14 @@ describe('AssetProxyDispatcher', () => { it('should return NULL address if requesting non-existent proxy', async () => { const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); - expect(proxyAddress).to.be.equal(ZeroEx.NULL_ADDRESS); + expect(proxyAddress).to.be.equal(constants.NULL_ADDRESS); }); }); describe('dispatchTransferFrom', () => { it('should dispatch transfer to registered proxy', async () => { // Register ERC20 proxy - const prevProxyAddress = ZeroEx.NULL_ADDRESS; + const prevProxyAddress = constants.NULL_ADDRESS; await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index 1036cb815..9af5916dd 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -1,4 +1,3 @@ -import { ZeroEx } from '0x.js'; import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -29,7 +28,6 @@ describe('Exchange libs', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; libs = await TestLibsContract.deployFrom0xArtifactAsync(artifacts.TestLibs, provider, txDefaults); - const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 94cdf4598..bdf4f54fb 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -1,6 +1,7 @@ -import { LogWithDecodedArgs, ZeroEx } from '0x.js'; import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; @@ -76,8 +77,6 @@ describe('matchOrders', () => { let matchOrderTester: MatchOrderTester; - let zeroEx: ZeroEx; - before(async () => { // Create accounts const accounts = await web3Wrapper.getAvailableAddressesAsync(); @@ -111,11 +110,7 @@ describe('matchOrders', () => { txDefaults, assetProxyUtils.encodeERC20ProxyData(zrxToken.address), ); - zeroEx = new ZeroEx(provider, { - exchangeContractAddress: exchange.address, - networkId: constants.TESTRPC_NETWORK_ID, - }); - exchangeWrapper = new ExchangeWrapper(exchange, zeroEx); + exchangeWrapper = new ExchangeWrapper(exchange); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); // Authorize ERC20 and ERC721 trades by exchange @@ -161,16 +156,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match signedOrderLeft with signedOrderRight @@ -195,16 +190,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Store original taker balance @@ -240,16 +235,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(20), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(4), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(4), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -274,16 +269,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(50), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -308,16 +303,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(50), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -347,8 +342,8 @@ describe('matchOrders', () => { makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(50), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match signedOrderLeft with signedOrderRight2 @@ -377,8 +372,8 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressLeft, }); @@ -386,8 +381,8 @@ describe('matchOrders', () => { makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(50), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -417,8 +412,8 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(50), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), feeRecipientAddress: feeRecipientAddressLeft, }); // Match signedOrderLeft2 with signedOrderRight @@ -450,16 +445,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress, }); // Match orders @@ -478,16 +473,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -507,16 +502,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -536,16 +531,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -565,16 +560,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -594,16 +589,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: makerAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: makerAddressRight, }); // Match orders @@ -622,16 +617,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Cancel left order @@ -648,16 +643,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Cancel right order @@ -674,16 +669,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -704,16 +699,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -734,16 +729,16 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(5), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(2), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders @@ -766,14 +761,14 @@ describe('matchOrders', () => { makerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: new BigNumber(1), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: new BigNumber(1), feeRecipientAddress: feeRecipientAddressRight, }); @@ -800,7 +795,7 @@ describe('matchOrders', () => { makerAddress: makerAddressLeft, makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), takerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: new BigNumber(1), feeRecipientAddress: feeRecipientAddressLeft, }); @@ -809,7 +804,7 @@ describe('matchOrders', () => { makerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), makerAssetAmount: new BigNumber(1), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressRight, }); // Match orders diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index 489ed32c5..7dac28c17 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -1,4 +1,3 @@ -import { ZeroEx } from '0x.js'; import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -33,7 +32,6 @@ describe('MixinSignatureValidator', () => { provider, txDefaults, ); - const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 482475554..cd18b60ed 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -1,5 +1,3 @@ -import { ZeroEx } from '0x.js'; - import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -59,8 +57,6 @@ describe('Exchange transactions', () => { let defaultMakerTokenAddress: string; let defaultTakerTokenAddress: string; - let zeroEx: ZeroEx; - before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts); @@ -77,11 +73,7 @@ describe('Exchange transactions', () => { txDefaults, assetProxyUtils.encodeERC20ProxyData(zrxToken.address), ); - zeroEx = new ZeroEx(provider, { - exchangeContractAddress: exchange.address, - networkId: constants.TESTRPC_NETWORK_ID, - }); - exchangeWrapper = new ExchangeWrapper(exchange, zeroEx); + exchangeWrapper = new ExchangeWrapper(exchange); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }); @@ -179,7 +171,7 @@ describe('Exchange transactions', () => { it('should reset the currentContextAddress', async () => { await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); const currentContextAddress = await exchange.currentContextAddress.callAsync(); - expect(currentContextAddress).to.equal(ZeroEx.NULL_ADDRESS); + expect(currentContextAddress).to.equal(constants.NULL_ADDRESS); }); }); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 0b79308dd..4ff530874 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -1,4 +1,3 @@ -import { ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -54,8 +53,6 @@ describe('Exchange wrappers', () => { let defaultMakerAssetAddress: string; let defaultTakerAssetAddress: string; - let zeroEx: ZeroEx; - before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); @@ -80,11 +77,7 @@ describe('Exchange wrappers', () => { txDefaults, assetProxyUtils.encodeERC20ProxyData(zrxToken.address), ); - zeroEx = new ZeroEx(provider, { - exchangeContractAddress: exchange.address, - networkId: constants.TESTRPC_NETWORK_ID, - }); - exchangeWrapper = new ExchangeWrapper(exchange, zeroEx); + exchangeWrapper = new ExchangeWrapper(exchange); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); @@ -119,8 +112,8 @@ describe('Exchange wrappers', () => { describe('fillOrKillOrder', () => { it('should transfer the correct amounts', async () => { const signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), }); const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2); await exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress, { @@ -187,8 +180,8 @@ describe('Exchange wrappers', () => { describe('fillOrderNoThrow', () => { it('should transfer the correct amounts', async () => { const signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), }); const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, { @@ -231,7 +224,7 @@ describe('Exchange wrappers', () => { it('should not change erc20Balances if maker erc20Balances are too low to fill order', async () => { const signedOrder = orderFactory.newSignedOrder({ - makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), + makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); @@ -241,7 +234,7 @@ describe('Exchange wrappers', () => { it('should not change erc20Balances if taker erc20Balances are too low to fill order', async () => { const signedOrder = orderFactory.newSignedOrder({ - takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); @@ -620,7 +613,7 @@ describe('Exchange wrappers', () => { }); it('should fill all signedOrders if cannot fill entire takerAssetFillAmount', async () => { - const takerAssetFillAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); + const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18); _.forEach(signedOrders, signedOrder => { erc20Balances[makerAddress][defaultMakerAssetAddress] = erc20Balances[makerAddress][ defaultMakerAssetAddress @@ -663,7 +656,7 @@ describe('Exchange wrappers', () => { return expect( exchangeWrapper.marketSellOrdersAsync(signedOrders, takerAddress, { - takerAssetFillAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), + takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), ).to.be.rejectedWith(constants.REVERT); }); @@ -709,7 +702,7 @@ describe('Exchange wrappers', () => { }); it('should fill all signedOrders if cannot fill entire takerAssetFillAmount', async () => { - const takerAssetFillAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); + const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18); _.forEach(signedOrders, signedOrder => { erc20Balances[makerAddress][defaultMakerAssetAddress] = erc20Balances[makerAddress][ defaultMakerAssetAddress @@ -752,7 +745,7 @@ describe('Exchange wrappers', () => { return expect( exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, { - takerAssetFillAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), + takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), ).to.be.rejectedWith(constants.REVERT); }); @@ -798,7 +791,7 @@ describe('Exchange wrappers', () => { }); it('should fill all signedOrders if cannot fill entire makerAssetFillAmount', async () => { - const makerAssetFillAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); + const makerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18); _.forEach(signedOrders, signedOrder => { erc20Balances[makerAddress][defaultMakerAssetAddress] = erc20Balances[makerAddress][ defaultMakerAssetAddress @@ -841,7 +834,7 @@ describe('Exchange wrappers', () => { return expect( exchangeWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, { - makerAssetFillAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), + makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), ).to.be.rejectedWith(constants.REVERT); }); @@ -887,7 +880,7 @@ describe('Exchange wrappers', () => { }); it('should fill all signedOrders if cannot fill entire takerAssetFillAmount', async () => { - const takerAssetFillAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); + const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18); _.forEach(signedOrders, signedOrder => { erc20Balances[makerAddress][defaultMakerAssetAddress] = erc20Balances[makerAddress][ defaultMakerAssetAddress @@ -930,7 +923,7 @@ describe('Exchange wrappers', () => { return expect( exchangeWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, { - makerAssetFillAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), + makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), ).to.be.rejectedWith(constants.REVERT); }); diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 5ed5c356f..d0e553939 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -1,5 +1,5 @@ -import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; +import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import BN = require('bn.js'); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 8e58006ac..771bae8af 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -1,5 +1,5 @@ -import { LogWithDecodedArgs, ZeroEx } from '0x.js'; import { BlockchainLifecycle, web3Factory } from '@0xproject/dev-utils'; +import { LogWithDecodedArgs } from '@0xproject/types'; import { AbiDecoder, BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; @@ -20,7 +20,6 @@ const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLock.compilerOutput.abi; chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); -const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); const abiDecoder = new AbiDecoder([MULTI_SIG_ABI]); describe('MultiSigWalletWithTimeLock', () => { @@ -74,7 +73,7 @@ describe('MultiSigWalletWithTimeLock', () => { args: [SECONDS_TIME_LOCKED.toNumber()], }; const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); + const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; @@ -94,14 +93,14 @@ describe('MultiSigWalletWithTimeLock', () => { args: [SECONDS_TIME_LOCKED.toNumber()], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); + const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; txId = log.args.transactionId; txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] }); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); expect(res.logs).to.have.length(2); const blockNum = await web3Wrapper.getBlockNumberAsync(); @@ -121,7 +120,7 @@ describe('MultiSigWalletWithTimeLock', () => { args: [SECONDS_TIME_LOCKED.toNumber()], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); + const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; @@ -132,7 +131,7 @@ describe('MultiSigWalletWithTimeLock', () => { expect(initialSecondsTimeLocked).to.be.equal(0); txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); - const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); expect(res.logs).to.have.length(2); const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync()); @@ -161,7 +160,7 @@ describe('MultiSigWalletWithTimeLock', () => { args: [newSecondsTimeLocked], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); - const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); + const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; @@ -169,7 +168,7 @@ describe('MultiSigWalletWithTimeLock', () => { txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1], }); - const confRes = await zeroEx.awaitTransactionMinedAsync(txHash); + const confRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); expect(confRes.logs).to.have.length(2); }); const newSecondsTimeLocked = 0; diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 9e4f7ca3b..f2c0f5bc7 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -1,4 +1,3 @@ -import { ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber, NULL_BYTES } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -60,7 +59,7 @@ describe('TokenRegistry', () => { }; const nullToken = { - address: ZeroEx.NULL_ADDRESS, + address: constants.NULL_ADDRESS, name: '', symbol: '', decimals: 0, diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index 723ddb066..1a53871cd 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -38,7 +38,7 @@ // let amountGive: BigNumber; // let makerTokenAmount: BigNumber; // let takerTokenAmount: BigNumber; -// const feeRecipient = ZeroEx.NULL_ADDRESS; +// const feeRecipient = constants.NULL_ADDRESS; // const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); // const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); @@ -115,7 +115,7 @@ // exchangeContractAddress: exchange.address, // networkId: constants.TESTRPC_NETWORK_ID, // }); -// exWrapper = new ExchangeWrapper(exchange, zeroEx); +// exWrapper = new ExchangeWrapper(exchange); // makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); // takerTokenAmount = makerTokenAmount; diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 5ad9321e8..147f77ab1 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -1,4 +1,4 @@ -import { ZeroEx } from '0x.js'; +import { ContractWrappers } from '@0xproject/contract-wrappers'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -19,7 +19,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('UnlimitedAllowanceToken', () => { let owner: string; let spender: string; - const zeroEx = new ZeroEx(provider, { + const contractWrappers = new ContractWrappers(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); @@ -51,7 +51,7 @@ describe('UnlimitedAllowanceToken', () => { }); describe('transfer', () => { it('should throw if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance.plus(1); return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith( constants.REVERT, @@ -60,11 +60,11 @@ describe('UnlimitedAllowanceToken', () => { it('should transfer balance from sender to receiver', async () => { const receiver = spender; - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = new BigNumber(1); - await zeroEx.token.transferAsync(tokenAddress, owner, receiver, amountToTransfer); - const finalOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const finalReceiverBalance = await zeroEx.token.getBalanceAsync(tokenAddress, receiver); + await contractWrappers.token.transferAsync(tokenAddress, owner, receiver, amountToTransfer); + const finalOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); + const finalReceiverBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, receiver); const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer); const expectedFinalReceiverBalance = amountToTransfer; @@ -82,9 +82,9 @@ describe('UnlimitedAllowanceToken', () => { describe('transferFrom', () => { it('should throw if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance.plus(1); - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer); + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer); return expect( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, @@ -93,10 +93,10 @@ describe('UnlimitedAllowanceToken', () => { }); it('should throw if spender has insufficient allowance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance; - const spenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); + const spenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender); const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); @@ -116,44 +116,44 @@ describe('UnlimitedAllowanceToken', () => { }); it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = initOwnerBalance; - const initSpenderAllowance = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { + const initSpenderAllowance = contractWrappers.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender); expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance); }); it('should transfer the correct balances if spender has sufficient allowance', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const newSpenderBalance = await zeroEx.token.getBalanceAsync(tokenAddress, spender); + const newOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); + const newSpenderBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, spender); expect(newOwnerBalance).to.be.bignumber.equal(0); expect(newSpenderBalance).to.be.bignumber.equal(initOwnerBalance); }); it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender); expect(newSpenderAllowance).to.be.bignumber.equal(0); }); }); diff --git a/packages/contracts/test/utils/match_order_tester.ts b/packages/contracts/test/utils/match_order_tester.ts index 14930de08..6dbd7bfbc 100644 --- a/packages/contracts/test/utils/match_order_tester.ts +++ b/packages/contracts/test/utils/match_order_tester.ts @@ -1,5 +1,5 @@ -import { LogWithDecodedArgs, ZeroEx } from '0x.js'; import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index 48b8f6e36..d621d9065 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -1,4 +1,4 @@ -import { ZeroEx } from '0x.js'; +import { ContractWrappers } from '@0xproject/contract-wrappers'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -19,7 +19,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('ZRXToken', () => { let owner: string; let spender: string; - let zeroEx: ZeroEx; + let contractWrappers: ContractWrappers; let MAX_UINT: BigNumber; @@ -30,12 +30,12 @@ describe('ZRXToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; spender = accounts[1]; - zeroEx = new ZeroEx(provider, { + contractWrappers = new ContractWrappers(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); zrxAddress = zrxToken.address; - MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; + MAX_UINT = contractWrappers.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -53,7 +53,7 @@ describe('ZRXToken', () => { it('should have a total supply of 1 billion tokens', async () => { const totalSupply = new BigNumber(await zrxToken.totalSupply.callAsync()); const expectedTotalSupply = 1000000000; - expect(ZeroEx.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply); + expect(Web3Wrapper.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply); }); it('should be named 0x Protocol Token', async () => { @@ -71,7 +71,7 @@ describe('ZRXToken', () => { describe('constructor', () => { it('should initialize owner balance to totalSupply', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const totalSupply = new BigNumber(await zrxToken.totalSupply.callAsync()); expect(totalSupply).to.be.bignumber.equal(ownerBalance); }); @@ -80,11 +80,11 @@ describe('ZRXToken', () => { describe('transfer', () => { it('should transfer balance from sender to receiver', async () => { const receiver = spender; - const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = new BigNumber(1); - await zeroEx.token.transferAsync(zrxAddress, owner, receiver, amountToTransfer); - const finalOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); - const finalReceiverBalance = await zeroEx.token.getBalanceAsync(zrxAddress, receiver); + await contractWrappers.token.transferAsync(zrxAddress, owner, receiver, amountToTransfer); + const finalOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const finalReceiverBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, receiver); const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer); const expectedFinalReceiverBalance = amountToTransfer; @@ -102,9 +102,9 @@ describe('ZRXToken', () => { describe('transferFrom', () => { it('should return false if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = ownerBalance.plus(1); - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_APPROVE_GAS, }); const didReturnTrue = await zrxToken.transferFrom.callAsync(owner, spender, amountToTransfer, { @@ -114,10 +114,10 @@ describe('ZRXToken', () => { }); it('should return false if spender has insufficient allowance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = ownerBalance; - const spenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); + const spenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); @@ -136,46 +136,46 @@ describe('ZRXToken', () => { }); it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = MAX_UINT; - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { gasLimit: constants.MAX_TOKEN_APPROVE_GAS, }); - await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance); }); it('should transfer the correct balances if spender has sufficient allowance', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); - const initSpenderBalance = await zeroEx.token.getBalanceAsync(zrxAddress, spender); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const initSpenderBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, spender); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); - const newSpenderBalance = await zeroEx.token.getBalanceAsync(zrxAddress, spender); + const newOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const newSpenderBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, spender); expect(newOwnerBalance).to.be.bignumber.equal(0); expect(newSpenderBalance).to.be.bignumber.equal(initSpenderBalance.plus(initOwnerBalance)); }); it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); - await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); + await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); expect(newSpenderAllowance).to.be.bignumber.equal(0); }); }); -- cgit v1.2.3 From 9373451ca8c19ac2ab20db792fd049ccf284f1f2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 11:58:42 -0700 Subject: Fix tslint issues --- packages/contracts/test/exchange/signature_validator.ts | 8 ++++---- packages/contracts/test/utils/match_order_tester.ts | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index 489ed32c5..edff3abc6 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -62,12 +62,12 @@ describe('MixinSignatureValidator', () => { it('should return true with a valid signature', async () => { const orderHashHex = orderUtils.getOrderHashHex(signedOrder); - const success = await signatureValidator.publicIsValidSignature.callAsync( + const isValidSignature = await signatureValidator.publicIsValidSignature.callAsync( orderHashHex, signedOrder.makerAddress, signedOrder.signature, ); - expect(success).to.be.true(); + expect(isValidSignature).to.be.true(); }); it('should return false with an invalid signature', async () => { @@ -81,12 +81,12 @@ describe('MixinSignatureValidator', () => { const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`; signedOrder.signature = invalidSigHex; const orderHashHex = orderUtils.getOrderHashHex(signedOrder); - const success = await signatureValidator.publicIsValidSignature.callAsync( + const isValidSignature = await signatureValidator.publicIsValidSignature.callAsync( orderHashHex, signedOrder.makerAddress, signedOrder.signature, ); - expect(success).to.be.false(); + expect(isValidSignature).to.be.false(); }); }); }); diff --git a/packages/contracts/test/utils/match_order_tester.ts b/packages/contracts/test/utils/match_order_tester.ts index da311e6ea..ae874e502 100644 --- a/packages/contracts/test/utils/match_order_tester.ts +++ b/packages/contracts/test/utils/match_order_tester.ts @@ -57,8 +57,8 @@ export class MatchOrderTester { realERC721TokenIdsByOwner: ERC721TokenIdsByOwner, ): boolean { // ERC20 Balances - const erc20BalancesMatch = _.isEqual(expectedNewERC20BalancesByOwner, realERC20BalancesByOwner); - if (!erc20BalancesMatch) { + const doesErc20BalancesMatch = _.isEqual(expectedNewERC20BalancesByOwner, realERC20BalancesByOwner); + if (!doesErc20BalancesMatch) { return false; } // ERC721 Token Ids @@ -75,8 +75,11 @@ export class MatchOrderTester { _.sortBy(tokenIds); }); }); - const erc721TokenIdsMatch = _.isEqual(sortedExpectedNewERC721TokenIdsByOwner, sortedNewERC721TokenIdsByOwner); - return erc721TokenIdsMatch; + const doesErc721TokenIdsMatch = _.isEqual( + sortedExpectedNewERC721TokenIdsByOwner, + sortedNewERC721TokenIdsByOwner, + ); + return doesErc721TokenIdsMatch; } /// @dev Constructs new MatchOrderTester. /// @param exchangeWrapper Used to call to the Exchange. @@ -156,13 +159,13 @@ export class MatchOrderTester { expectedTransferAmounts, ); // Assert our expected balances are equal to the actual balances - const expectedBalancesMatchRealBalances = MatchOrderTester._compareExpectedAndRealBalances( + const didExpectedBalancesMatchRealBalances = MatchOrderTester._compareExpectedAndRealBalances( expectedERC20BalancesByOwner, newERC20BalancesByOwner, expectedERC721TokenIdsByOwner, newERC721TokenIdsByOwner, ); - expect(expectedBalancesMatchRealBalances).to.be.true(); + expect(didExpectedBalancesMatchRealBalances).to.be.true(); return [newERC20BalancesByOwner, newERC721TokenIdsByOwner]; } /// @dev Calculates expected transfer amounts between order makers, fee recipients, and -- cgit v1.2.3 From 09d80b1e503b00483f32c60745a61ca8e4477be9 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 13:14:38 -0700 Subject: Fix imports --- packages/contracts/test/ether_token.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 4c85147df..8f2a01a4d 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -2,7 +2,6 @@ import { ContractWrappersError } from '@0xproject/contract-wrappers'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { Web3Wrapper } from '@0xproject/web3_wrapper'; import * as chai from 'chai'; import 'make-promises-safe'; -- cgit v1.2.3 From 9de9bf651b7cede14ed718a438c48204dec5f989 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 13:15:01 -0700 Subject: Fix ExchangeWrapper --- packages/contracts/test/exchange/core.ts | 8 +------- packages/contracts/test/exchange/match_orders.ts | 2 +- packages/contracts/test/exchange/transactions.ts | 2 +- packages/contracts/test/exchange/wrapper.ts | 2 +- packages/contracts/test/tutorials/arbitrage.ts | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index a54ec7692..5a91f42d1 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -60,8 +60,6 @@ describe('Exchange core', () => { let defaultMakerAssetAddress: string; let defaultTakerAssetAddress: string; - let zeroEx: ZeroEx; - before(async () => { await blockchainLifecycle.startAsync(); }); @@ -92,11 +90,7 @@ describe('Exchange core', () => { txDefaults, assetProxyUtils.encodeERC20ProxyData(zrxToken.address), ); - zeroEx = new ZeroEx(provider, { - exchangeContractAddress: exchange.address, - networkId: constants.TESTRPC_NETWORK_ID, - }); - exchangeWrapper = new ExchangeWrapper(exchange); + exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 9f8f6db44..e732c90db 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -116,7 +116,7 @@ describe('matchOrders', () => { txDefaults, assetProxyUtils.encodeERC20ProxyData(zrxToken.address), ); - exchangeWrapper = new ExchangeWrapper(exchange); + exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); // Authorize ERC20 and ERC721 trades by exchange diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 42e2429bb..203c05e53 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -79,7 +79,7 @@ describe('Exchange transactions', () => { txDefaults, assetProxyUtils.encodeERC20ProxyData(zrxToken.address), ); - exchangeWrapper = new ExchangeWrapper(exchange); + exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await web3Wrapper.awaitTransactionMinedAsync( diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 99f23a5db..39f861968 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -83,7 +83,7 @@ describe('Exchange wrappers', () => { txDefaults, assetProxyUtils.encodeERC20ProxyData(zrxToken.address), ); - exchangeWrapper = new ExchangeWrapper(exchange); + exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index 1a53871cd..e5787d5b8 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -115,7 +115,7 @@ // exchangeContractAddress: exchange.address, // networkId: constants.TESTRPC_NETWORK_ID, // }); -// exWrapper = new ExchangeWrapper(exchange); +// exWrapper = new ExchangeWrapper(exchange, provider); // makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); // takerTokenAmount = makerTokenAmount; -- cgit v1.2.3 From 5a09063adbb3fe506496b3413926d550575a85a5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 13:15:16 -0700 Subject: Refactor etherToken test to use contract-wrappers --- packages/contracts/test/ether_token.ts | 58 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 8f2a01a4d..90538caf9 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -1,4 +1,4 @@ -import { ContractWrappersError } from '@0xproject/contract-wrappers'; +import { ContractWrappers, ContractWrappersError } from '@0xproject/contract-wrappers'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -18,7 +18,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('EtherToken', () => { let account: string; const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); - let zeroEx: ZeroEx; + let contractWrappers: ContractWrappers; let etherTokenAddress: string; before(async () => { @@ -33,7 +33,7 @@ describe('EtherToken', () => { const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); etherTokenAddress = etherToken.address; - zeroEx = new ZeroEx(provider, { + contractWrappers = new ContractWrappers(provider, { gasPrice, networkId: constants.TESTRPC_NETWORK_ID, }); @@ -49,23 +49,26 @@ describe('EtherToken', () => { const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const ethToDeposit = initEthBalance.plus(1); - return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith( - ContractWrappersError.InsufficientEthBalanceForDeposit, - ); + return expect( + contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account), + ).to.be.rejectedWith(ContractWrappersError.InsufficientEthBalanceForDeposit); }); it('should convert deposited Ether to wrapped Ether tokens', async () => { const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); - const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); - const receipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + const txHash = await contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); + const receipt = await contractWrappers.awaitTransactionMinedAsync( + txHash, + constants.AWAIT_TRANSACTION_MINED_MS, + ); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); @@ -74,29 +77,37 @@ describe('EtherToken', () => { describe('withdraw', () => { it('should throw if caller attempts to withdraw greater than caller balance', async () => { - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); const ethTokensToWithdraw = initEthTokenBalance.plus(1); return expect( - zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account), + contractWrappers.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account), ).to.be.rejectedWith(ContractWrappersError.InsufficientWEthBalanceForWithdrawal); }); it('should convert ether tokens to ether with sufficient balance', async () => { const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); - await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + await contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); + const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const ethTokensToWithdraw = initEthTokenBalance; expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0); - const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, { - gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, - }); - const receipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + const txHash = await contractWrappers.etherToken.withdrawAsync( + etherTokenAddress, + ethTokensToWithdraw, + account, + { + gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, + }, + ); + const receipt = await contractWrappers.awaitTransactionMinedAsync( + txHash, + constants.AWAIT_TRANSACTION_MINED_MS, + ); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); expect(finalEthBalance).to.be.bignumber.equal( initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)), @@ -108,7 +119,7 @@ describe('EtherToken', () => { describe('fallback', () => { it('should convert sent ether to ether tokens', async () => { const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18); @@ -119,11 +130,14 @@ describe('EtherToken', () => { gasPrice, }); - const receipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + const receipt = await contractWrappers.awaitTransactionMinedAsync( + txHash, + constants.AWAIT_TRANSACTION_MINED_MS, + ); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); -- cgit v1.2.3 From c8dad01137ac718de721941ba86c1cc2075e2c5f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 13:19:29 -0700 Subject: Fix await calls --- packages/contracts/test/ether_token.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 90538caf9..9b04dd187 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -61,10 +61,7 @@ describe('EtherToken', () => { const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); const txHash = await contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); - const receipt = await contractWrappers.awaitTransactionMinedAsync( - txHash, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + const receipt = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); @@ -100,10 +97,7 @@ describe('EtherToken', () => { gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, }, ); - const receipt = await contractWrappers.awaitTransactionMinedAsync( - txHash, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + const receipt = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); @@ -130,10 +124,7 @@ describe('EtherToken', () => { gasPrice, }); - const receipt = await contractWrappers.awaitTransactionMinedAsync( - txHash, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + const receipt = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); -- cgit v1.2.3 From 4897513d7d4b25c671be81a81615f78cfcd30173 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 13:19:35 -0700 Subject: Fix import --- packages/contracts/test/exchange/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 5a91f42d1..78b36dfc3 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -1,7 +1,7 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web-wrapper'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import 'make-promises-safe'; -- cgit v1.2.3 From 1ff34bd0f4084d2f9dfd6f07447bb63684ac51ac Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 15 May 2018 15:14:36 +0200 Subject: Remove web3Factory.create and remove dev-tools dependency on sol-cov --- packages/contracts/test/global_hooks.ts | 4 +++- packages/contracts/test/utils/coverage.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/contracts/test/utils/coverage.ts (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/global_hooks.ts b/packages/contracts/test/global_hooks.ts index 089521d94..509dc6837 100644 --- a/packages/contracts/test/global_hooks.ts +++ b/packages/contracts/test/global_hooks.ts @@ -1,4 +1,6 @@ -import { coverage, env, EnvVars } from '@0xproject/dev-utils'; +import { env, EnvVars } from '@0xproject/dev-utils'; + +import { coverage } from './utils/coverage'; after('generate coverage report', async () => { if (env.parseBoolean(EnvVars.SolidityCoverage)) { diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts new file mode 100644 index 000000000..e3c5be428 --- /dev/null +++ b/packages/contracts/test/utils/coverage.ts @@ -0,0 +1,21 @@ +import { devConstants } from '@0xproject/dev-utils'; +import { CoverageSubprovider, ZeroExArtifactAdapter } from '@0xproject/sol-cov'; +import * as fs from 'fs'; +import * as _ from 'lodash'; + +let coverageSubprovider: CoverageSubprovider; + +export const coverage = { + getCoverageSubproviderSingleton(): CoverageSubprovider { + if (_.isUndefined(coverageSubprovider)) { + coverageSubprovider = coverage._getCoverageSubprovider(); + } + return coverageSubprovider; + }, + _getCoverageSubprovider(): CoverageSubprovider { + const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; + const config = JSON.parse(fs.readFileSync('compiler.json').toString()); + const zeroExArtifactsAdapter = new ZeroExArtifactAdapter(config.artifactsDir, config.contractsDir); + return new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress); + }, +}; -- cgit v1.2.3 From 56d1b0103f100c19ce0ee1572980b949161532f4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 21 May 2018 16:38:43 -0700 Subject: Introduce CONFIG_FILE --- packages/contracts/test/utils/coverage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts index e3c5be428..58010e47f 100644 --- a/packages/contracts/test/utils/coverage.ts +++ b/packages/contracts/test/utils/coverage.ts @@ -14,7 +14,8 @@ export const coverage = { }, _getCoverageSubprovider(): CoverageSubprovider { const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; - const config = JSON.parse(fs.readFileSync('compiler.json').toString()); + const CONFIG_FILE = 'compiler.json'; + const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString()); const zeroExArtifactsAdapter = new ZeroExArtifactAdapter(config.artifactsDir, config.contractsDir); return new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress); }, -- cgit v1.2.3 From 8267950dbcc22bb6d572a9523bfa578f78f891f8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 21 May 2018 16:41:19 -0700 Subject: Assign then return --- packages/contracts/test/utils/coverage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts index 58010e47f..52c419ffc 100644 --- a/packages/contracts/test/utils/coverage.ts +++ b/packages/contracts/test/utils/coverage.ts @@ -17,6 +17,7 @@ export const coverage = { const CONFIG_FILE = 'compiler.json'; const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString()); const zeroExArtifactsAdapter = new ZeroExArtifactAdapter(config.artifactsDir, config.contractsDir); - return new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress); + const coverageSubrpovider = new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress); + return coverageSubprovider; }, }; -- cgit v1.2.3 From 86f17fb466124ad4ecd9e4ac47e7fecde8f585ee Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 21 May 2018 16:44:25 -0700 Subject: Rename ZeroExArtifactAdapter to SolCompilerArtifactAdapter --- packages/contracts/test/utils/coverage.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts index 52c419ffc..eeb47667f 100644 --- a/packages/contracts/test/utils/coverage.ts +++ b/packages/contracts/test/utils/coverage.ts @@ -1,5 +1,5 @@ import { devConstants } from '@0xproject/dev-utils'; -import { CoverageSubprovider, ZeroExArtifactAdapter } from '@0xproject/sol-cov'; +import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0xproject/sol-cov'; import * as fs from 'fs'; import * as _ from 'lodash'; @@ -16,7 +16,7 @@ export const coverage = { const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; const CONFIG_FILE = 'compiler.json'; const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString()); - const zeroExArtifactsAdapter = new ZeroExArtifactAdapter(config.artifactsDir, config.contractsDir); + const zeroExArtifactsAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir); const coverageSubrpovider = new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress); return coverageSubprovider; }, -- cgit v1.2.3 From 06be580d2cbe7e3543d8c4deeb4d1c22b325e6a7 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 22 May 2018 13:21:44 -0700 Subject: Fix a bug in CALL-like opcode handling --- packages/contracts/test/utils/coverage.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts index eeb47667f..3b2a8d7b2 100644 --- a/packages/contracts/test/utils/coverage.ts +++ b/packages/contracts/test/utils/coverage.ts @@ -16,8 +16,8 @@ export const coverage = { const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; const CONFIG_FILE = 'compiler.json'; const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString()); - const zeroExArtifactsAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir); - const coverageSubrpovider = new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress); - return coverageSubprovider; + const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir); + const subprovider = new CoverageSubprovider(solCompilerArtifactAdapter, defaultFromAddress); + return subprovider; }, }; -- cgit v1.2.3 From d49f2c40ae28bde3574907a72c0fdd84196e8303 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 22 May 2018 16:41:50 -0700 Subject: Parse compiler.json in SolCompilerArtifactsAdapter --- packages/contracts/test/utils/coverage.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts index 3b2a8d7b2..a37939464 100644 --- a/packages/contracts/test/utils/coverage.ts +++ b/packages/contracts/test/utils/coverage.ts @@ -14,9 +14,7 @@ export const coverage = { }, _getCoverageSubprovider(): CoverageSubprovider { const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; - const CONFIG_FILE = 'compiler.json'; - const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString()); - const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir); + const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(); const subprovider = new CoverageSubprovider(solCompilerArtifactAdapter, defaultFromAddress); return subprovider; }, -- cgit v1.2.3 From 61e487224fab2995b18b1534bfa83362b38b5725 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 17:36:41 -0700 Subject: Fix Tslint error caused by "PromiseLike" value --- packages/contracts/test/exchange/core.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 78b36dfc3..f1d9a4156 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -533,6 +533,9 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); + // HACK: `rejectWith` returns a "promise-like" type, but not an actual "Promise", so TSLint + // complains, even though we do need to `await` it. So we disable the TSLint error below. + // tslint:disable-next-line:await-promise await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( constants.REVERT, ); @@ -551,6 +554,9 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); + // HACK: `rejectWith` returns a "promise-like" type, but not an actual "Promise", so TSLint + // complains, even though we do need to `await` it. So we disable the TSLint error below. + // tslint:disable-next-line:await-promise await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( constants.REVERT, ); -- cgit v1.2.3 From 6a77e0fe56b1fdc3bef990f8418d741c6a338763 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 23 May 2018 10:32:14 -0700 Subject: Move contract utils --- packages/contracts/test/exchange/match_orders.ts | 2 +- packages/contracts/test/global_hooks.ts | 2 +- packages/contracts/test/utils/coverage.ts | 21 -- .../contracts/test/utils/match_order_tester.ts | 356 --------------------- 4 files changed, 2 insertions(+), 379 deletions(-) delete mode 100644 packages/contracts/test/utils/coverage.ts delete mode 100644 packages/contracts/test/utils/match_order_tester.ts (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index e732c90db..8a3c91520 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -37,7 +37,7 @@ import { } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; -import { MatchOrderTester } from '../utils/match_order_tester'; +import { MatchOrderTester } from '../../src/utils/match_order_tester'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/global_hooks.ts b/packages/contracts/test/global_hooks.ts index 509dc6837..8b48b030d 100644 --- a/packages/contracts/test/global_hooks.ts +++ b/packages/contracts/test/global_hooks.ts @@ -1,6 +1,6 @@ import { env, EnvVars } from '@0xproject/dev-utils'; -import { coverage } from './utils/coverage'; +import { coverage } from '../src/utils/coverage'; after('generate coverage report', async () => { if (env.parseBoolean(EnvVars.SolidityCoverage)) { diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts deleted file mode 100644 index a37939464..000000000 --- a/packages/contracts/test/utils/coverage.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { devConstants } from '@0xproject/dev-utils'; -import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0xproject/sol-cov'; -import * as fs from 'fs'; -import * as _ from 'lodash'; - -let coverageSubprovider: CoverageSubprovider; - -export const coverage = { - getCoverageSubproviderSingleton(): CoverageSubprovider { - if (_.isUndefined(coverageSubprovider)) { - coverageSubprovider = coverage._getCoverageSubprovider(); - } - return coverageSubprovider; - }, - _getCoverageSubprovider(): CoverageSubprovider { - const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; - const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(); - const subprovider = new CoverageSubprovider(solCompilerArtifactAdapter, defaultFromAddress); - return subprovider; - }, -}; diff --git a/packages/contracts/test/utils/match_order_tester.ts b/packages/contracts/test/utils/match_order_tester.ts deleted file mode 100644 index 43196728c..000000000 --- a/packages/contracts/test/utils/match_order_tester.ts +++ /dev/null @@ -1,356 +0,0 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import { LogWithDecodedArgs } from '@0xproject/types'; -import { BigNumber } from '@0xproject/utils'; -import * as chai from 'chai'; -import ethUtil = require('ethereumjs-util'); -import * as _ from 'lodash'; - -import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token'; -import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c721_token'; -import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy'; -import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy'; -import { - CancelContractEventArgs, - ExchangeContract, - FillContractEventArgs, -} from '../../src/contract_wrappers/generated/exchange'; -import { assetProxyUtils } from '../../src/utils/asset_proxy_utils'; -import { chaiSetup } from '../../src/utils/chai_setup'; -import { constants } from '../../src/utils/constants'; -import { crypto } from '../../src/utils/crypto'; -import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; -import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; -import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; -import { OrderFactory } from '../../src/utils/order_factory'; -import { orderUtils } from '../../src/utils/order_utils'; -import { - AssetProxyId, - ContractName, - ERC20BalancesByOwner, - ERC721TokenIdsByOwner, - ExchangeStatus, - SignedOrder, - TransferAmountsByMatchOrders as TransferAmounts, -} from '../../src/utils/types'; -import { provider, web3Wrapper } from '../../src/utils/web3_wrapper'; - -chaiSetup.configure(); -const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); - -export class MatchOrderTester { - private _exchangeWrapper: ExchangeWrapper; - private _erc20Wrapper: ERC20Wrapper; - private _erc721Wrapper: ERC721Wrapper; - private _feeTokenAddress: string; - - /// @dev Compares a pair of ERC20 balances and a pair of ERC721 token owners. - /// @param expectedNewERC20BalancesByOwner Expected ERC20 balances. - /// @param realERC20BalancesByOwner Actual ERC20 balances. - /// @param expectedNewERC721TokenIdsByOwner Expected ERC721 token owners. - /// @param realERC721TokenIdsByOwner Actual ERC20 token owners. - /// @return True only if ERC20 balances match and ERC721 token owners match. - private static _compareExpectedAndRealBalances( - expectedNewERC20BalancesByOwner: ERC20BalancesByOwner, - realERC20BalancesByOwner: ERC20BalancesByOwner, - expectedNewERC721TokenIdsByOwner: ERC721TokenIdsByOwner, - realERC721TokenIdsByOwner: ERC721TokenIdsByOwner, - ): boolean { - // ERC20 Balances - const doesErc20BalancesMatch = _.isEqual(expectedNewERC20BalancesByOwner, realERC20BalancesByOwner); - if (!doesErc20BalancesMatch) { - return false; - } - // ERC721 Token Ids - const sortedExpectedNewERC721TokenIdsByOwner = _.mapValues( - expectedNewERC721TokenIdsByOwner, - tokenIdsByOwner => { - _.mapValues(tokenIdsByOwner, tokenIds => { - _.sortBy(tokenIds); - }); - }, - ); - const sortedNewERC721TokenIdsByOwner = _.mapValues(realERC721TokenIdsByOwner, tokenIdsByOwner => { - _.mapValues(tokenIdsByOwner, tokenIds => { - _.sortBy(tokenIds); - }); - }); - const doesErc721TokenIdsMatch = _.isEqual( - sortedExpectedNewERC721TokenIdsByOwner, - sortedNewERC721TokenIdsByOwner, - ); - return doesErc721TokenIdsMatch; - } - /// @dev Constructs new MatchOrderTester. - /// @param exchangeWrapper Used to call to the Exchange. - /// @param erc20Wrapper Used to fetch ERC20 balances. - /// @param erc721Wrapper Used to fetch ERC721 token owners. - /// @param feeTokenAddress Address of ERC20 fee token. - constructor( - exchangeWrapper: ExchangeWrapper, - erc20Wrapper: ERC20Wrapper, - erc721Wrapper: ERC721Wrapper, - feeTokenAddress: string, - ) { - this._exchangeWrapper = exchangeWrapper; - this._erc20Wrapper = erc20Wrapper; - this._erc721Wrapper = erc721Wrapper; - this._feeTokenAddress = feeTokenAddress; - } - /// @dev Matches two complementary orders and validates results. - /// Validation either succeeds or throws. - /// @param signedOrderLeft First matched order. - /// @param signedOrderRight Second matched order. - /// @param takerAddress Address of taker (the address who matched the two orders) - /// @param erc20BalancesByOwner Current ERC20 balances. - /// @param erc721TokenIdsByOwner Current ERC721 token owners. - /// @param initialTakerAssetFilledAmountLeft Current amount the left order has been filled. - /// @param initialTakerAssetFilledAmountRight Current amount the right order has been filled. - /// @return New ERC20 balances & ERC721 token owners. - public async matchOrdersAndVerifyBalancesAsync( - signedOrderLeft: SignedOrder, - signedOrderRight: SignedOrder, - takerAddress: string, - erc20BalancesByOwner: ERC20BalancesByOwner, - erc721TokenIdsByOwner: ERC721TokenIdsByOwner, - initialTakerAssetFilledAmountLeft?: BigNumber, - initialTakerAssetFilledAmountRight?: BigNumber, - ): Promise<[ERC20BalancesByOwner, ERC721TokenIdsByOwner]> { - // Test setup & verify preconditions - const makerAddressLeft = signedOrderLeft.makerAddress; - const makerAddressRight = signedOrderRight.makerAddress; - const feeRecipientAddressLeft = signedOrderLeft.feeRecipientAddress; - const feeRecipientAddressRight = signedOrderRight.feeRecipientAddress; - // Verify Left order preconditions - const orderTakerAssetFilledAmountLeft = await this._exchangeWrapper.getTakerAssetFilledAmountAsync( - orderUtils.getOrderHashHex(signedOrderLeft), - ); - const expectedOrderFilledAmountLeft = initialTakerAssetFilledAmountLeft - ? initialTakerAssetFilledAmountLeft - : new BigNumber(0); - expect(expectedOrderFilledAmountLeft).to.be.bignumber.equal(orderTakerAssetFilledAmountLeft); - // Verify Right order preconditions - const orderTakerAssetFilledAmountRight = await this._exchangeWrapper.getTakerAssetFilledAmountAsync( - orderUtils.getOrderHashHex(signedOrderRight), - ); - const expectedOrderFilledAmountRight = initialTakerAssetFilledAmountRight - ? initialTakerAssetFilledAmountRight - : new BigNumber(0); - expect(expectedOrderFilledAmountRight).to.be.bignumber.equal(orderTakerAssetFilledAmountRight); - // Match left & right orders - await this._exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress); - const newERC20BalancesByOwner = await this._erc20Wrapper.getBalancesAsync(); - const newERC721TokenIdsByOwner = await this._erc721Wrapper.getBalancesAsync(); - // Calculate expected balance changes - const expectedTransferAmounts = await this._calculateExpectedTransferAmountsAsync( - signedOrderLeft, - signedOrderRight, - orderTakerAssetFilledAmountLeft, - orderTakerAssetFilledAmountRight, - ); - let expectedERC20BalancesByOwner: ERC20BalancesByOwner; - let expectedERC721TokenIdsByOwner: ERC721TokenIdsByOwner; - [expectedERC20BalancesByOwner, expectedERC721TokenIdsByOwner] = this._calculateExpectedBalances( - signedOrderLeft, - signedOrderRight, - takerAddress, - erc20BalancesByOwner, - erc721TokenIdsByOwner, - expectedTransferAmounts, - ); - // Assert our expected balances are equal to the actual balances - const didExpectedBalancesMatchRealBalances = MatchOrderTester._compareExpectedAndRealBalances( - expectedERC20BalancesByOwner, - newERC20BalancesByOwner, - expectedERC721TokenIdsByOwner, - newERC721TokenIdsByOwner, - ); - expect(didExpectedBalancesMatchRealBalances).to.be.true(); - return [newERC20BalancesByOwner, newERC721TokenIdsByOwner]; - } - /// @dev Calculates expected transfer amounts between order makers, fee recipients, and - /// the taker when two orders are matched. - /// @param signedOrderLeft First matched order. - /// @param signedOrderRight Second matched order. - /// @param orderTakerAssetFilledAmountLeft How much left order has been filled, prior to matching orders. - /// @param orderTakerAssetFilledAmountRight How much the right order has been filled, prior to matching orders. - /// @return TransferAmounts A struct containing the expected transfer amounts. - private async _calculateExpectedTransferAmountsAsync( - signedOrderLeft: SignedOrder, - signedOrderRight: SignedOrder, - orderTakerAssetFilledAmountLeft: BigNumber, - orderTakerAssetFilledAmountRight: BigNumber, - ): Promise { - let amountBoughtByLeftMaker = await this._exchangeWrapper.getTakerAssetFilledAmountAsync( - orderUtils.getOrderHashHex(signedOrderLeft), - ); - amountBoughtByLeftMaker = amountBoughtByLeftMaker.minus(orderTakerAssetFilledAmountLeft); - const amountSoldByLeftMaker = amountBoughtByLeftMaker - .times(signedOrderLeft.makerAssetAmount) - .dividedToIntegerBy(signedOrderLeft.takerAssetAmount); - const amountReceivedByRightMaker = amountBoughtByLeftMaker - .times(signedOrderRight.takerAssetAmount) - .dividedToIntegerBy(signedOrderRight.makerAssetAmount); - const amountReceivedByTaker = amountSoldByLeftMaker.minus(amountReceivedByRightMaker); - let amountBoughtByRightMaker = await this._exchangeWrapper.getTakerAssetFilledAmountAsync( - orderUtils.getOrderHashHex(signedOrderRight), - ); - amountBoughtByRightMaker = amountBoughtByRightMaker.minus(orderTakerAssetFilledAmountRight); - const amountSoldByRightMaker = amountBoughtByRightMaker - .times(signedOrderRight.makerAssetAmount) - .dividedToIntegerBy(signedOrderRight.takerAssetAmount); - const amountReceivedByLeftMaker = amountSoldByRightMaker; - const feePaidByLeftMaker = signedOrderLeft.makerFee - .times(amountSoldByLeftMaker) - .dividedToIntegerBy(signedOrderLeft.makerAssetAmount); - const feePaidByRightMaker = signedOrderRight.makerFee - .times(amountSoldByRightMaker) - .dividedToIntegerBy(signedOrderRight.makerAssetAmount); - const feePaidByTakerLeft = signedOrderLeft.takerFee - .times(amountSoldByLeftMaker) - .dividedToIntegerBy(signedOrderLeft.makerAssetAmount); - const feePaidByTakerRight = signedOrderRight.takerFee - .times(amountSoldByRightMaker) - .dividedToIntegerBy(signedOrderRight.makerAssetAmount); - const totalFeePaidByTaker = feePaidByTakerLeft.add(feePaidByTakerRight); - const feeReceivedLeft = feePaidByLeftMaker.add(feePaidByTakerLeft); - const feeReceivedRight = feePaidByRightMaker.add(feePaidByTakerRight); - // Return values - const expectedTransferAmounts = { - // Left Maker - amountBoughtByLeftMaker, - amountSoldByLeftMaker, - amountReceivedByLeftMaker, - feePaidByLeftMaker, - // Right Maker - amountBoughtByRightMaker, - amountSoldByRightMaker, - amountReceivedByRightMaker, - feePaidByRightMaker, - // Taker - amountReceivedByTaker, - feePaidByTakerLeft, - feePaidByTakerRight, - totalFeePaidByTaker, - // Fee Recipients - feeReceivedLeft, - feeReceivedRight, - }; - return expectedTransferAmounts; - } - /// @dev Calculates the expected balances of order makers, fee recipients, and the taker, - /// as a result of matching two orders. - /// @param signedOrderLeft First matched order. - /// @param signedOrderRight Second matched order. - /// @param takerAddress Address of taker (the address who matched the two orders) - /// @param erc20BalancesByOwner Current ERC20 balances. - /// @param erc721TokenIdsByOwner Current ERC721 token owners. - /// @param expectedTransferAmounts A struct containing the expected transfer amounts. - /// @return Expected ERC20 balances & ERC721 token owners after orders have been matched. - private _calculateExpectedBalances( - signedOrderLeft: SignedOrder, - signedOrderRight: SignedOrder, - takerAddress: string, - erc20BalancesByOwner: ERC20BalancesByOwner, - erc721TokenIdsByOwner: ERC721TokenIdsByOwner, - expectedTransferAmounts: TransferAmounts, - ): [ERC20BalancesByOwner, ERC721TokenIdsByOwner] { - const makerAddressLeft = signedOrderLeft.makerAddress; - const makerAddressRight = signedOrderRight.makerAddress; - const feeRecipientAddressLeft = signedOrderLeft.feeRecipientAddress; - const feeRecipientAddressRight = signedOrderRight.feeRecipientAddress; - // Operations are performed on copies of the balances - const expectedNewERC20BalancesByOwner = _.cloneDeep(erc20BalancesByOwner); - const expectedNewERC721TokenIdsByOwner = _.cloneDeep(erc721TokenIdsByOwner); - // Left Maker Asset (Right Taker Asset) - const makerAssetProxyIdLeft = assetProxyUtils.decodeProxyDataId(signedOrderLeft.makerAssetData); - if (makerAssetProxyIdLeft === AssetProxyId.ERC20) { - // Decode asset data - const erc20ProxyData = assetProxyUtils.decodeERC20ProxyData(signedOrderLeft.makerAssetData); - const makerAssetAddressLeft = erc20ProxyData.tokenAddress; - const takerAssetAddressRight = makerAssetAddressLeft; - // Left Maker - expectedNewERC20BalancesByOwner[makerAddressLeft][makerAssetAddressLeft] = expectedNewERC20BalancesByOwner[ - makerAddressLeft - ][makerAssetAddressLeft].minus(expectedTransferAmounts.amountSoldByLeftMaker); - // Right Maker - expectedNewERC20BalancesByOwner[makerAddressRight][ - takerAssetAddressRight - ] = expectedNewERC20BalancesByOwner[makerAddressRight][takerAssetAddressRight].add( - expectedTransferAmounts.amountReceivedByRightMaker, - ); - // Taker - expectedNewERC20BalancesByOwner[takerAddress][makerAssetAddressLeft] = expectedNewERC20BalancesByOwner[ - takerAddress - ][makerAssetAddressLeft].add(expectedTransferAmounts.amountReceivedByTaker); - } else if (makerAssetProxyIdLeft === AssetProxyId.ERC721) { - // Decode asset data - const erc721ProxyData = assetProxyUtils.decodeERC721ProxyData(signedOrderLeft.makerAssetData); - const makerAssetAddressLeft = erc721ProxyData.tokenAddress; - const makerAssetIdLeft = erc721ProxyData.tokenId; - const takerAssetAddressRight = makerAssetAddressLeft; - const takerAssetIdRight = makerAssetIdLeft; - // Left Maker - _.remove(expectedNewERC721TokenIdsByOwner[makerAddressLeft][makerAssetAddressLeft], makerAssetIdLeft); - // Right Maker - expectedNewERC721TokenIdsByOwner[makerAddressRight][takerAssetAddressRight].push(takerAssetIdRight); - // Taker: Since there is only 1 asset transferred, the taker does not receive any of the left maker asset. - } - // Left Taker Asset (Right Maker Asset) - // Note: This exchange is only between the order makers: the Taker does not receive any of the left taker asset. - const takerAssetProxyIdLeft = assetProxyUtils.decodeProxyDataId(signedOrderLeft.takerAssetData); - if (takerAssetProxyIdLeft === AssetProxyId.ERC20) { - // Decode asset data - const erc20ProxyData = assetProxyUtils.decodeERC20ProxyData(signedOrderLeft.takerAssetData); - const takerAssetAddressLeft = erc20ProxyData.tokenAddress; - const makerAssetAddressRight = takerAssetAddressLeft; - // Left Maker - expectedNewERC20BalancesByOwner[makerAddressLeft][takerAssetAddressLeft] = expectedNewERC20BalancesByOwner[ - makerAddressLeft - ][takerAssetAddressLeft].add(expectedTransferAmounts.amountReceivedByLeftMaker); - // Right Maker - expectedNewERC20BalancesByOwner[makerAddressRight][ - makerAssetAddressRight - ] = expectedNewERC20BalancesByOwner[makerAddressRight][makerAssetAddressRight].minus( - expectedTransferAmounts.amountSoldByRightMaker, - ); - } else if (takerAssetProxyIdLeft === AssetProxyId.ERC721) { - // Decode asset data - const erc721ProxyData = assetProxyUtils.decodeERC721ProxyData(signedOrderRight.makerAssetData); - const makerAssetAddressRight = erc721ProxyData.tokenAddress; - const makerAssetIdRight = erc721ProxyData.tokenId; - const takerAssetAddressLeft = makerAssetAddressRight; - const takerAssetIdLeft = makerAssetIdRight; - // Right Maker - _.remove(expectedNewERC721TokenIdsByOwner[makerAddressRight][makerAssetAddressRight], makerAssetIdRight); - // Left Maker - expectedNewERC721TokenIdsByOwner[makerAddressLeft][takerAssetAddressLeft].push(takerAssetIdLeft); - } - // Left Maker Fees - expectedNewERC20BalancesByOwner[makerAddressLeft][this._feeTokenAddress] = expectedNewERC20BalancesByOwner[ - makerAddressLeft - ][this._feeTokenAddress].minus(expectedTransferAmounts.feePaidByLeftMaker); - // Right Maker Fees - expectedNewERC20BalancesByOwner[makerAddressRight][this._feeTokenAddress] = expectedNewERC20BalancesByOwner[ - makerAddressRight - ][this._feeTokenAddress].minus(expectedTransferAmounts.feePaidByRightMaker); - // Taker Fees - expectedNewERC20BalancesByOwner[takerAddress][this._feeTokenAddress] = expectedNewERC20BalancesByOwner[ - takerAddress - ][this._feeTokenAddress].minus(expectedTransferAmounts.totalFeePaidByTaker); - // Left Fee Recipient Fees - expectedNewERC20BalancesByOwner[feeRecipientAddressLeft][ - this._feeTokenAddress - ] = expectedNewERC20BalancesByOwner[feeRecipientAddressLeft][this._feeTokenAddress].add( - expectedTransferAmounts.feeReceivedLeft, - ); - // Right Fee Recipient Fees - expectedNewERC20BalancesByOwner[feeRecipientAddressRight][ - this._feeTokenAddress - ] = expectedNewERC20BalancesByOwner[feeRecipientAddressRight][this._feeTokenAddress].add( - expectedTransferAmounts.feeReceivedRight, - ); - - return [expectedNewERC20BalancesByOwner, expectedNewERC721TokenIdsByOwner]; - } -} -- cgit v1.2.3