2021-03-16 22:00:08 +01:00
|
|
|
import migration48 from './048';
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2020-10-12 21:05:40 +02:00
|
|
|
const localhostNetwork = {
|
|
|
|
rpcUrl: 'http://localhost:8545',
|
|
|
|
chainId: '0x539',
|
|
|
|
ticker: 'ETH',
|
|
|
|
nickname: 'Localhost 8545',
|
|
|
|
rpcPrefs: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 21:05:40 +02:00
|
|
|
const expectedPreferencesState = {
|
|
|
|
PreferencesController: {
|
2020-11-03 00:41:28 +01:00
|
|
|
frequentRpcListDetail: [
|
|
|
|
{
|
|
|
|
...localhostNetwork,
|
|
|
|
},
|
|
|
|
],
|
2020-10-12 21:05:40 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 21:05:40 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
describe('migration #48', () => {
|
|
|
|
it('should update the version metadata', async () => {
|
2020-10-06 19:57:02 +02:00
|
|
|
const oldStorage = {
|
2020-11-03 00:41:28 +01:00
|
|
|
meta: {
|
|
|
|
version: 47,
|
2020-10-06 19:57:02 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
data: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.meta).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
version: 48,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should delete NetworkController.settings', async () => {
|
2020-10-06 19:57:02 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
settings: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
provider: {
|
|
|
|
type: 'notRpc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 21:05:40 +02:00
|
|
|
...expectedPreferencesState,
|
2020-10-06 19:57:02 +02:00
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'notRpc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (1)', async () => {
|
2020-10-06 19:57:02 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'rpc',
|
2020-10-12 23:09:08 +02:00
|
|
|
chainId: 'foo',
|
2020-10-06 19:57:02 +02:00
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 21:05:40 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
NetworkController: {
|
2020-10-12 23:09:08 +02:00
|
|
|
provider: {
|
|
|
|
type: 'rinkeby',
|
|
|
|
rpcUrl: '',
|
|
|
|
chainId: '0x4',
|
|
|
|
nickname: '',
|
|
|
|
rpcPrefs: {},
|
|
|
|
ticker: 'ETH',
|
|
|
|
},
|
2020-10-12 21:05:40 +02:00
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-12 21:05:40 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (2)', async () => {
|
2020-10-12 23:09:08 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'rpc',
|
|
|
|
chainId: '0x01',
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 23:09:08 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'rinkeby',
|
|
|
|
rpcUrl: '',
|
|
|
|
chainId: '0x4',
|
|
|
|
nickname: '',
|
|
|
|
rpcPrefs: {},
|
|
|
|
ticker: 'ETH',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should not migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is valid', async () => {
|
2020-10-12 23:09:08 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'rpc',
|
|
|
|
chainId: '0x1',
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 23:09:08 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'rpc',
|
|
|
|
chainId: '0x1',
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should migrate NetworkController.provider to Rinkeby if the type is "localhost"', async () => {
|
2020-10-12 21:05:40 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'localhost',
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 21:05:40 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 21:05:40 +02:00
|
|
|
...expectedPreferencesState,
|
2020-10-06 19:57:02 +02:00
|
|
|
NetworkController: {
|
2020-10-12 23:09:08 +02:00
|
|
|
provider: {
|
|
|
|
type: 'rinkeby',
|
|
|
|
rpcUrl: '',
|
|
|
|
chainId: '0x4',
|
|
|
|
nickname: '',
|
|
|
|
rpcPrefs: {},
|
|
|
|
ticker: 'ETH',
|
|
|
|
},
|
2020-10-06 19:57:02 +02:00
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should re-key NetworkController.provider.rpcTarget to rpcUrl if the type is not "rpc" or "localhost"', async () => {
|
2020-10-06 19:57:02 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'someType',
|
|
|
|
rpcTarget: 'foo.xyz',
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 21:05:40 +02:00
|
|
|
...expectedPreferencesState,
|
2020-10-06 19:57:02 +02:00
|
|
|
NetworkController: {
|
|
|
|
foo: 'bar',
|
|
|
|
provider: {
|
|
|
|
type: 'someType',
|
|
|
|
rpcUrl: 'foo.xyz',
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing to NetworkController if affected state does not exist', async () => {
|
2020-10-06 19:57:02 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
NetworkController: {
|
|
|
|
provider: {
|
|
|
|
type: 'notRpc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect({ ...expectedPreferencesState, ...oldStorage.data }).toStrictEqual({
|
|
|
|
...expectedPreferencesState,
|
|
|
|
...newStorage.data,
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should add frequentRpcListDetail item to beginning of list', async () => {
|
2020-10-12 21:05:40 +02:00
|
|
|
const existingList = [
|
|
|
|
{ rpcUrl: 'foo', chainId: '0x1' },
|
|
|
|
{ rpcUrl: 'bar', chainId: '0x2' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-10-12 21:05:40 +02:00
|
|
|
|
2020-10-06 19:57:02 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
2020-10-12 21:05:40 +02:00
|
|
|
data: {
|
|
|
|
PreferencesController: {
|
2020-11-03 00:41:28 +01:00
|
|
|
frequentRpcListDetail: [...existingList],
|
2020-10-12 21:05:40 +02:00
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 21:05:40 +02:00
|
|
|
PreferencesController: {
|
2020-11-03 00:41:28 +01:00
|
|
|
frequentRpcListDetail: [{ ...localhostNetwork }, ...existingList],
|
2020-10-12 21:05:40 +02:00
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should delete CachedBalancesController.cachedBalances', async () => {
|
2020-10-12 23:09:08 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
CachedBalancesController: {
|
|
|
|
cachedBalances: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 23:09:08 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
CachedBalancesController: {
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should convert hex transaction metamaskNetworkId values to decimal', async () => {
|
2020-10-12 23:09:08 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
TransactionController: {
|
|
|
|
transactions: [
|
|
|
|
{ fizz: 'buzz' },
|
|
|
|
null,
|
|
|
|
undefined,
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '1' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '0x1' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: 'kaplar' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '0X2a' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '3' },
|
|
|
|
],
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 23:09:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-12 23:09:08 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
TransactionController: {
|
|
|
|
transactions: [
|
|
|
|
{ fizz: 'buzz' },
|
|
|
|
null,
|
|
|
|
undefined,
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '1' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '1' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: 'kaplar' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '42' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '3' },
|
|
|
|
],
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-13 01:35:55 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should migrate the address book', async () => {
|
2020-10-13 01:35:55 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
AddressBookController: {
|
|
|
|
addressBook: {
|
2021-12-09 20:06:24 +01:00
|
|
|
1: {
|
2020-11-03 00:41:28 +01:00
|
|
|
address1: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '1',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
2021-12-09 20:06:24 +01:00
|
|
|
100: {
|
2020-11-03 00:41:28 +01:00
|
|
|
address1: {
|
2020-10-13 04:24:45 +02:00
|
|
|
chainId: '100',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
2020-10-13 01:35:55 +02:00
|
|
|
'0x2': {
|
2020-11-03 00:41:28 +01:00
|
|
|
address2: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x2',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-13 01:35:55 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-13 01:35:55 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
AddressBookController: {
|
|
|
|
addressBook: {
|
|
|
|
'0x1': {
|
2020-11-03 00:41:28 +01:00
|
|
|
address1: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x1',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
2020-10-13 04:24:45 +02:00
|
|
|
'0x64': {
|
2020-11-03 00:41:28 +01:00
|
|
|
address1: {
|
2020-10-13 04:24:45 +02:00
|
|
|
chainId: '0x64',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
2020-10-13 01:35:55 +02:00
|
|
|
'0x2': {
|
2020-11-03 00:41:28 +01:00
|
|
|
address2: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x2',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-13 01:35:55 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should migrate the address book and merge entries', async () => {
|
2020-10-13 01:35:55 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
AddressBookController: {
|
|
|
|
addressBook: {
|
2021-12-09 20:06:24 +01:00
|
|
|
2: {
|
2020-11-03 00:41:28 +01:00
|
|
|
address1: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '2',
|
|
|
|
key2: 'kaplar',
|
|
|
|
key3: 'value3',
|
|
|
|
key4: null,
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
address2: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '2',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'0x2': {
|
2020-11-03 00:41:28 +01:00
|
|
|
address1: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x2',
|
|
|
|
key1: 'value1',
|
|
|
|
key2: 'value2',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
address3: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x2',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-13 01:35:55 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-13 01:35:55 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
AddressBookController: {
|
|
|
|
addressBook: {
|
|
|
|
'0x2': {
|
2020-11-03 00:41:28 +01:00
|
|
|
address1: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x2',
|
|
|
|
key1: 'value1',
|
|
|
|
key2: 'value2',
|
|
|
|
key3: 'value3',
|
|
|
|
key4: '',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
address2: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x2',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
address3: {
|
2020-10-13 01:35:55 +02:00
|
|
|
chainId: '0x2',
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-13 01:35:55 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should not modify address book if all entries are valid or un-parseable', async () => {
|
2020-10-13 01:35:55 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
AddressBookController: {
|
|
|
|
addressBook: {
|
|
|
|
'0x1': { foo: { bar: 'baz' } },
|
2021-12-09 20:06:24 +01:00
|
|
|
kaplar: { foo: { bar: 'baz' } },
|
2020-10-13 01:35:55 +02:00
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-13 01:35:55 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-13 01:35:55 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
AddressBookController: {
|
|
|
|
addressBook: {
|
|
|
|
'0x1': { foo: { bar: 'baz' } },
|
2021-12-09 20:06:24 +01:00
|
|
|
kaplar: { foo: { bar: 'baz' } },
|
2020-10-13 01:35:55 +02:00
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
baz: 'buzz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-13 15:18:24 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should delete localhost key in IncomingTransactionsController', async () => {
|
2020-10-13 15:18:24 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
incomingTxLastFetchedBlocksByNetwork: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
localhost: {},
|
|
|
|
},
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-13 15:18:24 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-13 15:18:24 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
incomingTxLastFetchedBlocksByNetwork: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
},
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-13 15:18:24 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should not modify IncomingTransactionsController state if affected key is missing', async () => {
|
2020-10-13 15:18:24 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
incomingTxLastFetchedBlocksByNetwork: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
rpc: {},
|
|
|
|
},
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-13 15:18:24 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-13 15:18:24 +02:00
|
|
|
...expectedPreferencesState,
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
incomingTxLastFetchedBlocksByNetwork: {
|
|
|
|
fizz: 'buzz',
|
|
|
|
rpc: {},
|
|
|
|
},
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-10-13 16:07:00 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should merge localhost token list into rpc token list', async () => {
|
2020-10-13 16:07:00 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
PreferencesController: {
|
|
|
|
accountTokens: {
|
|
|
|
address1: {
|
|
|
|
localhost: [
|
|
|
|
{ address: '1', data1: 'stuff1' },
|
|
|
|
{ address: '2', a: 'X', b: 'B' },
|
|
|
|
],
|
|
|
|
rpc: [
|
|
|
|
{ address: '2', a: 'A', c: 'C' },
|
|
|
|
{ address: '3', data3: 'stuff3' },
|
|
|
|
],
|
|
|
|
foo: [],
|
|
|
|
},
|
|
|
|
address2: {
|
|
|
|
localhost: [],
|
|
|
|
rpc: [],
|
|
|
|
foo: [],
|
|
|
|
},
|
|
|
|
address3: {},
|
|
|
|
},
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-13 16:07:00 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration48.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-10-13 16:07:00 +02:00
|
|
|
PreferencesController: {
|
|
|
|
accountTokens: {
|
|
|
|
address1: {
|
|
|
|
rpc: [
|
|
|
|
{ address: '1', data1: 'stuff1' },
|
|
|
|
{ address: '2', a: 'A', b: 'B', c: 'C' },
|
|
|
|
{ address: '3', data3: 'stuff3' },
|
|
|
|
],
|
|
|
|
foo: [],
|
|
|
|
},
|
|
|
|
address2: {
|
|
|
|
rpc: [],
|
|
|
|
foo: [],
|
|
|
|
},
|
|
|
|
address3: {},
|
|
|
|
},
|
|
|
|
bar: 'baz',
|
|
|
|
// from other migration
|
2020-11-03 00:41:28 +01:00
|
|
|
frequentRpcListDetail: [
|
|
|
|
{
|
|
|
|
...localhostNetwork,
|
|
|
|
},
|
|
|
|
],
|
2020-10-13 16:07:00 +02:00
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|