A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/test/unit/network-contoller-test.js

80 lines
2.8 KiB

8 years ago
const assert = require('assert')
7 years ago
const nock = require('nock')
8 years ago
const NetworkController = require('../../app/scripts/controllers/network')
const { createTestProviderTools } = require('../stub/provider')
const providerResultStub = {}
const provider = createTestProviderTools({ scaffold: providerResultStub }).provider
8 years ago
describe('# Network Controller', function () {
let networkController
const noop = () => {}
const networkControllerProviderInit = {
getAccounts: () => {},
}
8 years ago
beforeEach(function () {
7 years ago
nock('https://api.infura.io')
.get('/*/')
.reply(200)
nock('https://rinkeby.infura.io')
.post('/metamask')
.reply(200)
8 years ago
networkController = new NetworkController({
provider,
8 years ago
})
networkController.initializeProvider(networkControllerProviderInit, provider)
8 years ago
})
describe('network', function () {
8 years ago
describe('#provider', function () {
8 years ago
it('provider should be updatable without reassignment', function () {
networkController.initializeProvider(networkControllerProviderInit, provider)
const proxy = networkController._proxy
proxy.setTarget({ test: true, on: () => {} })
assert.ok(proxy.test)
8 years ago
})
})
describe('#getNetworkState', function () {
it('should return loading when new', function () {
8 years ago
const networkState = networkController.getNetworkState()
8 years ago
assert.equal(networkState, 'loading', 'network is loading')
})
})
describe('#setNetworkState', function () {
it('should update the network', function () {
networkController.setNetworkState(1)
8 years ago
const networkState = networkController.getNetworkState()
8 years ago
assert.equal(networkState, 1, 'network is 1')
})
})
describe('#getRpcAddressForType', function () {
it('should return the right rpc address', function () {
8 years ago
const rpcTarget = networkController.getRpcAddressForType('mainnet')
8 years ago
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')
})
})
})
})