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.
127 lines
3.5 KiB
127 lines
3.5 KiB
4 years ago
|
import { strict as assert } from 'assert';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import { getNetworkDisplayName } from './util';
|
||
|
import NetworkController from './network';
|
||
8 years ago
|
|
||
5 years ago
|
describe('NetworkController', function () {
|
||
|
describe('controller', function () {
|
||
4 years ago
|
let networkController;
|
||
|
const noop = () => undefined;
|
||
5 years ago
|
const networkControllerProviderConfig = {
|
||
|
getAccounts: noop,
|
||
4 years ago
|
};
|
||
8 years ago
|
|
||
5 years ago
|
beforeEach(function () {
|
||
4 years ago
|
networkController = new NetworkController();
|
||
|
networkController.setInfuraProjectId('foo');
|
||
|
});
|
||
7 years ago
|
|
||
8 years ago
|
describe('#provider', function () {
|
||
7 years ago
|
it('provider should be updatable without reassignment', function () {
|
||
4 years ago
|
networkController.initializeProvider(networkControllerProviderConfig);
|
||
4 years ago
|
const providerProxy = networkController.getProviderAndBlockTracker()
|
||
4 years ago
|
.provider;
|
||
|
assert.equal(providerProxy.test, undefined);
|
||
|
providerProxy.setTarget({ test: true });
|
||
|
assert.equal(providerProxy.test, true);
|
||
|
});
|
||
|
});
|
||
4 years ago
|
|
||
8 years ago
|
describe('#getNetworkState', function () {
|
||
4 years ago
|
it('should return "loading" when new', function () {
|
||
4 years ago
|
const networkState = networkController.getNetworkState();
|
||
|
assert.equal(networkState, 'loading', 'network is loading');
|
||
|
});
|
||
|
});
|
||
8 years ago
|
|
||
|
describe('#setNetworkState', function () {
|
||
|
it('should update the network', function () {
|
||
4 years ago
|
networkController.setNetworkState('1');
|
||
|
const networkState = networkController.getNetworkState();
|
||
|
assert.equal(networkState, '1', 'network is 1');
|
||
|
});
|
||
|
});
|
||
8 years ago
|
|
||
|
describe('#setProviderType', function () {
|
||
|
it('should update provider.type', function () {
|
||
4 years ago
|
networkController.initializeProvider(networkControllerProviderConfig);
|
||
|
networkController.setProviderType('mainnet');
|
||
|
const { type } = networkController.getProviderConfig();
|
||
|
assert.equal(type, 'mainnet', 'provider type is updated');
|
||
|
});
|
||
4 years ago
|
|
||
8 years ago
|
it('should set the network to loading', function () {
|
||
4 years ago
|
networkController.initializeProvider(networkControllerProviderConfig);
|
||
4 years ago
|
|
||
4 years ago
|
const spy = sinon.spy(networkController, 'setNetworkState');
|
||
|
networkController.setProviderType('mainnet');
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
spy.callCount,
|
||
|
1,
|
||
4 years ago
|
'should have called setNetworkState 2 times',
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.ok(
|
||
|
spy.calledOnceWithExactly('loading'),
|
||
|
'should have called with "loading" first',
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('utils', function () {
|
||
|
it('getNetworkDisplayName should return the correct network name', function () {
|
||
|
const tests = [
|
||
|
{
|
||
5 years ago
|
input: '3',
|
||
5 years ago
|
expected: 'Ropsten',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: '4',
|
||
5 years ago
|
expected: 'Rinkeby',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: '42',
|
||
|
expected: 'Kovan',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: '0x3',
|
||
|
expected: 'Ropsten',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: '0x4',
|
||
|
expected: 'Rinkeby',
|
||
4 years ago
|
},
|
||
|
{
|
||
4 years ago
|
input: '0x2a',
|
||
5 years ago
|
expected: 'Kovan',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: 'ropsten',
|
||
|
expected: 'Ropsten',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: 'rinkeby',
|
||
|
expected: 'Rinkeby',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: 'kovan',
|
||
|
expected: 'Kovan',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: 'mainnet',
|
||
4 years ago
|
expected: 'Ethereum Mainnet',
|
||
4 years ago
|
},
|
||
|
{
|
||
5 years ago
|
input: 'goerli',
|
||
|
expected: 'Goerli',
|
||
|
},
|
||
4 years ago
|
];
|
||
7 years ago
|
|
||
4 years ago
|
tests.forEach(({ input, expected }) =>
|
||
|
assert.equal(getNetworkDisplayName(input), expected),
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|