aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-12-14 22:31:37 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-12-14 22:47:03 +0800
commit28c409fc6d635ee8ed1430d97d9bbdde2f613e37 (patch)
tree419b94ff1d080c279ebe0ce94a87a42aeb20f746 /packages/0x.js/test
parent449a04d39ce49ac06e0de989dcbefe6f4a7d2e84 (diff)
downloaddexon-sol-tools-28c409fc6d635ee8ed1430d97d9bbdde2f613e37.tar
dexon-sol-tools-28c409fc6d635ee8ed1430d97d9bbdde2f613e37.tar.gz
dexon-sol-tools-28c409fc6d635ee8ed1430d97d9bbdde2f613e37.tar.bz2
dexon-sol-tools-28c409fc6d635ee8ed1430d97d9bbdde2f613e37.tar.lz
dexon-sol-tools-28c409fc6d635ee8ed1430d97d9bbdde2f613e37.tar.xz
dexon-sol-tools-28c409fc6d635ee8ed1430d97d9bbdde2f613e37.tar.zst
dexon-sol-tools-28c409fc6d635ee8ed1430d97d9bbdde2f613e37.zip
Add a function to init token balances
Diffstat (limited to 'packages/0x.js/test')
-rw-r--r--packages/0x.js/test/utils/fill_scenarios.ts25
-rw-r--r--packages/0x.js/test/utils/token_utils.ts9
2 files changed, 30 insertions, 4 deletions
diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts
index 090493935..bcaa63c78 100644
--- a/packages/0x.js/test/utils/fill_scenarios.ts
+++ b/packages/0x.js/test/utils/fill_scenarios.ts
@@ -1,10 +1,15 @@
+import {Web3Wrapper} from '@0xproject/web3-wrapper';
import BigNumber from 'bignumber.js';
import {SignedOrder, Token, ZeroEx} from '../../src';
+import {artifacts} from '../../src/artifacts';
+import {DummyTokenContract} from '../../src/contract_wrappers/generated/dummy_token';
import {orderFactory} from '../utils/order_factory';
import {constants} from './constants';
+const INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS = new BigNumber(100);
+
export class FillScenarios {
private zeroEx: ZeroEx;
private userAddresses: string[];
@@ -21,6 +26,26 @@ export class FillScenarios {
this.zrxTokenAddress = zrxTokenAddress;
this.exchangeContractAddress = exchangeContractAddress;
}
+ public async initTokenBalancesAsync() {
+ const web3Wrapper = (this.zeroEx as any)._web3Wrapper as Web3Wrapper;
+ for (const token of this.tokens) {
+ if (token.symbol === 'WETH') {
+ // _.noop
+ } else if (token.symbol !== 'ZRX') {
+ const contractInstance = web3Wrapper.getContractInstance(
+ artifacts.DummyTokenArtifact.abi, token.address,
+ );
+ const dummyToken = new DummyTokenContract(contractInstance, {});
+ const tokenSupply = ZeroEx.toBaseUnitAmount(INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS, token.decimals);
+ const txHash = await dummyToken.setBalance.sendTransactionAsync(this.coinbase, tokenSupply, {
+ from: this.coinbase,
+ });
+ await this.zeroEx.awaitTransactionMinedAsync(txHash);
+ } else {
+ // no-op
+ }
+ }
+ }
public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
makerAddress: string, takerAddress: string,
fillableAmount: BigNumber,
diff --git a/packages/0x.js/test/utils/token_utils.ts b/packages/0x.js/test/utils/token_utils.ts
index 9c20f52a1..4634899a7 100644
--- a/packages/0x.js/test/utils/token_utils.ts
+++ b/packages/0x.js/test/utils/token_utils.ts
@@ -3,6 +3,7 @@ import * as _ from 'lodash';
import {InternalZeroExError, Token} from '../../src/types';
const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
+const WETH_TOKEN_SYMBOL = 'WETH';
export class TokenUtils {
private tokens: Token[];
@@ -16,10 +17,10 @@ export class TokenUtils {
}
return zrxToken;
}
- public getNonProtocolTokens(): Token[] {
- const nonProtocolTokens = _.filter(this.tokens, token => {
- return token.symbol !== PROTOCOL_TOKEN_SYMBOL;
+ public getDummyTokens(): Token[] {
+ const dummyTokens = _.filter(this.tokens, token => {
+ return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
});
- return nonProtocolTokens;
+ return dummyTokens;
}
}