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.
103 lines
2.9 KiB
103 lines
2.9 KiB
8 years ago
|
const assert = require('assert')
|
||
7 years ago
|
const nock = require('nock')
|
||
7 years ago
|
const NetworkController = require('../../../../app/scripts/controllers/network')
|
||
7 years ago
|
const {
|
||
|
getNetworkDisplayName,
|
||
7 years ago
|
} = require('../../../../app/scripts/controllers/network/util')
|
||
8 years ago
|
|
||
7 years ago
|
const { createTestProviderTools } = require('../../../stub/provider')
|
||
7 years ago
|
const providerResultStub = {}
|
||
|
|
||
8 years ago
|
describe('# Network Controller', function () {
|
||
|
let networkController
|
||
7 years ago
|
const noop = () => {}
|
||
7 years ago
|
const networkControllerProviderConfig = {
|
||
7 years ago
|
getAccounts: noop,
|
||
7 years ago
|
}
|
||
8 years ago
|
|
||
|
beforeEach(function () {
|
||
7 years ago
|
|
||
|
nock('https://rinkeby.infura.io')
|
||
7 years ago
|
.persist()
|
||
7 years ago
|
.post('/metamask')
|
||
|
.reply(200)
|
||
|
|
||
7 years ago
|
networkController = new NetworkController()
|
||
8 years ago
|
|
||
7 years ago
|
networkController.initializeProvider(networkControllerProviderConfig)
|
||
8 years ago
|
})
|
||
7 years ago
|
|
||
|
afterEach(function () {
|
||
|
nock.cleanAll()
|
||
|
})
|
||
|
|
||
8 years ago
|
describe('network', function () {
|
||
8 years ago
|
describe('#provider', function () {
|
||
8 years ago
|
it('provider should be updatable without reassignment', function () {
|
||
7 years ago
|
networkController.initializeProvider(networkControllerProviderConfig)
|
||
7 years ago
|
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('#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')
|
||
|
})
|
||
|
})
|
||
|
})
|
||
7 years ago
|
})
|
||
|
|
||
7 years ago
|
describe('Network utils', () => {
|
||
7 years ago
|
it('getNetworkDisplayName should return the correct network name', () => {
|
||
|
const tests = [
|
||
|
{
|
||
|
input: 3,
|
||
|
expected: 'Ropsten',
|
||
|
}, {
|
||
|
input: 4,
|
||
|
expected: 'Rinkeby',
|
||
|
}, {
|
||
|
input: 42,
|
||
|
expected: 'Kovan',
|
||
|
}, {
|
||
|
input: 'ropsten',
|
||
|
expected: 'Ropsten',
|
||
|
}, {
|
||
|
input: 'rinkeby',
|
||
|
expected: 'Rinkeby',
|
||
|
}, {
|
||
|
input: 'kovan',
|
||
|
expected: 'Kovan',
|
||
|
}, {
|
||
|
input: 'mainnet',
|
||
|
expected: 'Main Ethereum Network',
|
||
|
},
|
||
|
]
|
||
|
|
||
|
tests.forEach(({ input, expected }) => assert.equal(getNetworkDisplayName(input), expected))
|
||
|
})
|
||
|
})
|