diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-31 22:03:16 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-31 22:03:16 +0800 |
commit | 84c652d205af0fd289149762661536895eaaafef (patch) | |
tree | 7141c486bb65fe5673fd04464a61ff71869e0637 /test | |
parent | 7f269cd791e4f0ed1515e90478de6b35683ce2bf (diff) | |
download | dexon-sol-tools-84c652d205af0fd289149762661536895eaaafef.tar dexon-sol-tools-84c652d205af0fd289149762661536895eaaafef.tar.gz dexon-sol-tools-84c652d205af0fd289149762661536895eaaafef.tar.bz2 dexon-sol-tools-84c652d205af0fd289149762661536895eaaafef.tar.lz dexon-sol-tools-84c652d205af0fd289149762661536895eaaafef.tar.xz dexon-sol-tools-84c652d205af0fd289149762661536895eaaafef.tar.zst dexon-sol-tools-84c652d205af0fd289149762661536895eaaafef.zip |
Revert tests
Diffstat (limited to 'test')
-rw-r--r-- | test/exchange_wrapper_test.ts | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index ede4198d8..ad82e6e82 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -2,18 +2,25 @@ import 'mocha'; import * as chai from 'chai'; import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src/0x.js'; +import promisify = require('es6-promisify'); +import * as _ from 'lodash'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import * as BigNumber from 'bignumber.js'; import {createSignedOrder} from './utils/order'; +import {Token} from '../src/types'; +import * as Web3 from 'web3'; const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(); describe('ExchangeWrapper', () => { let zeroEx: ZeroEx; + let userAddresses: string[]; + let web3: Web3; before(async () => { - const web3 = web3Factory.create(); + web3 = web3Factory.create(); zeroEx = new ZeroEx(web3); + userAddresses = await promisify(web3.eth.getAccounts)(); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -91,12 +98,41 @@ describe('ExchangeWrapper', () => { expect(isValid).to.be.true; }); }); - describe('#fillOrderAsync', async () => { - const signedOrder = await createSignedOrder(zeroEx); - it('should throw when the fill amount is zero', async () => { - const fillAmount = new BigNumber(0); - expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount)) - .to.be.rejectedWith('This order has already been filled or cancelled'); + describe('#fillOrderAsync', () => { + let tokens: Token[]; + const giveMeTokens = async (toAddress: string, + amountInBaseUnits: BigNumber.BigNumber|number, + symbol: string) => { + const amount = _.isNumber(amountInBaseUnits) ? new BigNumber(amountInBaseUnits) : amountInBaseUnits; + const token = _.find(tokens, {symbol}); + if (_.isUndefined(token)) { + throw new Error(`Token ${symbol} not found`); + } else { + await zeroEx.token.transferAsync(token.address, userAddresses[0], toAddress, amount); + } + }; + before('fetch tokens', async () => { + tokens = await zeroEx.tokenRegistry.getTokensAsync(); + }); + describe('failed fills', () => { + it('should throw when the fill amount is zero', async () => { + const signedOrder = await createSignedOrder(zeroEx, tokens, 5, 'MLN', 5, 'GNT'); + const fillAmount = new BigNumber(0); + expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount)) + .to.be.rejectedWith('This order has already been filled or cancelled'); + }); + }); + describe('successful fills', () => { + afterEach('reset default account', () => { + web3.eth.defaultAccount = userAddresses[0]; + }); + it('should fill the valid order', async () => { + const signedOrder = await createSignedOrder(zeroEx, tokens, 5, 'MLN', 5, 'GNT'); + await giveMeTokens(userAddresses[0], 5, 'GNT'); + const fillAmount = new BigNumber(0); + web3.eth.defaultAccount = userAddresses[1]; + expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount)).to.become(undefined); + }); }); }); }); |