diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-01 21:52:11 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-01 21:52:11 +0800 |
commit | 73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92 (patch) | |
tree | be077e8e1869bdc070401654133c1ac6762bdc98 /test/exchange_wrapper_test.ts | |
parent | 6a57c42e253a52a449cae8a5c6565276cb01a86c (diff) | |
parent | d8e35c364ea94b606810b340fb02d8706e257c3c (diff) | |
download | dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.gz dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.bz2 dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.lz dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.xz dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.zst dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.zip |
Merge branch 'fillOrderAsync' of github.com:0xProject/0x.js into fillOrderAsync
# Conflicts:
# src/contract_wrappers/exchange_wrapper.ts
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r-- | test/exchange_wrapper_test.ts | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index b2fb1894b..f929df149 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -7,7 +7,7 @@ import * as _ from 'lodash'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import * as BigNumber from 'bignumber.js'; import {orderFactory} from './utils/order_factory'; -import {Token} from '../src/types'; +import {FillOrderValidationErrs, Token} from '../src/types'; import * as Web3 from 'web3'; import * as dirtyChai from 'dirty-chai'; import ChaiBigNumber = require('chai-bignumber'); @@ -107,6 +107,9 @@ describe('ExchangeWrapper', () => { let tokens: Token[]; const addressBySymbol: {[symbol: string]: string} = {}; let networkId: number; + let maker: string; + let taker: string; + const fillAmount = new BigNumber(5); const setBalance = async (toAddress: string, amountInBaseUnits: BigNumber.BigNumber|number, tokenAddress: string) => { @@ -126,31 +129,43 @@ describe('ExchangeWrapper', () => { }); networkId = await promisify(web3.version.getNetwork)(); }); + beforeEach('get ready for fill', async () => { + [maker, taker] = userAddresses; + zeroEx.setDefaultAccount(taker); + await setAllowance(maker, 5, addressBySymbol.MLN); + await setBalance(taker, 5, addressBySymbol.GNT); + await setAllowance(taker, 5, addressBySymbol.GNT); + }); + afterEach('reset sender', () => { + zeroEx.setDefaultAccount(userAddresses[0]); + }); describe('failed fills', () => { it('should throw when the fill amount is zero', async () => { - const maker = userAddresses[0]; - const taker = userAddresses[1]; const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker, 5, addressBySymbol.MLN, 5, addressBySymbol.GNT); - const fillAmount = new BigNumber(0); expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount)) - .to.be.rejectedWith('This order has already been filled or cancelled'); + .to.be.rejectedWith(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO); + }); + it('should throw when sender is not a taker', async () => { + const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker, + 5, addressBySymbol.MLN, 5, addressBySymbol.GNT); + const notTaker = userAddresses[2]; + zeroEx.setDefaultAccount(notTaker); + expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount)) + .to.be.rejectedWith(FillOrderValidationErrs.NOT_A_TAKER); + }); + it('should throw when order is expired', async () => { + const OLD_TIMESTAMP = new BigNumber(42); + const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker, + 5, addressBySymbol.MLN, 5, addressBySymbol.GNT, OLD_TIMESTAMP); + expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount)) + .to.be.rejectedWith(FillOrderValidationErrs.EXPIRED); }); }); describe('successful fills', () => { - afterEach('reset default account', () => { - zeroEx.setDefaultAccount(userAddresses[0]); - }); it('should fill the valid order', async () => { - const maker = userAddresses[0]; - const taker = userAddresses[1]; - await setAllowance(maker, 5, addressBySymbol.MLN); - await setBalance(taker, 5, addressBySymbol.GNT); - await setAllowance(taker, 5, addressBySymbol.GNT); const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker, 5, addressBySymbol.MLN, 5, addressBySymbol.GNT); - const fillAmount = new BigNumber(5); - zeroEx.setDefaultAccount(taker); await zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount); expect(await zeroEx.token.getBalanceAsync(addressBySymbol.MLN, taker)).to.be.bignumber.equal(5); expect(await zeroEx.token.getBalanceAsync(addressBySymbol.GNT, taker)).to.be.bignumber.equal(0); |