2021-03-10 21:16:44 +01:00
|
|
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction';
|
2021-03-16 22:00:08 +01:00
|
|
|
import migration53 from './053';
|
2021-03-10 21:16:44 +01:00
|
|
|
|
2021-09-15 23:54:51 +02:00
|
|
|
const SENT_ETHER = 'sentEther'; // a legacy transaction type replaced now by TRANSACTION_TYPES.SIMPLE_SEND
|
|
|
|
|
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: [
|
|
|
|
{
|
|
|
|
type: TRANSACTION_TYPES.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',
|
|
|
|
transactionCategory: TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: TRANSACTION_TYPES.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: [
|
|
|
|
{ type: TRANSACTION_TYPES.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
|
|
|
{
|
|
|
|
type: TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
|
|
|
txParams: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
{ type: TRANSACTION_TYPES.RETRY, txParams: { foo: 'bar' } },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|