diff options
Diffstat (limited to 'test/unit/app/controllers/detect-tokens-test.js')
-rw-r--r-- | test/unit/app/controllers/detect-tokens-test.js | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/test/unit/app/controllers/detect-tokens-test.js b/test/unit/app/controllers/detect-tokens-test.js index 4ee73599d..d659d51df 100644 --- a/test/unit/app/controllers/detect-tokens-test.js +++ b/test/unit/app/controllers/detect-tokens-test.js @@ -1,16 +1,14 @@ const assert = require('assert') -const sinon = require('sinon') const nock = require('nock') +const sinon = require('sinon') const ObservableStore = require('obs-store') const DetectTokensController = require('../../../../app/scripts/controllers/detect-tokens') const NetworkController = require('../../../../app/scripts/controllers/network/network') const PreferencesController = require('../../../../app/scripts/controllers/preferences') describe('DetectTokensController', () => { - - let clock, network, preferences, controller, keyringMemStore - const sandbox = sinon.createSandbox() + let clock, keyringMemStore, network, preferences, controller const noop = () => {} @@ -20,13 +18,14 @@ describe('DetectTokensController', () => { beforeEach(async () => { + nock('https://api.infura.io') .get(/.*/) .reply(200) keyringMemStore = new ObservableStore({ isUnlocked: false}) network = new NetworkController() - preferences = new PreferencesController() + preferences = new PreferencesController({ network }) controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) network.initializeProvider(networkControllerProviderConfig) @@ -34,8 +33,8 @@ describe('DetectTokensController', () => { }) after(() => { - sandbox.restore() - nock.cleanAll() + sandbox.restore() + nock.cleanAll() }) it('should poll on correct interval', async () => { @@ -50,7 +49,7 @@ describe('DetectTokensController', () => { const network = new NetworkController() network.initializeProvider(networkControllerProviderConfig) network.setProviderType('mainnet') - const preferences = new PreferencesController() + const preferences = new PreferencesController({ network }) const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) controller.isOpen = true controller.isUnlocked = true @@ -68,7 +67,8 @@ describe('DetectTokensController', () => { }) it('should not check tokens while in test network', async () => { - network.setProviderType('rinkeby') + // network.setProviderType('rinkeby') + // const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) controller.isOpen = true controller.isUnlocked = true @@ -81,7 +81,8 @@ describe('DetectTokensController', () => { }) it('should only check and add tokens while in main network', async () => { - network.setProviderType('mainnet') + // network.setProviderType('mainnet') + const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) controller.isOpen = true controller.isUnlocked = true @@ -97,7 +98,8 @@ describe('DetectTokensController', () => { }) it('should not detect same token while in main network', async () => { - network.setProviderType('mainnet') + // network.setProviderType('mainnet') + preferences.addToken('0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', 'J8T', 8) const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) controller.isOpen = true controller.isUnlocked = true @@ -114,7 +116,8 @@ describe('DetectTokensController', () => { }) it('should trigger detect new tokens when change address', async () => { - network.setProviderType('mainnet') + // network.setProviderType('mainnet') + // const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) controller.isOpen = true controller.isUnlocked = true var stub = sandbox.stub(controller, 'detectNewTokens') @@ -123,7 +126,8 @@ describe('DetectTokensController', () => { }) it('should trigger detect new tokens when submit password', async () => { - network.setProviderType('mainnet') + // network.setProviderType('mainnet') + // const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) controller.isOpen = true controller.selectedAddress = '0x0' var stub = sandbox.stub(controller, 'detectNewTokens') @@ -132,7 +136,8 @@ describe('DetectTokensController', () => { }) it('should not trigger detect new tokens when not open or not unlocked', async () => { - network.setProviderType('mainnet') + // network.setProviderType('mainnet') + // const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore }) controller.isOpen = true controller.isUnlocked = false var stub = sandbox.stub(controller, 'detectTokenBalance') @@ -143,4 +148,4 @@ describe('DetectTokensController', () => { clock.tick(180000) sandbox.assert.notCalled(stub) }) -}) +})
\ No newline at end of file |