diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-02 22:18:54 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-02 22:18:54 +0800 |
commit | c650d1ba204a862de81b225118d9bcd1a38ad25d (patch) | |
tree | 746a4674576a3e906509247bcea4a50b2ed747ed /test | |
parent | d8587875b82ae2fde6dad1334a586c36cda2bfec (diff) | |
download | dexon-0x-contracts-c650d1ba204a862de81b225118d9bcd1a38ad25d.tar dexon-0x-contracts-c650d1ba204a862de81b225118d9bcd1a38ad25d.tar.gz dexon-0x-contracts-c650d1ba204a862de81b225118d9bcd1a38ad25d.tar.bz2 dexon-0x-contracts-c650d1ba204a862de81b225118d9bcd1a38ad25d.tar.lz dexon-0x-contracts-c650d1ba204a862de81b225118d9bcd1a38ad25d.tar.xz dexon-0x-contracts-c650d1ba204a862de81b225118d9bcd1a38ad25d.tar.zst dexon-0x-contracts-c650d1ba204a862de81b225118d9bcd1a38ad25d.zip |
Add tests and checks for fees balances and allowances
Diffstat (limited to 'test')
-rw-r--r-- | test/exchange_wrapper_test.ts | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index ecb5a408b..6f4105e1e 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -9,7 +9,7 @@ import promisify = require('es6-promisify'); import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src/0x.js'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; -import {FillOrderValidationErrs, Token} from '../src/types'; +import {FillOrderValidationErrs, SignedOrder, Token} from '../src/types'; import {FillScenarios} from './utils/fill_scenarios'; import {TokenUtils} from './utils/token_utils'; @@ -222,6 +222,49 @@ describe('ExchangeWrapper', () => { signedOrder, fillTakerAmountInBaseUnitsThatCausesRoundingError, shouldCheckTransfer, )).to.be.rejectedWith(FillOrderValidationErrs.ROUNDING_ERROR); }); + describe('should raise 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, + ); + zeroEx.setTransactionSenderAccount(takerAddress); + }); + it('should throw when maker doesn\'t have enough balance to pay fees', async () => { + const lackingBalance = new BigNumber(1); + await zeroEx.token.transferAsync(zrxTokenAddress, makerAddress, coinBase, lackingBalance); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, + )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_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, fillTakerAmountInBaseUnits, shouldCheckTransfer, + )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_MAKER_FEE_ALLOWANCE); + }); + it('should throw when taker doesn\'t have enough balance to pay fees', async () => { + const lackingBalance = new BigNumber(1); + await zeroEx.token.transferAsync(zrxTokenAddress, takerAddress, coinBase, lackingBalance); + return expect(zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, + )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_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, fillTakerAmountInBaseUnits, shouldCheckTransfer, + )).to.be.rejectedWith(FillOrderValidationErrs.NOT_ENOUGH_TAKER_FEE_ALLOWANCE); + }); + }); }); describe('successful fills', () => { it('should fill the valid order', async () => { |