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 196130ff96cd20bd13c7bada0ba5eb8d62a2cdc5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 8 Jun 2017 12:06:04 +0200 Subject: Make web3Wrapper protected instead of public --- test/0x.js_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 58f259a11..9cba93488 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -35,9 +35,9 @@ describe('ZeroEx library', () => { // Check that all nested web3 instances return the updated provider const nestedWeb3WrapperProvider = (zeroEx as any).web3Wrapper.getCurrentProvider(); expect((nestedWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); - const exchangeWeb3WrapperProvider = zeroEx.exchange.web3Wrapper.getCurrentProvider(); + const exchangeWeb3WrapperProvider = (zeroEx.exchange as any).web3Wrapper.getCurrentProvider(); expect((exchangeWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); - const tokenRegistryWeb3WrapperProvider = zeroEx.tokenRegistry.web3Wrapper.getCurrentProvider(); + const tokenRegistryWeb3WrapperProvider = (zeroEx.tokenRegistry as any).web3Wrapper.getCurrentProvider(); expect((tokenRegistryWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); }); }); -- cgit v1.2.3 From 8311203f73bf6eff8bcac8d1fb72f9cf8b65c45b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 12:14:35 +0200 Subject: Refactor isValidSignature --- test/exchange_wrapper_test.ts | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 08936f1d2..aed3c3c0b 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -51,7 +51,7 @@ describe('ExchangeWrapper', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); - describe('#isValidSignatureAsync', () => { + describe('#isValidSignatureUsingContractCallAsync', () => { // The Exchange smart contract `isValidSignature` method only validates orderHashes and assumes // the length of the data is exactly 32 bytes. Thus for these tests, we use data of this size. const dataHex = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; @@ -68,8 +68,9 @@ describe('ExchangeWrapper', () => { r: signature.r, s: signature.s, }; - return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected(); + return expect((zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), + ).to.be.rejected(); }); it('r lacks 0x prefix', async () => { const malformedR = signature.r.replace('0x', ''); @@ -78,8 +79,9 @@ describe('ExchangeWrapper', () => { r: malformedR, s: signature.s, }; - return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected(); + return expect((zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), + ).to.be.rejected(); }); it('r is too short', async () => { const malformedR = signature.r.substr(10); @@ -88,8 +90,9 @@ describe('ExchangeWrapper', () => { r: malformedR, s: signature.s.replace('0', 'z'), }; - return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected(); + return expect((zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), + ).to.be.rejected(); }); it('s is not hex', async () => { const malformedS = signature.s.replace('0', 'z'); @@ -98,26 +101,31 @@ describe('ExchangeWrapper', () => { r: signature.r, s: malformedS, }; - return expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected(); + return expect((zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), + ).to.be.rejected(); }); }); it('should return false if the data doesn\'t pertain to the signature & address', async () => { - const isValid = await zeroEx.exchange.isValidSignatureAsync('0x0', signature, address); + const isValid = await (zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync('0x0', signature, address); expect(isValid).to.be.false(); }); it('should return false if the address doesn\'t pertain to the signature & dataHex', async () => { const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; - const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, signature, validUnrelatedAddress); + const isValid = await (zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, signature, validUnrelatedAddress); expect(isValid).to.be.false(); }); it('should return false if the signature doesn\'t pertain to the dataHex & address', async () => { const wrongSignature = {...signature, v: 28}; - const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, wrongSignature, address); + const isValid = await (zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, wrongSignature, address); expect(isValid).to.be.false(); }); it('should return true if the signature does pertain to the dataHex & address', async () => { - const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, signature, address); + const isValid = await (zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, signature, address); expect(isValid).to.be.true(); }); }); -- cgit v1.2.3 From cb68f9c9ec52463a1c9a865a446bc9acbc4b703d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 12:20:01 +0200 Subject: Remove tests for isValidSignatureUsingContractCallAsync --- test/exchange_wrapper_test.ts | 78 ------------------------------------------- 1 file changed, 78 deletions(-) (limited to 'test') diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index aed3c3c0b..bd52f155a 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -51,84 +51,6 @@ describe('ExchangeWrapper', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); - describe('#isValidSignatureUsingContractCallAsync', () => { - // The Exchange smart contract `isValidSignature` method only validates orderHashes and assumes - // the length of the data is exactly 32 bytes. Thus for these tests, we use data of this size. - const dataHex = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; - const signature = { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - }; - const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; - describe('should throw if passed a malformed signature', () => { - it('malformed v', async () => { - const malformedSignature = { - v: 34, - r: signature.r, - s: signature.s, - }; - return expect((zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), - ).to.be.rejected(); - }); - it('r lacks 0x prefix', async () => { - const malformedR = signature.r.replace('0x', ''); - const malformedSignature = { - v: signature.v, - r: malformedR, - s: signature.s, - }; - return expect((zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), - ).to.be.rejected(); - }); - it('r is too short', async () => { - const malformedR = signature.r.substr(10); - const malformedSignature = { - v: signature.v, - r: malformedR, - s: signature.s.replace('0', 'z'), - }; - return expect((zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), - ).to.be.rejected(); - }); - it('s is not hex', async () => { - const malformedS = signature.s.replace('0', 'z'); - const malformedSignature = { - v: signature.v, - r: signature.r, - s: malformedS, - }; - return expect((zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, malformedSignature, address), - ).to.be.rejected(); - }); - }); - it('should return false if the data doesn\'t pertain to the signature & address', async () => { - const isValid = await (zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync('0x0', signature, address); - expect(isValid).to.be.false(); - }); - it('should return false if the address doesn\'t pertain to the signature & dataHex', async () => { - const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; - const isValid = await (zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, signature, validUnrelatedAddress); - expect(isValid).to.be.false(); - }); - it('should return false if the signature doesn\'t pertain to the dataHex & address', async () => { - const wrongSignature = {...signature, v: 28}; - const isValid = await (zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, wrongSignature, address); - expect(isValid).to.be.false(); - }); - it('should return true if the signature does pertain to the dataHex & address', async () => { - const isValid = await (zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, signature, address); - expect(isValid).to.be.true(); - }); - }); describe('#fillOrKillOrderAsync', () => { let makerTokenAddress: string; let takerTokenAddress: string; -- cgit v1.2.3 From a0fd89aeebc41b52b845674fd83edeccbb7f7bd8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 14:24:12 +0200 Subject: Rewrite isValidSignature tests --- test/0x.js_test.ts | 76 ++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 51 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 58f259a11..78032006b 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -6,8 +6,9 @@ import * as BigNumber from 'bignumber.js'; import * as Sinon from 'sinon'; import {ZeroEx} from '../src/0x.js'; import {constants} from './utils/constants'; -import {web3Factory} from './utils/web3_factory'; import {Order} from '../src/types'; +import {ECSignature} from '../src/types'; +import {web3Factory} from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; @@ -51,60 +52,33 @@ describe('ZeroEx library', () => { s: '0x2d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee', }; const address = '0x9b2055d370f73ec7d8a03e965129118dc8f5bf83'; - describe('should throw if passed a malformed signature', () => { - it('malformed v', () => { - const malformedSignature = { - v: 34, - r: signature.r, - s: signature.s, - }; - expect(() => ZeroEx.isValidSignature(data, malformedSignature, address)).to.throw(); - }); - it('r lacks 0x prefix', () => { - const malformedR = signature.r.replace('0x', ''); - const malformedSignature = { - v: signature.v, - r: malformedR, - s: signature.s, - }; - expect(() => ZeroEx.isValidSignature(data, malformedSignature, address)).to.throw(); - }); - it('r is too short', () => { - const malformedR = signature.r.substr(10); - const malformedSignature = { - v: signature.v, - r: malformedR, - s: signature.s.replace('0', 'z'), - }; - expect(() => ZeroEx.isValidSignature(data, malformedSignature, address)).to.throw(); - }); - it('s is not hex', () => { - const malformedS = signature.s.replace('0', 'z'); - const malformedSignature = { - v: signature.v, - r: signature.r, - s: malformedS, - }; - expect(() => ZeroEx.isValidSignature(data, malformedSignature, address)).to.throw(); - }); - }); - it('should return false if the data doesn\'t pertain to the signature & address', () => { - const isValid = ZeroEx.isValidSignature('0x0', signature, address); - expect(isValid).to.be.false(); + const web3 = web3Factory.create(); + const zeroEx = new ZeroEx(web3); + it('should return false if the data doesn\'t pertain to the signature & address', async () => { + expect(ZeroEx.isValidSignature('0x0', signature, address)).to.be.false(); + return expect( + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync('0x0', signature, address), + ).to.become(false); }); - it('should return false if the address doesn\'t pertain to the signature & data', () => { + it('should return false if the address doesn\'t pertain to the signature & data', async () => { const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; - const isValid = ZeroEx.isValidSignature(data, signature, validUnrelatedAddress); - expect(isValid).to.be.false(); + expect(ZeroEx.isValidSignature(data, signature, validUnrelatedAddress)).to.be.false(); + return expect( + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, validUnrelatedAddress) + ).to.become(false); }); - it('should return false if the signature doesn\'t pertain to the data & address', () => { + it('should return false if the signature doesn\'t pertain to the data & address', async () => { const wrongSignature = _.assign({}, signature, {v: 28}); - const isValid = ZeroEx.isValidSignature(data, wrongSignature, address); - expect(isValid).to.be.false(); - }); - it('should return true if the signature does pertain to the data & address', () => { - const isValid = ZeroEx.isValidSignature(data, signature, address); - expect(isValid).to.be.true(); + expect(ZeroEx.isValidSignature(data, wrongSignature, address)).to.be.false(); + return expect( + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, wrongSignature, address) + ).to.become(false); + }); + it('should return true if the signature does pertain to the data & address', async () => { + expect(ZeroEx.isValidSignature(data, signature, address)).to.be.true(); + return expect( + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, address) + ).to.become(true); }); }); describe('#generateSalt', () => { -- cgit v1.2.3 From 807e62e76e87ed8eb12ebf8d7b6f1a92e9d34f3b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 14:31:05 +0200 Subject: Fix linter error --- test/0x.js_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 78032006b..d41cbefd7 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -64,20 +64,20 @@ describe('ZeroEx library', () => { const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; expect(ZeroEx.isValidSignature(data, signature, validUnrelatedAddress)).to.be.false(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, validUnrelatedAddress) + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, validUnrelatedAddress), ).to.become(false); }); it('should return false if the signature doesn\'t pertain to the data & address', async () => { const wrongSignature = _.assign({}, signature, {v: 28}); expect(ZeroEx.isValidSignature(data, wrongSignature, address)).to.be.false(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, wrongSignature, address) + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, wrongSignature, address), ).to.become(false); }); it('should return true if the signature does pertain to the data & address', async () => { expect(ZeroEx.isValidSignature(data, signature, address)).to.be.true(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, address) + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, address), ).to.become(true); }); }); -- 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 From 31cc75bd6d2651466ebf50e9374d5cd19de6dd5e Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 8 Jun 2017 18:02:31 +0200 Subject: Fix isValidSignature tests --- test/0x.js_test.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index d33480c6b..1349d6360 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -43,15 +43,15 @@ describe('ZeroEx library', () => { }); }); describe('#isValidSignature', () => { - // This test data was borrowed from the JSON RPC documentation - // Source: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign - const data = '0xdeadbeaf'; + // The Exchange smart contract `isValidSignature` method only validates orderHashes and assumes + // the length of the data is exactly 32 bytes. Thus for these tests, we use data of this size. + const dataHex = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; const signature = { v: 27, - r: '0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a1', - s: '0x2d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee', + r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', }; - const address = '0x9b2055d370f73ec7d8a03e965129118dc8f5bf83'; + const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); it('should return false if the data doesn\'t pertain to the signature & address', async () => { @@ -62,23 +62,25 @@ describe('ZeroEx library', () => { }); it('should return false if the address doesn\'t pertain to the signature & data', async () => { const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; - expect(ZeroEx.isValidSignature(data, signature, validUnrelatedAddress)).to.be.false(); + expect(ZeroEx.isValidSignature(dataHex, signature, validUnrelatedAddress)).to.be.false(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, validUnrelatedAddress), + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(dataHex, signature, + validUnrelatedAddress), ).to.become(false); }); - it('should return false if the signature doesn\'t pertain to the data & address', async () => { + it('should return false if the signature doesn\'t pertain to the dataHex & address', async () => { const wrongSignature = _.assign({}, signature, {v: 28}); - expect(ZeroEx.isValidSignature(data, wrongSignature, address)).to.be.false(); + expect(ZeroEx.isValidSignature(dataHex, wrongSignature, address)).to.be.false(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, wrongSignature, address), + (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(dataHex, wrongSignature, address), ).to.become(false); }); - it('should return true if the signature does pertain to the data & address', async () => { - expect(ZeroEx.isValidSignature(data, signature, address)).to.be.true(); - return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(data, signature, address), - ).to.become(true); + it('should return true if the signature does pertain to the dataHex & address', async () => { + const isValidSignatureLocal = ZeroEx.isValidSignature(dataHex, signature, address); + expect(isValidSignatureLocal).to.be.true(); + const isValidSignatureOnContract = await (zeroEx.exchange as any) + .isValidSignatureUsingContractCallAsync(dataHex, signature, address); + return expect(isValidSignatureOnContract).to.be.true(); }); }); describe('#generateSalt', () => { -- cgit v1.2.3