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.
636 lines
15 KiB
636 lines
15 KiB
4 years ago
|
import { strict as assert } from 'assert';
|
||
4 years ago
|
import migration48 from './048';
|
||
4 years ago
|
|
||
4 years ago
|
const localhostNetwork = {
|
||
|
rpcUrl: 'http://localhost:8545',
|
||
|
chainId: '0x539',
|
||
|
ticker: 'ETH',
|
||
|
nickname: 'Localhost 8545',
|
||
|
rpcPrefs: {},
|
||
4 years ago
|
};
|
||
4 years ago
|
const expectedPreferencesState = {
|
||
|
PreferencesController: {
|
||
4 years ago
|
frequentRpcListDetail: [
|
||
|
{
|
||
|
...localhostNetwork,
|
||
|
},
|
||
|
],
|
||
4 years ago
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
describe('migration #48', function () {
|
||
|
it('should update the version metadata', async function () {
|
||
|
const oldStorage = {
|
||
4 years ago
|
meta: {
|
||
|
version: 47,
|
||
4 years ago
|
},
|
||
4 years ago
|
data: {},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.meta, {
|
||
4 years ago
|
version: 48,
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should delete NetworkController.settings', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
settings: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
provider: {
|
||
|
type: 'notRpc',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
4 years ago
|
...expectedPreferencesState,
|
||
4 years ago
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'notRpc',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (1)', async function () {
|
||
4 years ago
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'rpc',
|
||
4 years ago
|
chainId: 'foo',
|
||
4 years ago
|
fizz: 'buzz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
4 years ago
|
...expectedPreferencesState,
|
||
|
NetworkController: {
|
||
4 years ago
|
provider: {
|
||
|
type: 'rinkeby',
|
||
|
rpcUrl: '',
|
||
|
chainId: '0x4',
|
||
|
nickname: '',
|
||
|
rpcPrefs: {},
|
||
|
ticker: 'ETH',
|
||
|
},
|
||
4 years ago
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (2)', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'rpc',
|
||
|
chainId: '0x01',
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'rinkeby',
|
||
|
rpcUrl: '',
|
||
|
chainId: '0x4',
|
||
|
nickname: '',
|
||
|
rpcPrefs: {},
|
||
|
ticker: 'ETH',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should not migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is valid', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'rpc',
|
||
|
chainId: '0x1',
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'rpc',
|
||
|
chainId: '0x1',
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should migrate NetworkController.provider to Rinkeby if the type is "localhost"', async function () {
|
||
4 years ago
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'localhost',
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
4 years ago
|
NetworkController: {
|
||
4 years ago
|
provider: {
|
||
|
type: 'rinkeby',
|
||
|
rpcUrl: '',
|
||
|
chainId: '0x4',
|
||
|
nickname: '',
|
||
|
rpcPrefs: {},
|
||
|
ticker: 'ETH',
|
||
|
},
|
||
4 years ago
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('should re-key NetworkController.provider.rpcTarget to rpcUrl if the type is not "rpc" or "localhost"', async function () {
|
||
4 years ago
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'someType',
|
||
|
rpcTarget: 'foo.xyz',
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
4 years ago
|
...expectedPreferencesState,
|
||
4 years ago
|
NetworkController: {
|
||
|
foo: 'bar',
|
||
|
provider: {
|
||
|
type: 'someType',
|
||
|
rpcUrl: 'foo.xyz',
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('should do nothing to NetworkController if affected state does not exist', async function () {
|
||
4 years ago
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
NetworkController: {
|
||
|
provider: {
|
||
|
type: 'notRpc',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(
|
||
4 years ago
|
{ ...expectedPreferencesState, ...oldStorage.data },
|
||
|
{ ...expectedPreferencesState, ...newStorage.data },
|
||
4 years ago
|
);
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('should add frequentRpcListDetail item to beginning of list', async function () {
|
||
|
const existingList = [
|
||
|
{ rpcUrl: 'foo', chainId: '0x1' },
|
||
|
{ rpcUrl: 'bar', chainId: '0x2' },
|
||
4 years ago
|
];
|
||
4 years ago
|
|
||
4 years ago
|
const oldStorage = {
|
||
|
meta: {},
|
||
4 years ago
|
data: {
|
||
|
PreferencesController: {
|
||
4 years ago
|
frequentRpcListDetail: [...existingList],
|
||
4 years ago
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
PreferencesController: {
|
||
4 years ago
|
frequentRpcListDetail: [{ ...localhostNetwork }, ...existingList],
|
||
4 years ago
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should delete CachedBalancesController.cachedBalances', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
CachedBalancesController: {
|
||
|
cachedBalances: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
CachedBalancesController: {
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should convert hex transaction metamaskNetworkId values to decimal', async function () {
|
||
|
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',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...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',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should migrate the address book', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
AddressBookController: {
|
||
|
addressBook: {
|
||
4 years ago
|
1: {
|
||
|
address1: {
|
||
4 years ago
|
chainId: '1',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
4 years ago
|
100: {
|
||
|
address1: {
|
||
4 years ago
|
chainId: '100',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
4 years ago
|
'0x2': {
|
||
4 years ago
|
address2: {
|
||
4 years ago
|
chainId: '0x2',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
AddressBookController: {
|
||
|
addressBook: {
|
||
|
'0x1': {
|
||
4 years ago
|
address1: {
|
||
4 years ago
|
chainId: '0x1',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
4 years ago
|
'0x64': {
|
||
4 years ago
|
address1: {
|
||
4 years ago
|
chainId: '0x64',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
4 years ago
|
'0x2': {
|
||
4 years ago
|
address2: {
|
||
4 years ago
|
chainId: '0x2',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should migrate the address book and merge entries', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
AddressBookController: {
|
||
|
addressBook: {
|
||
4 years ago
|
2: {
|
||
|
address1: {
|
||
4 years ago
|
chainId: '2',
|
||
|
key2: 'kaplar',
|
||
|
key3: 'value3',
|
||
|
key4: null,
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
address2: {
|
||
4 years ago
|
chainId: '2',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
|
'0x2': {
|
||
4 years ago
|
address1: {
|
||
4 years ago
|
chainId: '0x2',
|
||
|
key1: 'value1',
|
||
|
key2: 'value2',
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
address3: {
|
||
4 years ago
|
chainId: '0x2',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
AddressBookController: {
|
||
|
addressBook: {
|
||
|
'0x2': {
|
||
4 years ago
|
address1: {
|
||
4 years ago
|
chainId: '0x2',
|
||
|
key1: 'value1',
|
||
|
key2: 'value2',
|
||
|
key3: 'value3',
|
||
|
key4: '',
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
address2: {
|
||
4 years ago
|
chainId: '0x2',
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
address3: {
|
||
4 years ago
|
chainId: '0x2',
|
||
|
foo: 'bar',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should not modify address book if all entries are valid or un-parseable', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
AddressBookController: {
|
||
|
addressBook: {
|
||
|
'0x1': { foo: { bar: 'baz' } },
|
||
4 years ago
|
kaplar: { foo: { bar: 'baz' } },
|
||
4 years ago
|
},
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
AddressBookController: {
|
||
|
addressBook: {
|
||
|
'0x1': { foo: { bar: 'baz' } },
|
||
4 years ago
|
kaplar: { foo: { bar: 'baz' } },
|
||
4 years ago
|
},
|
||
|
bar: {
|
||
|
baz: 'buzz',
|
||
|
},
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should delete localhost key in IncomingTransactionsController', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
IncomingTransactionsController: {
|
||
|
incomingTxLastFetchedBlocksByNetwork: {
|
||
|
fizz: 'buzz',
|
||
|
localhost: {},
|
||
|
},
|
||
|
bar: 'baz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
IncomingTransactionsController: {
|
||
|
incomingTxLastFetchedBlocksByNetwork: {
|
||
|
fizz: 'buzz',
|
||
|
},
|
||
|
bar: 'baz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should not modify IncomingTransactionsController state if affected key is missing', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {},
|
||
|
data: {
|
||
|
IncomingTransactionsController: {
|
||
|
incomingTxLastFetchedBlocksByNetwork: {
|
||
|
fizz: 'buzz',
|
||
|
rpc: {},
|
||
|
},
|
||
|
bar: 'baz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
...expectedPreferencesState,
|
||
|
IncomingTransactionsController: {
|
||
|
incomingTxLastFetchedBlocksByNetwork: {
|
||
|
fizz: 'buzz',
|
||
|
rpc: {},
|
||
|
},
|
||
|
bar: 'baz',
|
||
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should merge localhost token list into rpc token list', async function () {
|
||
|
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',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration48.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.data, {
|
||
|
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
|
||
4 years ago
|
frequentRpcListDetail: [
|
||
|
{
|
||
|
...localhostNetwork,
|
||
|
},
|
||
|
],
|
||
4 years ago
|
},
|
||
|
foo: 'bar',
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|