diff options
Diffstat (limited to 'packages/contracts/test/exchange/wrapper.ts')
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 97 |
1 files changed, 57 insertions, 40 deletions
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 0b79308dd..39f861968 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,12 @@ describe('Exchange wrappers', () => { let defaultMakerAssetAddress: string; let defaultTakerAssetAddress: string; - 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); @@ -80,20 +83,22 @@ 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, provider); 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; @@ -119,8 +124,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 +192,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 +236,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 +246,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); @@ -251,13 +256,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); @@ -265,13 +276,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); @@ -620,7 +637,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 +680,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 +726,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 +769,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 +815,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 +858,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 +904,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 +947,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); }); |