From 1ad395cf86b2006c09bdae814607c2baf9790b91 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 18:14:48 +0200 Subject: Make the functions immidiately return txHash instead of awaiting for a transaction to be mined --- test/exchange_wrapper_test.ts | 64 +++++++++++-------------------------------- 1 file changed, 16 insertions(+), 48 deletions(-) (limited to 'test/exchange_wrapper_test.ts') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 90ac37387..15e957ee1 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -196,34 +196,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 +203,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 blockchainLifecycle.waitUntilMinedAsync(txHash); expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) .to.be.bignumber.equal(makerFee.plus(takerFee)); }); @@ -265,13 +238,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 blockchainLifecycle.waitUntilMinedAsync(txHash); const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); expect(filledAmount).to.be.bignumber.equal(fillTakerAmount); @@ -298,26 +273,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 blockchainLifecycle.waitUntilMinedAsync(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 +315,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 blockchainLifecycle.waitUntilMinedAsync(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', () => { -- cgit v1.2.3 From c9e490bdaec53e3a93b5da8daaaf0b1d87d9de76 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 19:08:14 +0200 Subject: Implement zeroEx.awaitTransactionMined --- test/exchange_wrapper_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/exchange_wrapper_test.ts') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 15e957ee1..99e61a751 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -205,7 +205,7 @@ describe('ExchangeWrapper', () => { ); const txHash = await zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); - await blockchainLifecycle.waitUntilMinedAsync(txHash); + await zeroEx.awaitTransactionMined(txHash); expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) .to.be.bignumber.equal(makerFee.plus(takerFee)); }); @@ -246,7 +246,7 @@ describe('ExchangeWrapper', () => { it('should successfully fill multiple orders', async () => { const txHash = await zeroEx.exchange.batchFillOrdersAsync( orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); - await blockchainLifecycle.waitUntilMinedAsync(txHash); + await zeroEx.awaitTransactionMined(txHash); const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); expect(filledAmount).to.be.bignumber.equal(fillTakerAmount); @@ -282,7 +282,7 @@ describe('ExchangeWrapper', () => { const txHash = await zeroEx.exchange.fillOrdersUpToAsync( signedOrders, fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, ); - await blockchainLifecycle.waitUntilMinedAsync(txHash); + await zeroEx.awaitTransactionMined(txHash); const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); expect(filledAmount).to.be.bignumber.equal(fillableAmount); @@ -316,7 +316,7 @@ describe('ExchangeWrapper', () => { describe('successful cancels', () => { it('should cancel an order', async () => { const txHash = await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); - await blockchainLifecycle.waitUntilMinedAsync(txHash); + await zeroEx.awaitTransactionMined(txHash); const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); }); -- cgit v1.2.3 From 2b547f94a44dfed029b5559b743344d5998fa3bc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 10:07:16 +0200 Subject: Change non-exhange contracts to also return txHash --- test/exchange_wrapper_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/exchange_wrapper_test.ts') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 99e61a751..990a4dca6 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -205,7 +205,7 @@ describe('ExchangeWrapper', () => { ); const txHash = await zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); - await zeroEx.awaitTransactionMined(txHash); + await zeroEx.awaitTransactionMinedAsync(txHash); expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) .to.be.bignumber.equal(makerFee.plus(takerFee)); }); @@ -246,7 +246,7 @@ describe('ExchangeWrapper', () => { it('should successfully fill multiple orders', async () => { const txHash = await zeroEx.exchange.batchFillOrdersAsync( orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress); - await zeroEx.awaitTransactionMined(txHash); + 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); @@ -282,7 +282,7 @@ describe('ExchangeWrapper', () => { const txHash = await zeroEx.exchange.fillOrdersUpToAsync( signedOrders, fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, ); - await zeroEx.awaitTransactionMined(txHash); + 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); @@ -316,7 +316,7 @@ describe('ExchangeWrapper', () => { describe('successful cancels', () => { it('should cancel an order', async () => { const txHash = await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); - await zeroEx.awaitTransactionMined(txHash); + await zeroEx.awaitTransactionMinedAsync(txHash); const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); }); -- cgit v1.2.3 From a7b2131db77b72379f0d57eaff694d5a925191cd Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 18:45:20 +0200 Subject: Decode logs args in awaitTransactionMinedAsync --- test/exchange_wrapper_test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/exchange_wrapper_test.ts') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 990a4dca6..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)) -- cgit v1.2.3