1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/test/unit/network-contoller-test.js

78 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-05-23 08:12:28 +02:00
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
2017-05-24 17:57:31 +02:00
networkController._provider = new Proxy({}, {
2017-05-24 17:52:18 +02:00
get: (obj, name) => {
return () => {}
},
})
2017-05-23 08:12:28 +02:00
networkController.providerInit = {
getAccounts: () => {},
}
networkController.ethQuery = new Proxy({}, {
get: (obj, name) => {
return () => {}
},
})
})
describe('network', function () {
2017-05-28 20:18:07 +02:00
describe('#provider', function () {
2017-05-23 08:12:28 +02:00
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 () {
2017-05-28 20:18:07 +02:00
const networkState = networkController.getNetworkState()
2017-05-23 08:12:28 +02:00
assert.equal(networkState, 'loading', 'network is loading')
})
})
describe('#setNetworkState', function () {
it('should update the network', function () {
networkController.setNetworkState(1)
2017-05-28 20:18:07 +02:00
const networkState = networkController.getNetworkState()
2017-05-23 08:12:28 +02:00
assert.equal(networkState, 1, 'network is 1')
})
})
describe('#getRpcAddressForType', function () {
it('should return the right rpc address', function () {
2017-05-28 20:18:07 +02:00
const rpcTarget = networkController.getRpcAddressForType('mainnet')
2017-05-23 08:12:28 +02:00
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')
})
})
})
})