diff options
-rw-r--r-- | src/contract_wrappers/token_registry_wrapper.ts | 2 | ||||
-rw-r--r-- | test/token_registry_wrapper_test.ts | 60 |
2 files changed, 58 insertions, 4 deletions
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 207259fcd..7a88d329d 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -60,7 +60,7 @@ export class TokenRegistryWrapper extends ContractWrapper { return addressIfExists; } } - public async getTokenAddressByNameIfExistsAsync(symbol: string): Promise<string|undefined> { + public async getTokenAddressByNameIfExistsAsync(name: string): Promise<string|undefined> { assert.isString('name', name); const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const addressIfExists = await tokenRegistryContract.getTokenAddressByName.call(name); diff --git a/test/token_registry_wrapper_test.ts b/test/token_registry_wrapper_test.ts index 2b0873245..18f2f2541 100644 --- a/test/token_registry_wrapper_test.ts +++ b/test/token_registry_wrapper_test.ts @@ -3,7 +3,7 @@ import 'mocha'; import * as chai from 'chai'; import {chaiSetup} from './utils/chai_setup'; import {web3Factory} from './utils/web3_factory'; -import {ZeroEx} from '../src'; +import {ZeroEx, Token} from '../src'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {SchemaValidator} from '../src/utils/schema_validator'; import {tokenSchema} from '../src/schemas/token_schema'; @@ -17,9 +17,25 @@ const TOKEN_REGISTRY_SIZE_AFTER_MIGRATION = 7; describe('TokenRegistryWrapper', () => { let zeroEx: ZeroEx; + let tokens: Token[]; + const tokenAddressBySymbol: {[symbol: string]: string} = {}; + const tokenAddressByName: {[symbol: string]: string} = {}; + const tokenBySymbol: {[symbol: string]: Token} = {}; + const tokenByName: {[symbol: string]: Token} = {}; + const registeredSymbol = 'ZRX'; + const registeredName = '0x Protocol Token'; + const unregisteredSymbol = 'FUCK'; + const unregisteredName = 'FUCKtoken'; before(async () => { const web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider); + tokens = await zeroEx.tokenRegistry.getTokensAsync(); + _.map(tokens, token => { + tokenAddressBySymbol[token.symbol] = token.address; + tokenAddressByName[token.name] = token.address; + tokenBySymbol[token.symbol] = token; + tokenByName[token.name] = token; + }); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -29,7 +45,6 @@ describe('TokenRegistryWrapper', () => { }); describe('#getTokensAsync', () => { it('should return all the tokens added to the tokenRegistry during the migration', async () => { - const tokens = await zeroEx.tokenRegistry.getTokensAsync(); expect(tokens).to.have.lengthOf(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION); const schemaValidator = new SchemaValidator(); @@ -52,9 +67,48 @@ describe('TokenRegistryWrapper', () => { }); }); }); + describe('#getTokenAddressBySymbol', () => { + it('should return correct address for a token in the registry', async () => { + const tokenAddress = await zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync(registeredSymbol); + expect(tokenAddress).to.be.equal(tokenAddressBySymbol[registeredSymbol]); + }); + it('should return undefined for a token out of registry', async () => { + const tokenAddress = await zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync(unregisteredSymbol); + expect(tokenAddress).to.be.undefined(); + }); + }); + describe('#getTokenAddressByName', () => { + it('should return correct address for a token in the registry', async () => { + const tokenAddress = await zeroEx.tokenRegistry.getTokenAddressByNameIfExistsAsync(registeredName); + expect(tokenAddress).to.be.equal(tokenAddressByName[registeredName]); + }); + it('should return undefined for a token out of registry', async () => { + const tokenAddress = await zeroEx.tokenRegistry.getTokenAddressByNameIfExistsAsync(unregisteredName); + expect(tokenAddress).to.be.undefined(); + }); + }); + describe('#getTokenBySymbol', () => { + it('should return correct token for a token in the registry', async () => { + const token = await zeroEx.tokenRegistry.getTokenBySymbolIfExistsAsync(registeredSymbol); + expect(token).to.be.deep.equal(tokenBySymbol[registeredSymbol]); + }); + it('should return undefined for a token out of registry', async () => { + const token = await zeroEx.tokenRegistry.getTokenBySymbolIfExistsAsync(unregisteredSymbol); + expect(token).to.be.undefined(); + }); + }); + describe('#getTokenByName', () => { + it('should return correct token for a token in the registry', async () => { + const token = await zeroEx.tokenRegistry.getTokenByNameIfExistsAsync(registeredName); + expect(token).to.be.deep.equal(tokenByName[registeredName]); + }); + it('should return undefined for a token out of registry', async () => { + const token = await zeroEx.tokenRegistry.getTokenByNameIfExistsAsync(unregisteredName); + expect(token).to.be.undefined(); + }); + }); describe('#getTokenIfExistsAsync', () => { it('should return the token added to the tokenRegistry during the migration', async () => { - const tokens = await zeroEx.tokenRegistry.getTokensAsync(); const aToken = tokens[0]; const token = await zeroEx.tokenRegistry.getTokenIfExistsAsync(aToken.address); |