2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionType } from '../../../shared/constants/transaction';
|
2021-03-16 22:00:08 +01:00
|
|
|
import migration53 from './053';
|
2021-03-10 21:16:44 +01:00
|
|
|
|
2023-01-18 15:47:29 +01:00
|
|
|
const SENT_ETHER = 'sentEther'; // a legacy transaction type replaced now by TransactionType.simpleSend
|
2021-09-15 23:54:51 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
describe('migration #53', () => {
|
|
|
|
it('should update the version metadata', async () => {
|
2021-03-10 21:16:44 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 52,
|
|
|
|
},
|
|
|
|
data: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migration53.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.meta).toStrictEqual({
|
2021-03-10 21:16:44 +01:00
|
|
|
version: 53,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should update type of standard transactions', async () => {
|
2021-03-10 21:16:44 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
TransactionController: {
|
|
|
|
transactions: [
|
|
|
|
{
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.cancel,
|
2021-09-15 23:54:51 +02:00
|
|
|
transactionCategory: SENT_ETHER,
|
2021-03-10 21:16:44 +01:00
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'standard',
|
2021-09-15 23:54:51 +02:00
|
|
|
transactionCategory: SENT_ETHER,
|
2021-03-10 21:16:44 +01:00
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'standard',
|
2023-01-18 15:47:29 +01:00
|
|
|
transactionCategory: TransactionType.contractInteraction,
|
2021-03-10 21:16:44 +01:00
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
{
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.retry,
|
2021-09-15 23:54:51 +02:00
|
|
|
transactionCategory: SENT_ETHER,
|
2021-03-10 21:16:44 +01:00
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
incomingTransactions: {
|
|
|
|
test: {
|
|
|
|
transactionCategory: 'incoming',
|
|
|
|
txParams: {
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migration53.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(newStorage.data).toStrictEqual({
|
2021-03-10 21:16:44 +01:00
|
|
|
TransactionController: {
|
|
|
|
transactions: [
|
2023-01-18 15:47:29 +01:00
|
|
|
{ type: TransactionType.cancel, txParams: { foo: 'bar' } },
|
2021-09-15 23:54:51 +02:00
|
|
|
{
|
|
|
|
type: SENT_ETHER,
|
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
2021-03-10 21:16:44 +01:00
|
|
|
{
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.contractInteraction,
|
2021-03-10 21:16:44 +01:00
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
{ type: TransactionType.retry, txParams: { foo: 'bar' } },
|
2021-03-10 21:16:44 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
incomingTransactions: {
|
|
|
|
test: {
|
|
|
|
type: 'incoming',
|
|
|
|
txParams: {
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing if transactions state does not exist', async () => {
|
2021-03-10 21:16:44 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
TransactionController: {
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
foo: 'baz',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migration53.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(oldStorage.data).toStrictEqual(newStorage.data);
|
2021-03-10 21:16:44 +01:00
|
|
|
});
|
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing if transactions state is empty', async () => {
|
2021-03-10 21:16:44 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
TransactionController: {
|
|
|
|
transactions: [],
|
|
|
|
bar: 'baz',
|
|
|
|
},
|
|
|
|
IncomingTransactionsController: {
|
|
|
|
incomingTransactions: {},
|
|
|
|
baz: 'bar',
|
|
|
|
},
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migration53.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(oldStorage.data).toStrictEqual(newStorage.data);
|
2021-03-10 21:16:44 +01:00
|
|
|
});
|
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should do nothing if state is empty', async () => {
|
2021-03-10 21:16:44 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {},
|
|
|
|
data: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migration53.migrate(oldStorage);
|
2021-09-21 18:28:13 +02:00
|
|
|
expect(oldStorage.data).toStrictEqual(newStorage.data);
|
2021-03-10 21:16:44 +01:00
|
|
|
});
|
|
|
|
});
|