aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-18 08:40:19 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-26 04:25:56 +0800
commitdefd09459dd774791b5bb88e2ec3a5216e8b6b4a (patch)
tree28b26c6f89f8e5b0d284b93423ad9c032697d9d8 /test
parent58d2b799d6adb8d8af7565af4b63e3a3c5748c10 (diff)
downloaddexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.gz
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.bz2
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.lz
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.xz
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.tar.zst
dexon-sol-tools-defd09459dd774791b5bb88e2ec3a5216e8b6b4a.zip
Cover all possible branches of order validation errors with tests
Diffstat (limited to 'test')
-rw-r--r--test/exchange_wrapper_test.ts73
1 files changed, 59 insertions, 14 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 813afdddd..2488e6428 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -303,20 +303,65 @@ describe('ExchangeWrapper', () => {
)).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerFeeAllowance);
});
});
- it('should throw when maker has balance to cover fees or transfer but not both', async () => {
- const makerFee = new BigNumber(1);
- const takerFee = new BigNumber(1);
- const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
- zrxTokenAddress, takerTokenAddress, makerFee, takerFee,
- makerAddress, takerAddress, fillableAmount, feeRecipient,
- );
- 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.InsufficientMakerBalance);
+ describe('should throw on insufficient balance or allowance when makerToken is ZRX',
+ () => {
+ const makerFee = new BigNumber(2);
+ const takerFee = new BigNumber(2);
+ let signedOrder: SignedOrder;
+ beforeEach(async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
+ zrxTokenAddress, takerTokenAddress, makerFee, takerFee,
+ makerAddress, takerAddress, fillableAmount, feeRecipient,
+ );
+ });
+ it('should throw on insufficient balance when makerToken is ZRX', 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.InsufficientMakerBalance);
+ });
+ it('should throw on insufficient allowance when makerToken is ZRX', async () => {
+ const oldAllowance = await zeroEx.token.getProxyAllowanceAsync(zrxTokenAddress, makerAddress);
+ const newAllowanceWhichIsInsufficient = oldAllowance.minus(1);
+ await zeroEx.token.setProxyAllowanceAsync(
+ zrxTokenAddress, makerAddress, newAllowanceWhichIsInsufficient);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerAllowance);
+ });
+ });
+ describe('should throw on insufficient balance or allowance when takerToken is ZRX',
+ () => {
+ const makerFee = new BigNumber(2);
+ const takerFee = new BigNumber(2);
+ let signedOrder: SignedOrder;
+ before(async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
+ makerTokenAddress, zrxTokenAddress, makerFee, takerFee,
+ makerAddress, takerAddress, fillableAmount, feeRecipient,
+ );
+ });
+ it('should throw on insufficient balance when takerToken is ZRX', 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.InsufficientTakerBalance);
+ });
+ it('should throw on insufficient allowance when takerToken is ZRX', async () => {
+ const oldAllowance = await zeroEx.token.getProxyAllowanceAsync(zrxTokenAddress, takerAddress);
+ const newAllowanceWhichIsInsufficient = oldAllowance.minus(1);
+ await zeroEx.token.setProxyAllowanceAsync(
+ zrxTokenAddress, takerAddress, newAllowanceWhichIsInsufficient);
+ return expect(zeroEx.exchange.fillOrderAsync(
+ signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress,
+ )).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerAllowance);
+ });
});
});
describe('successful fills', () => {