aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/test/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-10 02:36:28 +0800
committerFabio Berger <me@fabioberger.com>2018-05-10 02:36:28 +0800
commit209266dbed9d7d038c90c2da8d9b99acab77c80c (patch)
treecfefd5ab15bc237716b15687629e0f41362a8e86 /packages/contract-wrappers/test/utils
parent69a6166b6a1d39afc24b8dd950ec5d8539a03420 (diff)
downloaddexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.gz
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.bz2
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.lz
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.xz
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.zst
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.zip
Split 0x.js into contract-wrappers, order-watcher but keep 0x.js as a unifying library with the same interface
Diffstat (limited to 'packages/contract-wrappers/test/utils')
-rw-r--r--packages/contract-wrappers/test/utils/chai_setup.ts13
-rw-r--r--packages/contract-wrappers/test/utils/constants.ts9
-rw-r--r--packages/contract-wrappers/test/utils/deployer.ts18
-rw-r--r--packages/contract-wrappers/test/utils/token_utils.ts33
-rw-r--r--packages/contract-wrappers/test/utils/web3_wrapper.ts9
5 files changed, 82 insertions, 0 deletions
diff --git a/packages/contract-wrappers/test/utils/chai_setup.ts b/packages/contract-wrappers/test/utils/chai_setup.ts
new file mode 100644
index 000000000..078edd309
--- /dev/null
+++ b/packages/contract-wrappers/test/utils/chai_setup.ts
@@ -0,0 +1,13 @@
+import * as chai from 'chai';
+import chaiAsPromised = require('chai-as-promised');
+import ChaiBigNumber = require('chai-bignumber');
+import * as dirtyChai from 'dirty-chai';
+
+export const chaiSetup = {
+ configure() {
+ chai.config.includeStack = true;
+ chai.use(ChaiBigNumber());
+ chai.use(dirtyChai);
+ chai.use(chaiAsPromised);
+ },
+};
diff --git a/packages/contract-wrappers/test/utils/constants.ts b/packages/contract-wrappers/test/utils/constants.ts
new file mode 100644
index 000000000..cf030259c
--- /dev/null
+++ b/packages/contract-wrappers/test/utils/constants.ts
@@ -0,0 +1,9 @@
+export const constants = {
+ NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
+ ROPSTEN_NETWORK_ID: 3,
+ KOVAN_NETWORK_ID: 42,
+ TESTRPC_NETWORK_ID: 50,
+ KOVAN_RPC_URL: 'https://kovan.infura.io/',
+ ROPSTEN_RPC_URL: 'https://ropsten.infura.io/',
+ ZRX_DECIMALS: 18,
+};
diff --git a/packages/contract-wrappers/test/utils/deployer.ts b/packages/contract-wrappers/test/utils/deployer.ts
new file mode 100644
index 000000000..b092322e2
--- /dev/null
+++ b/packages/contract-wrappers/test/utils/deployer.ts
@@ -0,0 +1,18 @@
+import { Deployer } from '@0xproject/deployer';
+import { devConstants } from '@0xproject/dev-utils';
+import * as path from 'path';
+
+import { constants } from './constants';
+
+import { provider } from './web3_wrapper';
+
+const artifactsDir = path.resolve('test', 'artifacts');
+const deployerOpts = {
+ artifactsDir,
+ provider,
+ networkId: constants.TESTRPC_NETWORK_ID,
+ defaults: {
+ gas: devConstants.GAS_ESTIMATE,
+ },
+};
+export const deployer = new Deployer(deployerOpts);
diff --git a/packages/contract-wrappers/test/utils/token_utils.ts b/packages/contract-wrappers/test/utils/token_utils.ts
new file mode 100644
index 000000000..fe85de085
--- /dev/null
+++ b/packages/contract-wrappers/test/utils/token_utils.ts
@@ -0,0 +1,33 @@
+import * as _ from 'lodash';
+
+import { InternalContractWrappersError, Token } from '../../src/types';
+
+const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
+const WETH_TOKEN_SYMBOL = 'WETH';
+
+export class TokenUtils {
+ private _tokens: Token[];
+ constructor(tokens: Token[]) {
+ this._tokens = tokens;
+ }
+ public getProtocolTokenOrThrow(): Token {
+ const zrxToken = _.find(this._tokens, { symbol: PROTOCOL_TOKEN_SYMBOL });
+ if (_.isUndefined(zrxToken)) {
+ throw new Error(InternalContractWrappersError.ZrxNotInTokenRegistry);
+ }
+ return zrxToken;
+ }
+ public getWethTokenOrThrow(): Token {
+ const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL });
+ if (_.isUndefined(wethToken)) {
+ throw new Error(InternalContractWrappersError.WethNotInTokenRegistry);
+ }
+ return wethToken;
+ }
+ public getDummyTokens(): Token[] {
+ const dummyTokens = _.filter(this._tokens, token => {
+ return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
+ });
+ return dummyTokens;
+ }
+}
diff --git a/packages/contract-wrappers/test/utils/web3_wrapper.ts b/packages/contract-wrappers/test/utils/web3_wrapper.ts
new file mode 100644
index 000000000..b0ccfa546
--- /dev/null
+++ b/packages/contract-wrappers/test/utils/web3_wrapper.ts
@@ -0,0 +1,9 @@
+import { devConstants, web3Factory } from '@0xproject/dev-utils';
+import { Provider } from '@0xproject/types';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+
+const web3 = web3Factory.create({ shouldUseInProcessGanache: true });
+const provider: Provider = web3.currentProvider;
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+
+export { provider, web3Wrapper };