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 }); }