From 21a704987d7d05b6c7476cccea4d4b8b01b6658f Mon Sep 17 00:00:00 2001 From: Lawrence Wang Date: Mon, 23 Mar 2020 11:50:14 -0700 Subject: [PATCH] add token.addressOverrides to config --- packages/dai/src/eth/EthereumTokenService.js | 3 +++ .../dai/test/eth/EthereumTokenService.spec.js | 18 ++++++++++++++++++ packages/dai/test/helpers/serviceBuilders.js | 10 +++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/dai/src/eth/EthereumTokenService.js b/packages/dai/src/eth/EthereumTokenService.js index 138fb2555..cfc98574b 100644 --- a/packages/dai/src/eth/EthereumTokenService.js +++ b/packages/dai/src/eth/EthereumTokenService.js @@ -24,6 +24,8 @@ export default class EthereumTokenService extends PrivateService { this._addedTokens[symbol] = [token]; } } + + this._addressOverrides = settings.addressOverrides || {}; } getTokens() { @@ -90,6 +92,7 @@ export default class EthereumTokenService extends PrivateService { ? tokenInfoList[version - 1] : tokenInfoList[tokenInfoList.length - 1]; + if (typeof tokenInfo.address === 'string') return tokenInfo; return { diff --git a/packages/dai/test/eth/EthereumTokenService.spec.js b/packages/dai/test/eth/EthereumTokenService.spec.js index 0931c536c..4b4b7f1a7 100644 --- a/packages/dai/test/eth/EthereumTokenService.spec.js +++ b/packages/dai/test/eth/EthereumTokenService.spec.js @@ -51,3 +51,21 @@ test('_getTokenInfo returns token address for current network', () => { const tokenInfo = ethereumTokenService._getTokenInfo('FOO'); expect(tokenInfo).toEqual({ address: '0xtest' }); }); + +test('addressOverrides', async () => { + const service = buildTestEthereumTokenService({ + token: { + addressOverrides: { + PETH: { + testnet: '0xmockpeth', + kovan: '0xmockpeth2' + }, + WETH: '0xmockweth' + } + } + }); + await service.manager().authenticate(); + + expect(service.getToken('PETH')._contract.address).toBe('0xmockpeth'); + expect(service.getToken('WETH')._contract.address).toBe('0xmockweth'); +}); \ No newline at end of file diff --git a/packages/dai/test/helpers/serviceBuilders.js b/packages/dai/test/helpers/serviceBuilders.js index 0dfd1387f..1de1ac9ad 100644 --- a/packages/dai/test/helpers/serviceBuilders.js +++ b/packages/dai/test/helpers/serviceBuilders.js @@ -57,20 +57,20 @@ export function buildTestService(name, settings = {}) { } export function buildTestEthereumCdpService(settings = {}) { - return buildTestService('cdp', { ...settings, cdp: true }); + return buildTestService('cdp', { cdp: true, ...settings }); } export function buildTestEthereumTokenService(settings = {}) { - return buildTestService('token', { ...settings, token: true }); + return buildTestService('token', { token: true, ...settings }); } export function buildTestSmartContractService(settings = {}) { return buildTestService('smartContract', { - ...settings, - smartContract: true + smartContract: true, + ...settings }); } export function buildTestEventService(settings = {}) { - return buildTestService('event', { ...settings, event: true }); + return buildTestService('event', { event: true, ...settings }); }