2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
2021-03-16 22:00:08 +01:00
|
|
|
import data from '../first-time-state';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
|
2021-03-16 22:00:08 +01:00
|
|
|
import migration25 from './025';
|
2020-01-09 04:34:58 +01:00
|
|
|
|
2018-04-06 03:05:03 +02:00
|
|
|
const firstTimeState = {
|
|
|
|
meta: {},
|
2020-01-09 04:34:58 +01:00
|
|
|
data,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-06 03:05:03 +02:00
|
|
|
|
|
|
|
const storage = {
|
2020-11-03 00:41:28 +01:00
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
TransactionController: {
|
|
|
|
transactions: [],
|
2018-04-06 03:05:03 +02:00
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-06 03:05:03 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const transactions = [];
|
2018-04-06 03:05:03 +02:00
|
|
|
|
|
|
|
while (transactions.length <= 10) {
|
2020-11-03 00:41:28 +01:00
|
|
|
transactions.push({
|
|
|
|
txParams: {
|
|
|
|
from: '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675',
|
|
|
|
random: 'stuff',
|
|
|
|
chainId: 2,
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
transactions.push({
|
|
|
|
txParams: { from: '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675' },
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-04-06 03:05:03 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
storage.data.TransactionController.transactions = transactions;
|
2018-04-06 03:05:03 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('storage is migrated successfully and the txParams.from are lowercase', function () {
|
|
|
|
it('should lowercase the from for unapproved txs', function (done) {
|
2020-11-03 00:41:28 +01:00
|
|
|
migration25
|
|
|
|
.migrate(storage)
|
2019-07-31 22:17:11 +02:00
|
|
|
.then((migratedData) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const migratedTransactions =
|
2021-02-04 19:15:23 +01:00
|
|
|
migratedData.data.TransactionController.transactions;
|
2019-07-31 22:17:11 +02:00
|
|
|
migratedTransactions.forEach((tx) => {
|
2020-11-07 08:38:12 +01:00
|
|
|
if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(!tx.txParams.random);
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2020-11-07 08:38:12 +01:00
|
|
|
if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(!tx.txParams.chainId);
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
done();
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
|
|
|
});
|
2018-04-06 03:05:03 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should migrate first time state', function (done) {
|
2020-11-03 00:41:28 +01:00
|
|
|
migration25
|
|
|
|
.migrate(firstTimeState)
|
2019-07-31 22:17:11 +02:00
|
|
|
.then((migratedData) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.equal(migratedData.meta.version, 25);
|
|
|
|
done();
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
|
|
|
});
|
|
|
|
});
|