From 87e0eceb9b5b4460e0875bedcd3a5864ab870e12 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 12:21:53 +0200 Subject: Add comments for dates --- test/exchange_wrapper_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 3a3ec1ca7..c0068c58a 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -158,7 +158,7 @@ describe('ExchangeWrapper', () => { )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); }); it('should throw when order is expired', async () => { - const expirationInPast = new BigNumber(1496826058); + const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 const fillableAmount = new BigNumber(5); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, @@ -350,7 +350,7 @@ describe('ExchangeWrapper', () => { .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO); }); it('should throw when order is expired', async () => { - const expirationInPast = new BigNumber(1496826058); + const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 const expiredSignedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, ); -- cgit v1.2.3 From 2947f55acf932703a54d3177b0c4d9e115c861c2 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 13:20:02 +0200 Subject: Add tests for batchCancelAsync --- test/exchange_wrapper_test.ts | 88 ++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index c0068c58a..6487ba98c 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -323,7 +323,7 @@ describe('ExchangeWrapper', () => { }); }); }); - describe('#cancelOrderAsync', () => { + describe('cancel order(s)', () => { let makerTokenAddress: string; let takerTokenAddress: string; let coinbase: string; @@ -343,32 +343,74 @@ describe('ExchangeWrapper', () => { ); orderHashHex = await zeroEx.getOrderHashHexAsync(signedOrder); }); - describe('failed cancels', () => { - it('should throw when cancel amount is zero', async () => { - const zeroCancelAmount = new BigNumber(0); - return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, zeroCancelAmount)) - .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO); + describe('#cancelOrderAsync', () => { + describe('failed cancels', () => { + it('should throw when cancel amount is zero', async () => { + const zeroCancelAmount = new BigNumber(0); + return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, zeroCancelAmount)) + .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO); + }); + it('should throw when order is expired', async () => { + const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 + const expiredSignedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, + fillableAmount, expirationInPast, + ); + orderHashHex = await zeroEx.getOrderHashHexAsync(expiredSignedOrder); + return expect(zeroEx.exchange.cancelOrderAsync(expiredSignedOrder, cancelAmount)) + .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_EXPIRED); + }); + it('should throw when order is already cancelled or filled', async () => { + await zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount); + return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount)) + .to.be.rejectedWith(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED); + }); }); - it('should throw when order is expired', async () => { - const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 - const expiredSignedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, + describe('successful cancels', () => { + it('should cancel an order', async () => { + await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); + const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); + expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); + }); + }); + }); + describe('#batchCancelOrderAsync', () => { + let anotherSignedOrder: SignedOrder; + let anotherOrderHashHex: string; + beforeEach(async () => { + anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); - orderHashHex = await zeroEx.getOrderHashHexAsync(expiredSignedOrder); - return expect(zeroEx.exchange.cancelOrderAsync(expiredSignedOrder, cancelAmount)) - .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_EXPIRED); + anotherOrderHashHex = await zeroEx.getOrderHashHexAsync(anotherSignedOrder); }); - it('should throw when order is already cancelled or filled', async () => { - await zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount); - return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount)) - .to.be.rejectedWith(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED); + describe('failed batch cancels', () => { + it('should throw when length of orders and cancelAmounts mismatch', async () => { + return expect(zeroEx.exchange.batchCancelOrderAsync([signedOrder], [])) + .to.be.rejectedWith('orders and takerTokenCancelAmounts length mismatch. 1 != 0'); + }); + it('should throw when orders are empty', async () => { + return expect(zeroEx.exchange.batchCancelOrderAsync([], [])) + .to.be.rejectedWith('Can not cancel an empty batch'); + }); + it.only('should throw when orders have different makers', async () => { + const signedOrderWithADifferentMaker = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, takerAddress, takerAddress, fillableAmount, + ); + return expect(zeroEx.exchange.batchCancelOrderAsync( + [signedOrder, signedOrderWithADifferentMaker], [cancelAmount, cancelAmount])) + .to.be.rejectedWith('Can not cancel orders from multiple makers in a single batch'); + }); }); - }); - describe('successful cancels', () => { - it('should cancel an order', async () => { - await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); - const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); - expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); + describe('successful batch cancels', () => { + it('should cancel a batch of orders', async () => { + await zeroEx.exchange.batchCancelOrderAsync( + [signedOrder, anotherSignedOrder], [cancelAmount, cancelAmount]); + const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); + const anotherCancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( + anotherOrderHashHex); + expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); + expect(anotherCancelledAmount).to.be.bignumber.equal(cancelAmount); + }); }); }); }); -- cgit v1.2.3 From d5767428e598e9355786dd30c3ebb17a89b088ba Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 13:32:05 +0200 Subject: Move fillOrderAsync to fill order describe block --- test/exchange_wrapper_test.ts | 364 +++++++++++++++++++++--------------------- 1 file changed, 185 insertions(+), 179 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 6487ba98c..309791518 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -120,206 +120,212 @@ describe('ExchangeWrapper', () => { expect(isValid).to.be.true(); }); }); - describe('#fillOrderAsync', () => { - let makerTokenAddress: string; - let takerTokenAddress: string; - let coinbase: string; - let makerAddress: string; - let takerAddress: string; - let feeRecipient: string; - const fillTakerAmount = new BigNumber(5); - const shouldCheckTransfer = false; - before(async () => { - [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; - tokens = await zeroEx.tokenRegistry.getTokensAsync(); - const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); - makerTokenAddress = makerToken.address; - takerTokenAddress = takerToken.address; - }); - describe('failed fills', () => { - it('should throw when the fill amount is zero', async () => { - const fillableAmount = new BigNumber(5); - const signedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, - ); - const zeroFillAmount = new BigNumber(0); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, zeroFillAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); - }); - it('should throw when sender is not a taker', async () => { - const fillableAmount = new BigNumber(5); - const signedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, - ); - const nonExistentSenderAddress = userAddresses[6]; - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, nonExistentSenderAddress, - )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); + describe('fill order', () => { + describe('#fillOrderAsync', () => { + let makerTokenAddress: string; + let takerTokenAddress: string; + let coinbase: string; + let makerAddress: string; + let takerAddress: string; + let feeRecipient: string; + const fillTakerAmount = new BigNumber(5); + const shouldCheckTransfer = false; + before(async () => { + [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; + tokens = await zeroEx.tokenRegistry.getTokensAsync(); + const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); + makerTokenAddress = makerToken.address; + takerTokenAddress = takerToken.address; }); - it('should throw when order is expired', async () => { - const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 - const fillableAmount = new BigNumber(5); - const signedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, - ); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_EXPIRED); - }); - describe('should throw when not enough balance or allowance to fulfill the order', () => { - const fillableAmount = new BigNumber(5); - const balanceToSubtractFromMaker = new BigNumber(3); - const lackingAllowance = new BigNumber(3); - let signedOrder: SignedOrder; - beforeEach('create fillable signed order', async () => { - signedOrder = await fillScenarios.createFillableSignedOrderAsync( + describe('failed fills', () => { + it('should throw when the fill amount is zero', async () => { + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); + const zeroFillAmount = new BigNumber(0); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, zeroFillAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); }); - it('should throw when taker balance is less than fill amount', async () => { - await zeroEx.token.transferAsync( - takerTokenAddress, takerAddress, coinbase, balanceToSubtractFromMaker, + it('should throw when sender is not a taker', async () => { + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); + const nonExistentSenderAddress = userAddresses[6]; return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_BALANCE); + signedOrder, fillTakerAmount, shouldCheckTransfer, nonExistentSenderAddress, + )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); }); - it('should throw when taker allowance is less than fill amount', async () => { - const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); - await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, - newAllowanceWhichIsLessThanFillAmount); + it('should throw when order is expired', async () => { + const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, + fillableAmount, expirationInPast, + ); return expect(zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_ALLOWANCE); + )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_EXPIRED); + }); + describe('should throw when not enough balance or allowance to fulfill the order', () => { + const fillableAmount = new BigNumber(5); + const balanceToSubtractFromMaker = new BigNumber(3); + const lackingAllowance = new BigNumber(3); + let signedOrder: SignedOrder; + beforeEach('create fillable signed order', async () => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + }); + it('should throw when taker balance is less than fill amount', async () => { + await zeroEx.token.transferAsync( + takerTokenAddress, takerAddress, coinbase, balanceToSubtractFromMaker, + ); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_BALANCE); + }); + it('should throw when taker allowance is less than fill amount', async () => { + const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); + await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, + newAllowanceWhichIsLessThanFillAmount); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_ALLOWANCE); + }); + it('should throw when maker balance is less than maker fill amount', async () => { + await zeroEx.token.transferAsync( + makerTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker, + ); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_BALANCE); + }); + it('should throw when maker allowance is less than maker fill amount', async () => { + const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); + await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, + newAllowanceWhichIsLessThanFillAmount); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE); + }); }); - it('should throw when maker balance is less than maker fill amount', async () => { - await zeroEx.token.transferAsync( - makerTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker, + it('should throw when there a rounding error would have occurred', async () => { + const makerAmount = new BigNumber(3); + const takerAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createAsymmetricFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, + makerAmount, takerAmount, ); + const fillTakerAmountThatCausesRoundingError = new BigNumber(3); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_BALANCE); + signedOrder, fillTakerAmountThatCausesRoundingError, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); }); - it('should throw when maker allowance is less than maker fill amount', async () => { - const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); - await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, - newAllowanceWhichIsLessThanFillAmount); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE); + describe('should throw when not enough balance or allowance to pay fees', () => { + const fillableAmount = new BigNumber(5); + const makerFee = new BigNumber(2); + const takerFee = new BigNumber(2); + let signedOrder: SignedOrder; + beforeEach('setup', async () => { + signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerTokenAddress, takerTokenAddress, makerFee, takerFee, + makerAddress, takerAddress, fillableAmount, feeRecipient, + ); + }); + it('should throw when maker doesn\'t have enough balance to pay fees', async () => { + const balanceToSubtractFromMaker = new BigNumber(1); + await zeroEx.token.transferAsync( + zrxTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker, + ); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_BALANCE); + }); + it('should throw when maker doesn\'t have enough allowance to pay fees', async () => { + const newAllowanceWhichIsLessThanFees = makerFee.minus(1); + await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, makerAddress, + newAllowanceWhichIsLessThanFees); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE); + }); + it('should throw when taker doesn\'t have enough balance to pay fees', async () => { + const balanceToSubtractFromTaker = new BigNumber(1); + await zeroEx.token.transferAsync( + zrxTokenAddress, takerAddress, coinbase, balanceToSubtractFromTaker, + ); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_BALANCE); + }); + it('should throw when taker doesn\'t have enough allowance to pay fees', async () => { + const newAllowanceWhichIsLessThanFees = makerFee.minus(1); + await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, takerAddress, + newAllowanceWhichIsLessThanFees); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_ALLOWANCE); + }); }); }); - it('should throw when there a rounding error would have occurred', async () => { - const makerAmount = new BigNumber(3); - const takerAmount = new BigNumber(5); - const signedOrder = await fillScenarios.createAsymmetricFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, - makerAmount, takerAmount, - ); - const fillTakerAmountThatCausesRoundingError = new BigNumber(3); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmountThatCausesRoundingError, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); - }); - describe('should throw when not enough balance or allowance to pay fees', () => { - const fillableAmount = new BigNumber(5); - const makerFee = new BigNumber(2); - const takerFee = new BigNumber(2); - let signedOrder: SignedOrder; - beforeEach('setup', async () => { - signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( - makerTokenAddress, takerTokenAddress, makerFee, takerFee, - makerAddress, takerAddress, fillableAmount, feeRecipient, + describe('successful fills', () => { + it('should fill a valid order', async () => { + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillableAmount); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) + .to.be.bignumber.equal(0); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) + .to.be.bignumber.equal(0); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillableAmount); + await zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillTakerAmount); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillTakerAmount); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); }); - it('should throw when maker doesn\'t have enough balance to pay fees', async () => { - const balanceToSubtractFromMaker = new BigNumber(1); - await zeroEx.token.transferAsync( - zrxTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker, + it('should partially fill the valid order', async () => { + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_BALANCE); + const partialFillAmount = new BigNumber(3); + await zeroEx.exchange.fillOrderAsync( + signedOrder, partialFillAmount, shouldCheckTransfer, takerAddress); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) + .to.be.bignumber.equal(partialFillAmount); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) + .to.be.bignumber.equal(partialFillAmount); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); }); - it('should throw when maker doesn\'t have enough allowance to pay fees', async () => { - const newAllowanceWhichIsLessThanFees = makerFee.minus(1); - await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, makerAddress, - newAllowanceWhichIsLessThanFees); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE); - }); - it('should throw when taker doesn\'t have enough balance to pay fees', async () => { - const balanceToSubtractFromTaker = new BigNumber(1); - await zeroEx.token.transferAsync( - zrxTokenAddress, takerAddress, coinbase, balanceToSubtractFromTaker, + it('should fill the valid orders with fees', async () => { + const fillableAmount = new BigNumber(5); + const makerFee = new BigNumber(1); + const takerFee = new BigNumber(2); + const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerTokenAddress, takerTokenAddress, makerFee, takerFee, + makerAddress, takerAddress, fillableAmount, feeRecipient, ); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_BALANCE); + await zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress); + expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) + .to.be.bignumber.equal(makerFee.plus(takerFee)); }); - it('should throw when taker doesn\'t have enough allowance to pay fees', async () => { - const newAllowanceWhichIsLessThanFees = makerFee.minus(1); - await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, takerAddress, - newAllowanceWhichIsLessThanFees); - return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, - )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_ALLOWANCE); - }); - }); - }); - describe('successful fills', () => { - it('should fill a valid order', async () => { - const fillableAmount = new BigNumber(5); - const signedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, - ); - expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) - .to.be.bignumber.equal(fillableAmount); - expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) - .to.be.bignumber.equal(0); - expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) - .to.be.bignumber.equal(0); - expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) - .to.be.bignumber.equal(fillableAmount); - await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress); - expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) - .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); - expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) - .to.be.bignumber.equal(fillTakerAmount); - expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) - .to.be.bignumber.equal(fillTakerAmount); - expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) - .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); - }); - it('should partially fill the valid order', async () => { - const fillableAmount = new BigNumber(5); - const signedOrder = await fillScenarios.createFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, - ); - const partialFillAmount = new BigNumber(3); - await zeroEx.exchange.fillOrderAsync(signedOrder, partialFillAmount, shouldCheckTransfer, takerAddress); - expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) - .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); - expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) - .to.be.bignumber.equal(partialFillAmount); - expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) - .to.be.bignumber.equal(partialFillAmount); - expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) - .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); - }); - it('should fill the valid orders with fees', async () => { - const fillableAmount = new BigNumber(5); - const makerFee = new BigNumber(1); - const takerFee = new BigNumber(2); - const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( - makerTokenAddress, takerTokenAddress, makerFee, takerFee, - makerAddress, takerAddress, fillableAmount, feeRecipient, - ); - await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress); - expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) - .to.be.bignumber.equal(makerFee.plus(takerFee)); }); }); }); -- cgit v1.2.3 From 426f43391e0b762f03eb2aaf11e0a8d6c6aab301 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 13:33:04 +0200 Subject: Move initialization up --- test/exchange_wrapper_test.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 309791518..21d54e061 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -121,22 +121,22 @@ describe('ExchangeWrapper', () => { }); }); describe('fill order', () => { + let makerTokenAddress: string; + let takerTokenAddress: string; + let coinbase: string; + let makerAddress: string; + let takerAddress: string; + let feeRecipient: string; + const fillTakerAmount = new BigNumber(5); + const shouldCheckTransfer = false; + before(async () => { + [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; + tokens = await zeroEx.tokenRegistry.getTokensAsync(); + const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); + makerTokenAddress = makerToken.address; + takerTokenAddress = takerToken.address; + }); describe('#fillOrderAsync', () => { - let makerTokenAddress: string; - let takerTokenAddress: string; - let coinbase: string; - let makerAddress: string; - let takerAddress: string; - let feeRecipient: string; - const fillTakerAmount = new BigNumber(5); - const shouldCheckTransfer = false; - before(async () => { - [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; - tokens = await zeroEx.tokenRegistry.getTokensAsync(); - const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); - makerTokenAddress = makerToken.address; - takerTokenAddress = takerToken.address; - }); describe('failed fills', () => { it('should throw when the fill amount is zero', async () => { const fillableAmount = new BigNumber(5); -- cgit v1.2.3 From efbd81df0273a2b29b072b737bd04c4b3c065913 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 13:36:21 +0200 Subject: Move fillableAmount to initialization section --- test/exchange_wrapper_test.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 21d54e061..43f8683c8 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -127,6 +127,7 @@ describe('ExchangeWrapper', () => { let makerAddress: string; let takerAddress: string; let feeRecipient: string; + const fillableAmount = new BigNumber(5); const fillTakerAmount = new BigNumber(5); const shouldCheckTransfer = false; before(async () => { @@ -139,7 +140,6 @@ describe('ExchangeWrapper', () => { describe('#fillOrderAsync', () => { describe('failed fills', () => { it('should throw when the fill amount is zero', async () => { - const fillableAmount = new BigNumber(5); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); @@ -149,7 +149,6 @@ describe('ExchangeWrapper', () => { )).to.be.rejectedWith(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); }); it('should throw when sender is not a taker', async () => { - const fillableAmount = new BigNumber(5); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); @@ -160,7 +159,6 @@ describe('ExchangeWrapper', () => { }); it('should throw when order is expired', async () => { const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 - const fillableAmount = new BigNumber(5); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, @@ -170,7 +168,6 @@ describe('ExchangeWrapper', () => { )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_EXPIRED); }); describe('should throw when not enough balance or allowance to fulfill the order', () => { - const fillableAmount = new BigNumber(5); const balanceToSubtractFromMaker = new BigNumber(3); const lackingAllowance = new BigNumber(3); let signedOrder: SignedOrder; @@ -225,7 +222,6 @@ describe('ExchangeWrapper', () => { )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); }); describe('should throw when not enough balance or allowance to pay fees', () => { - const fillableAmount = new BigNumber(5); const makerFee = new BigNumber(2); const takerFee = new BigNumber(2); let signedOrder: SignedOrder; @@ -273,7 +269,6 @@ describe('ExchangeWrapper', () => { }); describe('successful fills', () => { it('should fill a valid order', async () => { - const fillableAmount = new BigNumber(5); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); @@ -297,7 +292,6 @@ describe('ExchangeWrapper', () => { .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); }); it('should partially fill the valid order', async () => { - const fillableAmount = new BigNumber(5); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); @@ -314,7 +308,6 @@ describe('ExchangeWrapper', () => { .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); }); it('should fill the valid orders with fees', async () => { - const fillableAmount = new BigNumber(5); const makerFee = new BigNumber(1); const takerFee = new BigNumber(2); const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( @@ -328,6 +321,22 @@ describe('ExchangeWrapper', () => { }); }); }); + describe('#batchFillOrderAsync', () => { + let anotherSignedOrder: SignedOrder; + let anotherOrderHashHex: string; + beforeEach(async () => { + anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + anotherOrderHashHex = await zeroEx.getOrderHashHexAsync(anotherSignedOrder); + }); + describe('failed batch fills', () => { + + }); + describe('successful batch fills', () => { + + }); + }); }); describe('cancel order(s)', () => { let makerTokenAddress: string; -- cgit v1.2.3 From 31b10973509ac1925a4cc6f5731a6c4db65b444c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 16:51:58 +0200 Subject: Remove only --- test/exchange_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 683c4b17d..b0aa351a4 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -414,7 +414,7 @@ describe('ExchangeWrapper', () => { return expect(zeroEx.exchange.batchCancelOrderAsync([])) .to.be.rejectedWith('Can not cancel an empty batch'); }); - it.only('should throw when orders have different makers', async () => { + it('should throw when orders have different makers', async () => { const signedOrderWithADifferentMaker = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, takerAddress, takerAddress, fillableAmount, ); -- cgit v1.2.3 From edbbf5a215209bcb67052ca6cb83bb40e149d9a7 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 19:11:21 +0200 Subject: Add success test --- test/exchange_wrapper_test.ts | 30 +++++++++++++++++++++++++++--- test/utils/fill_scenarios.ts | 8 ++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index b0aa351a4..748816949 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -16,7 +16,9 @@ import { ExchangeEvents, ContractEvent, DoneCallback, - ExchangeContractErrs, OrderCancellationRequest, + ExchangeContractErrs, + OrderCancellationRequest, + OrderFillRequest, } from '../src/types'; import {FillScenarios} from './utils/fill_scenarios'; import {TokenUtils} from './utils/token_utils'; @@ -132,7 +134,6 @@ describe('ExchangeWrapper', () => { const shouldCheckTransfer = false; before(async () => { [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; - tokens = await zeroEx.tokenRegistry.getTokensAsync(); const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); makerTokenAddress = makerToken.address; takerTokenAddress = takerToken.address; @@ -322,19 +323,42 @@ describe('ExchangeWrapper', () => { }); }); describe('#batchFillOrderAsync', () => { + let signedOrder: SignedOrder; + let signedOrderHashHex: string; let anotherSignedOrder: SignedOrder; let anotherOrderHashHex: string; + let orderFillBatch: OrderFillRequest[]; beforeEach(async () => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + signedOrderHashHex = await zeroEx.getOrderHashHexAsync(signedOrder); anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); anotherOrderHashHex = await zeroEx.getOrderHashHexAsync(anotherSignedOrder); + orderFillBatch = [ + { + signedOrder, + takerTokenFillAmount: fillTakerAmount, + }, + { + signedOrder: anotherSignedOrder, + takerTokenFillAmount: fillTakerAmount, + }, + ]; }); describe('failed batch fills', () => { }); describe('successful batch fills', () => { - + it('should successfully fill multiple orders', async () => { + await zeroEx.exchange.batchFillOrderAsync(orderFillBatch, shouldCheckTransfer, takerAddress); + const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); + const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); + expect(filledAmount).to.be.bignumber.equal(fillTakerAmount); + expect(anotherFilledAmount).to.be.bignumber.equal(fillTakerAmount); + }); }); }); }); diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index d8d6cd0b9..8ff27ceb1 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -70,9 +70,13 @@ export class FillScenarios { makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber, feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinbase, makerAddress, makerFillableAmount); - await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount); + const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(makerTokenAddress, makerAddress); + await this.zeroEx.token.setProxyAllowanceAsync( + makerTokenAddress, makerAddress, oldMakerAllowance.plus(makerFillableAmount)); await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinbase, takerAddress, takerFillableAmount); - await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount); + const oldTakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(takerTokenAddress, takerAddress); + await this.zeroEx.token.setProxyAllowanceAsync( + takerTokenAddress, takerAddress, oldTakerAllowance.plus(takerFillableAmount)); if (!makerFee.isZero()) { await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, makerAddress, makerFee); -- cgit v1.2.3 From 01c33ef8b7929ae936fd4bb84bb5d3aee3e63e8d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 19:12:43 +0200 Subject: Add no-op test --- test/exchange_wrapper_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 748816949..bd2536741 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -347,11 +347,11 @@ describe('ExchangeWrapper', () => { takerTokenFillAmount: fillTakerAmount, }, ]; - }); - describe('failed batch fills', () => { - }); describe('successful batch fills', () => { + it('should no-op for an empty batch', async () => { + await zeroEx.exchange.batchFillOrderAsync([], shouldCheckTransfer, takerAddress); + }); it('should successfully fill multiple orders', async () => { await zeroEx.exchange.batchFillOrderAsync(orderFillBatch, shouldCheckTransfer, takerAddress); const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); -- cgit v1.2.3 From 49d8b5b18b48604f852038662a0bb0ea598671e0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 16:28:55 +0200 Subject: Address feedback --- test/exchange_wrapper_test.ts | 6 +++--- test/utils/fill_scenarios.ts | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 2d7810bcc..5cc864d12 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -229,9 +229,9 @@ describe('ExchangeWrapper', () => { const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); - const nonExistentSenderAddress = userAddresses[6]; + const nonTakerAddress = userAddresses[6]; return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, nonExistentSenderAddress, + signedOrder, fillTakerAmount, shouldCheckTransfer, nonTakerAddress, )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); }); it('should throw when order is expired', async () => { @@ -520,7 +520,7 @@ describe('ExchangeWrapper', () => { order: signedOrderWithDifferentMaker, takerTokenCancelAmount: cancelAmount, }, - ])).to.be.rejectedWith('Can not cancel orders from multiple makers in a single batch'); + ])).to.be.rejectedWith(ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH); }); }); describe('successful batch cancels', () => { diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 8ff27ceb1..539333b9b 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -72,19 +72,29 @@ export class FillScenarios { await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinbase, makerAddress, makerFillableAmount); const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(makerTokenAddress, makerAddress); await this.zeroEx.token.setProxyAllowanceAsync( - makerTokenAddress, makerAddress, oldMakerAllowance.plus(makerFillableAmount)); + makerTokenAddress, makerAddress, oldMakerAllowance.plus(makerFillableAmount), + ); await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinbase, takerAddress, takerFillableAmount); const oldTakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(takerTokenAddress, takerAddress); await this.zeroEx.token.setProxyAllowanceAsync( - takerTokenAddress, takerAddress, oldTakerAllowance.plus(takerFillableAmount)); + takerTokenAddress, takerAddress, oldTakerAllowance.plus(takerFillableAmount), + ); if (!makerFee.isZero()) { await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, makerAddress, makerFee); - await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, makerAddress, makerFee); + const oldMakerFeeAllowance = + await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, makerAddress); + await this.zeroEx.token.setProxyAllowanceAsync( + this.zrxTokenAddress, makerAddress, oldMakerFeeAllowance.plus(makerFee), + ); } if (!takerFee.isZero()) { await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, takerAddress, takerFee); - await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee); + const oldTakerFeeAllowance = + await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, takerAddress); + await this.zeroEx.token.setProxyAllowanceAsync( + this.zrxTokenAddress, takerAddress, oldTakerFeeAllowance.plus(takerFee), + ); } const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, -- cgit v1.2.3 From 6629a716b9dccbc5f07f60830dfe356c4c434f52 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 17:18:00 +0200 Subject: Don't pass expressions as parameters --- test/utils/fill_scenarios.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 539333b9b..a90fc5f57 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -71,13 +71,15 @@ export class FillScenarios { feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinbase, makerAddress, makerFillableAmount); const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(makerTokenAddress, makerAddress); + const newMakerAllowance = oldMakerAllowance.plus(makerFillableAmount); await this.zeroEx.token.setProxyAllowanceAsync( - makerTokenAddress, makerAddress, oldMakerAllowance.plus(makerFillableAmount), + makerTokenAddress, makerAddress, newMakerAllowance, ); await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinbase, takerAddress, takerFillableAmount); const oldTakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(takerTokenAddress, takerAddress); + const newTakerAllowance = oldTakerAllowance.plus(takerFillableAmount); await this.zeroEx.token.setProxyAllowanceAsync( - takerTokenAddress, takerAddress, oldTakerAllowance.plus(takerFillableAmount), + takerTokenAddress, takerAddress, newTakerAllowance, ); if (!makerFee.isZero()) { -- cgit v1.2.3 From f7953511bb1886c6fe3810462926bdbdd0088781 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 17:18:55 +0200 Subject: Don't pass expressions as parameters --- test/utils/fill_scenarios.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index a90fc5f57..2860f1472 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -86,16 +86,18 @@ export class FillScenarios { await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, makerAddress, makerFee); const oldMakerFeeAllowance = await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, makerAddress); + const newMakerFeeAllowance = oldMakerFeeAllowance.plus(makerFee); await this.zeroEx.token.setProxyAllowanceAsync( - this.zrxTokenAddress, makerAddress, oldMakerFeeAllowance.plus(makerFee), + this.zrxTokenAddress, makerAddress, newMakerFeeAllowance, ); } if (!takerFee.isZero()) { await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, takerAddress, takerFee); const oldTakerFeeAllowance = await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, takerAddress); + const newTakerFeeAllowance = oldTakerFeeAllowance.plus(takerFee); await this.zeroEx.token.setProxyAllowanceAsync( - this.zrxTokenAddress, takerAddress, oldTakerFeeAllowance.plus(takerFee), + this.zrxTokenAddress, takerAddress, newTakerFeeAllowance, ); } -- cgit v1.2.3