From d114613384599f69c6fe10bb3172ad9be7d086f3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 12 Oct 2017 17:01:55 +0300 Subject: Add a regression test --- test/order_validation_test.ts | 36 ++++++++++++++++++++++++++++++++++++ test/utils/fill_scenarios.ts | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/test/order_validation_test.ts b/test/order_validation_test.ts index 6f9388a69..742739aaa 100644 --- a/test/order_validation_test.ts +++ b/test/order_validation_test.ts @@ -257,5 +257,41 @@ describe('OrderValidation', () => { ), ).to.be.true(); }); + it('should call exchangeTransferSimulator.transferFrom with correct values for an open order', async () => { + const makerFee = new BigNumber(2); + const takerFee = new BigNumber(2); + const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerTokenAddress, takerTokenAddress, makerFee, takerFee, + makerAddress, ZeroEx.NULL_ADDRESS, fillableAmount, feeRecipient, + ); + await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync( + exchangeTransferSimulator, signedOrder, fillableAmount, takerAddress, zrxTokenAddress, + ); + expect(transferFromAsync.callCount).to.be.equal(4); + expect( + transferFromAsync.getCall(0).calledWith( + makerTokenAddress, makerAddress, takerAddress, bigNumberMatch(fillableAmount), + TradeSide.Maker, TransferType.Trade, + ), + ).to.be.true(); + expect( + transferFromAsync.getCall(1).calledWith( + takerTokenAddress, takerAddress, makerAddress, bigNumberMatch(fillableAmount), + TradeSide.Taker, TransferType.Trade, + ), + ).to.be.true(); + expect( + transferFromAsync.getCall(2).calledWith( + zrxTokenAddress, makerAddress, feeRecipient, bigNumberMatch(makerFee), + TradeSide.Maker, TransferType.Fee, + ), + ).to.be.true(); + expect( + transferFromAsync.getCall(3).calledWith( + zrxTokenAddress, takerAddress, feeRecipient, bigNumberMatch(takerFee), + TradeSide.Taker, TransferType.Fee, + ), + ).to.be.true(); + }); }); }); diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index e305759f6..c399c7bf4 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -91,7 +91,7 @@ export class FillScenarios { } private async increaseBalanceAndAllowanceAsync( tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise { - if (amount.isZero()) { + if (amount.isZero() || address === ZeroEx.NULL_ADDRESS) { return; // noop } await Promise.all([ -- cgit From 74c6be369878bbb50c913ab2a8fd15b889d6f938 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 12 Oct 2017 17:02:18 +0300 Subject: Pass correct parameters to validation simulation --- src/utils/order_validation_utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts index 5d14602db..1d9aac884 100644 --- a/src/utils/order_validation_utils.ts +++ b/src/utils/order_validation_utils.ts @@ -102,11 +102,11 @@ export class OrderValidationUtils { fillTakerTokenAmount: BigNumber.BigNumber, senderAddress: string, zrxTokenAddress: string): Promise { const fillMakerTokenAmount = this.getFillMakerTokenAmount(signedOrder, fillTakerTokenAmount); await exchangeTradeEmulator.transferFromAsync( - signedOrder.makerTokenAddress, signedOrder.maker, signedOrder.taker, fillMakerTokenAmount, + signedOrder.makerTokenAddress, signedOrder.maker, senderAddress, fillMakerTokenAmount, TradeSide.Maker, TransferType.Trade, ); await exchangeTradeEmulator.transferFromAsync( - signedOrder.takerTokenAddress, signedOrder.taker, signedOrder.maker, fillTakerTokenAmount, + signedOrder.takerTokenAddress, senderAddress, signedOrder.maker, fillTakerTokenAmount, TradeSide.Taker, TransferType.Trade, ); await exchangeTradeEmulator.transferFromAsync( @@ -114,7 +114,7 @@ export class OrderValidationUtils { TransferType.Fee, ); await exchangeTradeEmulator.transferFromAsync( - zrxTokenAddress, signedOrder.taker, signedOrder.feeRecipient, signedOrder.takerFee, TradeSide.Taker, + zrxTokenAddress, senderAddress, signedOrder.feeRecipient, signedOrder.takerFee, TradeSide.Taker, TransferType.Fee, ); } -- cgit From b86f6322e16309feea865e1b304dc7da5ce8ec86 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 12 Oct 2017 17:08:46 +0300 Subject: Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b96a02db..efda95316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +v0.21.3 - _October 12, 2017_ + * Fixed a bug causing order fills to throw `INSUFFICIENT_TAKER_ALLOWANCE` (#193) + v0.21.2 - _October 11, 2017_ * Exported `ContractEventArg` as a public type (#190) -- cgit