diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-09-06 16:35:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-06 16:35:19 +0800 |
commit | 35c133caeda613121d7d90f3f1347ebdc8087d66 (patch) | |
tree | 6156865472010078a9f27b905bcaec7782f6521c /test/exchange_wrapper_test.ts | |
parent | 18a52a1ea758ee5640680f1097eba1ce9a9e81fc (diff) | |
parent | f0a5ad2d2063fe8ba4682147ec2f73e2763b0275 (diff) | |
download | dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.gz dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.bz2 dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.lz dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.xz dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.tar.zst dexon-sol-tools-35c133caeda613121d7d90f3f1347ebdc8087d66.zip |
Merge branch 'development' into fix/signature-verification
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r-- | test/exchange_wrapper_test.ts | 70 |
1 files changed, 20 insertions, 50 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 90ac37387..f72e7f64f 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -169,8 +169,9 @@ describe('ExchangeWrapper', () => { .to.be.bignumber.equal(0); expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) .to.be.bignumber.equal(fillableAmount); - await zeroEx.exchange.fillOrderAsync( + const txHash = await zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); + await zeroEx.awaitTransactionMinedAsync(txHash); expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) @@ -185,8 +186,9 @@ describe('ExchangeWrapper', () => { makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); const partialFillAmount = new BigNumber(3); - await zeroEx.exchange.fillOrderAsync( + const txHash = await zeroEx.exchange.fillOrderAsync( signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); + await zeroEx.awaitTransactionMinedAsync(txHash); expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) @@ -196,34 +198,6 @@ describe('ExchangeWrapper', () => { expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); }); - it('should return filled amount', async () => { - const signedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, - ); - const partialFillAmount = new BigNumber(3); - const filledAmount = await zeroEx.exchange.fillOrderAsync( - signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); - expect(filledAmount).to.be.bignumber.equal(partialFillAmount); - }); - it('should return the partially filled amount \ - if the fill amount specified is greater then the amount available', async () => { - const signedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, - ); - const partialFillAmount = new BigNumber(3); - await zeroEx.exchange.fillOrderAsync( - signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); - const missingBalance = new BigNumber(1); - const totalBalance = partialFillAmount.plus(missingBalance); - await zeroEx.token.transferAsync(takerTokenAddress, coinbase, takerAddress, missingBalance); - await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, totalBalance); - await zeroEx.token.transferAsync(makerTokenAddress, coinbase, makerAddress, missingBalance); - await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, totalBalance); - const remainingFillAmount = fillableAmount.minus(partialFillAmount); - const filledAmount = await zeroEx.exchange.fillOrderAsync( - signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); - expect(filledAmount).to.be.bignumber.equal(remainingFillAmount); - }); it('should fill the valid orders with fees', async () => { const makerFee = new BigNumber(1); const takerFee = new BigNumber(2); @@ -231,8 +205,9 @@ describe('ExchangeWrapper', () => { makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, fillableAmount, feeRecipient, ); - await zeroEx.exchange.fillOrderAsync( + const txHash = await zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); + await zeroEx.awaitTransactionMinedAsync(txHash); expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) .to.be.bignumber.equal(makerFee.plus(takerFee)); }); @@ -265,13 +240,15 @@ describe('ExchangeWrapper', () => { ]; }); describe('successful batch fills', () => { - it('should no-op for an empty batch', async () => { - await zeroEx.exchange.batchFillOrdersAsync( - [], shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); + it('should throw if a batch is empty', async () => { + return expect(zeroEx.exchange.batchFillOrdersAsync( + [], shouldThrowOnInsufficientBalanceOrAllowance, takerAddress), + ).to.be.rejectedWith(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem); }); it('should successfully fill multiple orders', async () => { - await zeroEx.exchange.batchFillOrdersAsync( + const txHash = await zeroEx.exchange.batchFillOrdersAsync( orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); + await zeroEx.awaitTransactionMinedAsync(txHash); const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); expect(filledAmount).to.be.bignumber.equal(fillTakerAmount); @@ -298,26 +275,22 @@ describe('ExchangeWrapper', () => { signedOrders = [signedOrder, anotherSignedOrder]; }); describe('successful batch fills', () => { - it('should no-op for an empty batch', async () => { - await zeroEx.exchange.fillOrdersUpToAsync( - [], fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); + it('should throw if a batch is empty', async () => { + return expect(zeroEx.exchange.fillOrdersUpToAsync( + [], fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress), + ).to.be.rejectedWith(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem); }); it('should successfully fill up to specified amount', async () => { - await zeroEx.exchange.fillOrdersUpToAsync( + const txHash = await zeroEx.exchange.fillOrdersUpToAsync( signedOrders, fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, ); + await zeroEx.awaitTransactionMinedAsync(txHash); const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); expect(filledAmount).to.be.bignumber.equal(fillableAmount); const remainingFillAmount = fillableAmount.minus(1); expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount); }); - it('should return filled amount', async () => { - const filledTakerTokenAmount = await zeroEx.exchange.fillOrdersUpToAsync( - signedOrders, fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, - ); - expect(filledTakerTokenAmount).to.be.bignumber.equal(fillUpToAmount); - }); }); }); }); @@ -344,14 +317,11 @@ describe('ExchangeWrapper', () => { describe('#cancelOrderAsync', () => { describe('successful cancels', () => { it('should cancel an order', async () => { - await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); + const txHash = await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); + await zeroEx.awaitTransactionMinedAsync(txHash); const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); }); - it('should return cancelled amount', async () => { - const cancelledAmount = await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); - expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); - }); }); }); describe('#batchCancelOrdersAsync', () => { |