Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
add token.addressOverrides to config
Browse files Browse the repository at this point in the history
  • Loading branch information
levity committed Mar 23, 2020
1 parent 352367f commit 21a7049
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/dai/src/eth/EthereumTokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class EthereumTokenService extends PrivateService {
this._addedTokens[symbol] = [token];
}
}

this._addressOverrides = settings.addressOverrides || {};
}

getTokens() {
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions packages/dai/test/eth/EthereumTokenService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
10 changes: 5 additions & 5 deletions packages/dai/test/helpers/serviceBuilders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

0 comments on commit 21a7049

Please sign in to comment.