mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
5ed415d807
* Fix migration 88 to handle the case where chainId keys can be undefined * Add migration 91 to delete network configurations that have no chainId * Lint fix * Update migration number * Update migration 91 description * Update version numbers in 091.test.js * Fix 088.test.ts typescript problem * Fix 088.test.ts typescript problem * Update app/scripts/migrations/091.ts Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Change app/scripts/migrations/091.test.js to typescript * clone oldstorage for test result comparisons in 091.test.js * Lint fix * Add missing test case --------- Co-authored-by: Mark Stacey <markjstacey@gmail.com>
151 lines
3.2 KiB
TypeScript
151 lines
3.2 KiB
TypeScript
import { cloneDeep } from 'lodash';
|
|
import { migrate, version } from './091';
|
|
|
|
jest.mock('uuid', () => {
|
|
const actual = jest.requireActual('uuid');
|
|
|
|
return {
|
|
...actual,
|
|
v4: jest.fn(),
|
|
};
|
|
});
|
|
|
|
describe('migration #91', () => {
|
|
it('should update the version metadata', async () => {
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 90,
|
|
},
|
|
data: {},
|
|
};
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
expect(newStorage.meta).toStrictEqual({
|
|
version,
|
|
});
|
|
});
|
|
|
|
it('should return state unaltered if there is no network controller state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 90,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
const newStorage = await migrate(cloneDeep(oldStorage));
|
|
expect(newStorage.data).toStrictEqual(oldData);
|
|
});
|
|
|
|
it('should return state unaltered if there is no network controller networkConfigurations state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
NetworkController: {
|
|
providerConfig: {
|
|
foo: 'bar',
|
|
},
|
|
},
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 90,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
const newStorage = await migrate(cloneDeep(oldStorage));
|
|
expect(newStorage.data).toStrictEqual(oldData);
|
|
});
|
|
|
|
it('should return state unaltered if the networkConfigurations all have a chainId', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
NetworkController: {
|
|
networkConfigurations: {
|
|
id1: {
|
|
foo: 'bar',
|
|
chainId: '0x1',
|
|
},
|
|
id2: {
|
|
fizz: 'buzz',
|
|
chainId: '0x2',
|
|
},
|
|
},
|
|
providerConfig: {
|
|
id: 'test',
|
|
},
|
|
},
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 90,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
const newStorage = await migrate(cloneDeep(oldStorage));
|
|
expect(newStorage.data).toStrictEqual(oldData);
|
|
});
|
|
|
|
it('should delete networks that have an undefined or null chainId', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
NetworkController: {
|
|
networkConfigurations: {
|
|
id1: {
|
|
foo: 'bar',
|
|
chainId: '0x1',
|
|
},
|
|
id2: {
|
|
fizz: 'buzz',
|
|
chainId: '0x2',
|
|
},
|
|
id3: {
|
|
buzz: 'baz',
|
|
chainId: undefined,
|
|
},
|
|
id4: {
|
|
foo: 'bar',
|
|
chainId: null,
|
|
},
|
|
id5: {
|
|
fizz: 'buzz',
|
|
},
|
|
},
|
|
providerConfig: {
|
|
rpcUrl: 'http://foo.bar',
|
|
},
|
|
},
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 90,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
const newStorage = await migrate(cloneDeep(oldStorage));
|
|
expect(newStorage.data).toStrictEqual({
|
|
other: 'data',
|
|
NetworkController: {
|
|
networkConfigurations: {
|
|
id1: {
|
|
foo: 'bar',
|
|
chainId: '0x1',
|
|
},
|
|
id2: {
|
|
fizz: 'buzz',
|
|
chainId: '0x2',
|
|
},
|
|
},
|
|
providerConfig: {
|
|
rpcUrl: 'http://foo.bar',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
});
|