2021-03-16 22:00:08 +01:00
|
|
|
import migration47 from './047';
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
describe('migration #47', () => {
|
|
|
|
it('should update the version metadata', async () => {
|
2020-07-08 21:48:39 +02:00
|
|
|
const oldStorage = {
|
2020-11-03 00:41:28 +01:00
|
|
|
meta: {
|
|
|
|
version: 46,
|
2020-07-08 21:48:39 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
data: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration47.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.meta).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
version: 47,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should stringify transactions metamaskNetworkId values', async () => {
|
2020-07-08 21:48:39 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
2020-07-16 15:16:41 +02:00
|
|
|
TransactionController: {
|
2020-07-08 21:48:39 +02:00
|
|
|
transactions: [
|
|
|
|
{ foo: 'bar', metamaskNetworkId: 2 },
|
|
|
|
{ foo: 'bar' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: 0 },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: 42 },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration47.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2020-07-16 15:16:41 +02:00
|
|
|
TransactionController: {
|
2020-07-08 21:48:39 +02:00
|
|
|
transactions: [
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '2' },
|
|
|
|
{ foo: 'bar' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '0' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '42' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing if transactions metamaskNetworkId values are already strings', async () => {
|
2020-07-08 21:48:39 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
2020-07-16 15:16:41 +02:00
|
|
|
TransactionController: {
|
2020-07-08 21:48:39 +02:00
|
|
|
transactions: [
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '2' },
|
|
|
|
{ foo: 'bar' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '0' },
|
|
|
|
{ foo: 'bar', metamaskNetworkId: '42' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration47.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(oldStorage.data).toStrictEqual(newStorage.data);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing if transactions state does not exist', async () => {
|
2020-07-08 21:48:39 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
2020-07-16 15:16:41 +02:00
|
|
|
TransactionController: {
|
2020-07-08 21:48:39 +02:00
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration47.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(oldStorage.data).toStrictEqual(newStorage.data);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing if transactions state is empty', async () => {
|
2020-07-08 21:48:39 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
2020-07-16 15:16:41 +02:00
|
|
|
TransactionController: {
|
2020-07-08 21:48:39 +02:00
|
|
|
transactions: [],
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration47.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(oldStorage.data).toStrictEqual(newStorage.data);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing if state is empty', async () => {
|
2020-07-08 21:48:39 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-07-08 21:48:39 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newStorage = await migration47.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(oldStorage.data).toStrictEqual(newStorage.data);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|