From ecb735634553050d094c73f3474fae1396ee77e0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 27 Jun 2018 11:26:55 +0300 Subject: Refactor tokenUtils to not use tokenRegistry --- .../contract-wrappers/test/utils/token_utils.ts | 72 +++++++++++++--------- 1 file changed, 42 insertions(+), 30 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/test/utils/token_utils.ts b/packages/contract-wrappers/test/utils/token_utils.ts index fe85de085..db14a013f 100644 --- a/packages/contract-wrappers/test/utils/token_utils.ts +++ b/packages/contract-wrappers/test/utils/token_utils.ts @@ -1,33 +1,45 @@ -import * as _ from 'lodash'; +import { generatePseudoRandomSalt } from '@0xproject/order-utils'; +import { BigNumber } from '@0xproject/utils'; -import { InternalContractWrappersError, Token } from '../../src/types'; +import { artifacts } from '../../src/artifacts'; +import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/dummy_erc721_token'; -const PROTOCOL_TOKEN_SYMBOL = 'ZRX'; -const WETH_TOKEN_SYMBOL = 'WETH'; +import { constants } from './constants'; +import { provider, txDefaults, web3Wrapper } from './web3_wrapper'; -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; - } -} +const DUMMY_ERC_20_ADRESSES = [ + '0x07f96aa816c1f244cbc6ef114bb2b023ba54a2eb', + '0x6a4a62e5a7ed13c361b176a5f62c2ee620ac0df8', + '0x6dfff22588be9b3ef8cf0ad6dc9b84796f9fb45f', + '0xcfc18cec799fbd1793b5c43e773c98d4d61cc2db', + '0xf22469f31527adc53284441bae1665a7b9214dba', +]; + +const DUMMY_ERC_721_ADRESSES = ['0x10add991de718a69dec2117cb6aa28098836511b']; + +export const tokenUtils = { + getProtocolTokenAddress(): string { + return artifacts.ZRXToken.networks[constants.TESTRPC_NETWORK_ID].address; + }, + getWethTokenAddress(): string { + return artifacts.EtherToken.networks[constants.TESTRPC_NETWORK_ID].address; + }, + getDummyERC20TokenAddresses(): string[] { + return DUMMY_ERC_20_ADRESSES; + }, + getDummyERC721TokenAddresses(): string[] { + return DUMMY_ERC_721_ADRESSES; + }, + async mintDummyERC721Async(address: string, tokenOwner: string): Promise { + const erc721 = new DummyERC721TokenContract( + artifacts.DummyERC721Token.compilerOutput.abi, + address, + provider, + txDefaults, + ); + const tokenId = generatePseudoRandomSalt(); + const txHash = await erc721.mint.sendTransactionAsync(tokenOwner, tokenId); + web3Wrapper.awaitTransactionSuccessAsync(txHash); + return tokenId; + }, +}; -- cgit v1.2.3