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.
125 lines
3.2 KiB
125 lines
3.2 KiB
4 years ago
|
import { strict as assert } from 'assert';
|
||
4 years ago
|
import {
|
||
|
INFURA_PROVIDER_TYPES,
|
||
|
NETWORK_TYPE_TO_ID_MAP,
|
||
4 years ago
|
} from '../../../shared/constants/network';
|
||
4 years ago
|
import migration51 from './051';
|
||
4 years ago
|
|
||
|
describe('migration #51', function () {
|
||
|
it('should update the version metadata', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {
|
||
|
version: 50,
|
||
|
},
|
||
|
data: {},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration51.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.meta, {
|
||
|
version: 51,
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
describe('setting chainId', function () {
|
||
|
INFURA_PROVIDER_TYPES.forEach(function (type) {
|
||
|
it(`should correctly set the chainId for the Infura network "${type}", if no chainId is set`, async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
settings: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
provider: {
|
||
|
type,
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
|
const newStorage = await migration51.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
NetworkController: {
|
||
|
settings: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
provider: {
|
||
|
type,
|
||
|
chainId: NETWORK_TYPE_TO_ID_MAP[type].chainId,
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it(`should correctly set the chainId for the Infura network "${type}", if an incorrect chainId is set`, async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
settings: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
provider: {
|
||
|
type,
|
||
|
chainId: 'foo',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
|
const newStorage = await migration51.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
NetworkController: {
|
||
|
settings: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
provider: {
|
||
|
type,
|
||
|
chainId: NETWORK_TYPE_TO_ID_MAP[type].chainId,
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should not set the chainId for a non-Infura network that does not have chainId set', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
settings: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
provider: {
|
||
|
type: 'foo',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
|
const newStorage = await migration51.migrate(oldStorage);
|
||
|
assert.deepEqual(newStorage.data, oldStorage.data);
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should not set the chainId for a non-Infura network that does have chainId set', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
settings: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
provider: {
|
||
|
type: 'foo',
|
||
|
chainId: '0x999',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
|
const newStorage = await migration51.migrate(oldStorage);
|
||
|
assert.deepEqual(newStorage.data, oldStorage.data);
|
||
|
});
|
||
|
});
|
||
|
});
|