2021-01-11 15:39:15 +01:00
|
|
|
import {
|
|
|
|
INFURA_PROVIDER_TYPES,
|
2022-09-14 16:55:31 +02:00
|
|
|
BUILT_IN_NETWORKS,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../shared/constants/network';
|
2021-03-16 22:00:08 +01:00
|
|
|
import migration51 from './051';
|
2021-01-11 15:39:15 +01:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
describe('migration #51', () => {
|
|
|
|
it('should update the version metadata', async () => {
|
2021-01-11 15:39:15 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 50,
|
|
|
|
},
|
|
|
|
data: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-01-11 15:39:15 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration51.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.meta).toStrictEqual({
|
2021-01-11 15:39:15 +01:00
|
|
|
version: 51,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-01-11 15:39:15 +01:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
describe('setting chainId', () => {
|
2021-01-11 15:39:15 +01:00
|
|
|
INFURA_PROVIDER_TYPES.forEach(function (type) {
|
2021-09-21 18:28:13 +02:00
|
|
|
it(`should correctly set the chainId for the Infura network "${type}", if no chainId is set`, async () => {
|
2021-01-11 15:39:15 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
settings: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
provider: {
|
|
|
|
type,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const newStorage = await migration51.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2021-01-11 15:39:15 +01:00
|
|
|
NetworkController: {
|
|
|
|
settings: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
provider: {
|
|
|
|
type,
|
2022-09-14 16:55:31 +02:00
|
|
|
chainId: BUILT_IN_NETWORKS[type].chainId,
|
2021-01-11 15:39:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-01-11 15:39:15 +01:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it(`should correctly set the chainId for the Infura network "${type}", if an incorrect chainId is set`, async () => {
|
2021-01-11 15:39:15 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
settings: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
provider: {
|
|
|
|
type,
|
|
|
|
chainId: 'foo',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const newStorage = await migration51.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2021-01-11 15:39:15 +01:00
|
|
|
NetworkController: {
|
|
|
|
settings: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
provider: {
|
|
|
|
type,
|
2022-09-14 16:55:31 +02:00
|
|
|
chainId: BUILT_IN_NETWORKS[type].chainId,
|
2021-01-11 15:39:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-11 15:39:15 +01:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should not set the chainId for a non-Infura network that does not have chainId set', async () => {
|
2021-01-11 15:39:15 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
settings: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
provider: {
|
|
|
|
type: 'foo',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const newStorage = await migration51.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual(oldStorage.data);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-01-11 15:39:15 +01:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should not set the chainId for a non-Infura network that does have chainId set', async () => {
|
2021-01-11 15:39:15 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
settings: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
provider: {
|
|
|
|
type: 'foo',
|
|
|
|
chainId: '0x999',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const newStorage = await migration51.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual(oldStorage.data);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|