2021-02-04 19:15:23 +01:00
|
|
|
import { strict as assert } from 'assert';
|
2021-03-16 22:00:08 +01:00
|
|
|
import migration47 from './047';
|
2020-07-08 21:48:39 +02:00
|
|
|
|
|
|
|
describe('migration #47', function () {
|
|
|
|
it('should update the version metadata', async function () {
|
|
|
|
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);
|
2020-07-08 21:48:39 +02:00
|
|
|
assert.deepEqual(newStorage.meta, {
|
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
|
|
|
|
|
|
|
it('should stringify transactions metamaskNetworkId values', async function () {
|
|
|
|
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);
|
2020-07-08 21:48:39 +02:00
|
|
|
assert.deepEqual(newStorage.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
|
|
|
|
|
|
|
it('should do nothing if transactions metamaskNetworkId values are already strings', async function () {
|
|
|
|
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);
|
|
|
|
assert.deepEqual(oldStorage.data, newStorage.data);
|
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
|
|
|
it('should do nothing if transactions state does not exist', async function () {
|
|
|
|
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);
|
|
|
|
assert.deepEqual(oldStorage.data, newStorage.data);
|
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
|
|
|
it('should do nothing if transactions state is empty', async function () {
|
|
|
|
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);
|
|
|
|
assert.deepEqual(oldStorage.data, newStorage.data);
|
|
|
|
});
|
2020-07-08 21:48:39 +02:00
|
|
|
|
|
|
|
it('should do nothing if state is empty', async function () {
|
|
|
|
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);
|
|
|
|
assert.deepEqual(oldStorage.data, newStorage.data);
|
|
|
|
});
|
|
|
|
});
|