diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-05-24 08:57:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-24 08:57:58 +0800 |
commit | e8288ad4bfaa5b65b23f0a03d0c036457a24893f (patch) | |
tree | b1ed4d382b3008fe3271b0c10a8f6dab41b6ee9f /test/unit/network-contoller-test.js | |
parent | 9c316664de2eb82bdd10ab9cd6fa0a33f5185e20 (diff) | |
parent | 97ea7454b353acb8f87dac087eeae61f945325d7 (diff) | |
download | tangerine-wallet-browser-e8288ad4bfaa5b65b23f0a03d0c036457a24893f.tar tangerine-wallet-browser-e8288ad4bfaa5b65b23f0a03d0c036457a24893f.tar.gz tangerine-wallet-browser-e8288ad4bfaa5b65b23f0a03d0c036457a24893f.tar.bz2 tangerine-wallet-browser-e8288ad4bfaa5b65b23f0a03d0c036457a24893f.tar.lz tangerine-wallet-browser-e8288ad4bfaa5b65b23f0a03d0c036457a24893f.tar.xz tangerine-wallet-browser-e8288ad4bfaa5b65b23f0a03d0c036457a24893f.tar.zst tangerine-wallet-browser-e8288ad4bfaa5b65b23f0a03d0c036457a24893f.zip |
Merge pull request #1455 from MetaMask/networkController
Create a network controller to manage switching networks an updating t…
Diffstat (limited to 'test/unit/network-contoller-test.js')
-rw-r--r-- | test/unit/network-contoller-test.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/unit/network-contoller-test.js b/test/unit/network-contoller-test.js new file mode 100644 index 000000000..183e69cab --- /dev/null +++ b/test/unit/network-contoller-test.js @@ -0,0 +1,74 @@ +const EventEmitter = require('events') +const assert = require('assert') +const NetworkController = require('../../app/scripts/controllers/network') + +describe('# Network Controller', function () { + let networkController + + beforeEach(function () { + networkController = new NetworkController({ + provider: { + type: 'rinkeby', + }, + }) + // stub out provider + networkController._provider = new EventEmitter() + networkController.providerInit = { + getAccounts: () => {}, + } + + networkController.ethQuery = new Proxy({}, { + get: (obj, name) => { + return () => {} + }, + }) + }) + describe('network', function () { + describe('#provider', function() { + it('provider should be updatable without reassignment', function () { + networkController.initializeProvider(networkController.providerInit) + const provider = networkController.provider + networkController._provider = {test: true} + assert.ok(provider.test) + }) + }) + describe('#getNetworkState', function () { + it('should return loading when new', function () { + let networkState = networkController.getNetworkState() + assert.equal(networkState, 'loading', 'network is loading') + }) + }) + + describe('#setNetworkState', function () { + it('should update the network', function () { + networkController.setNetworkState(1) + let networkState = networkController.getNetworkState() + assert.equal(networkState, 1, 'network is 1') + }) + }) + + describe('#getRpcAddressForType', function () { + it('should return the right rpc address', function () { + let rpcTarget = networkController.getRpcAddressForType('mainnet') + assert.equal(rpcTarget, 'https://mainnet.infura.io/metamask', 'returns the right rpcAddress') + }) + }) + describe('#setProviderType', function () { + it('should update provider.type', function () { + networkController.setProviderType('mainnet') + const type = networkController.getProviderConfig().type + assert.equal(type, 'mainnet', 'provider type is updated') + }) + it('should set the network to loading', function () { + networkController.setProviderType('mainnet') + const loading = networkController.isNetworkLoading() + assert.ok(loading, 'network is loading') + }) + it('should set the right rpcTarget', function () { + networkController.setProviderType('mainnet') + const rpcTarget = networkController.getProviderConfig().rpcTarget + assert.equal(rpcTarget, 'https://mainnet.infura.io/metamask', 'returns the right rpcAddress') + }) + }) + }) +}) |