aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/test/utils/token_utils.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
commit9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a (patch)
treef72aae5170b6f1f6d3d70ebf6c03ed171680ff50 /packages/contract-wrappers/test/utils/token_utils.ts
parent9744b1906a111aa0c65c8fafb4db66aef32a5a23 (diff)
parent6aed4fb1ae27dabed027c855f2cbdc0bfb4f3b6b (diff)
downloaddexon-0x-contracts-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.gz
dexon-0x-contracts-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.zst
dexon-0x-contracts-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.zip
Merge branch 'development' into v2-prototype
Diffstat (limited to 'packages/contract-wrappers/test/utils/token_utils.ts')
-rw-r--r--packages/contract-wrappers/test/utils/token_utils.ts33
1 files changed, 33 insertions, 0 deletions
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;
+ }
+}