1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 12:47:14 +01:00
metamask-extension/test/unit/migrations/025.test.js

69 lines
1.7 KiB
JavaScript
Raw Normal View History

import assert from 'assert';
import migration25 from '../../../app/scripts/migrations/025';
import data from '../../../app/scripts/first-time-state';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
2018-04-06 03:05:03 +02:00
const firstTimeState = {
meta: {},
data,
};
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
},
},
};
2018-04-06 03:05:03 +02: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,
},
status: TRANSACTION_STATUSES.UNAPPROVED,
});
2020-11-03 00:41:28 +01:00
transactions.push({
txParams: { from: '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675' },
status: TRANSACTION_STATUSES.CONFIRMED,
});
2018-04-06 03:05:03 +02:00
}
storage.data.TransactionController.transactions = transactions;
2018-04-06 03:05:03 +02: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)
.then((migratedData) => {
2020-11-03 00:41:28 +01:00
const migratedTransactions =
migratedData.data.TransactionController.transactions;
migratedTransactions.forEach((tx) => {
if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) {
assert(!tx.txParams.random);
}
if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) {
assert(!tx.txParams.chainId);
}
});
done();
2020-11-03 00:41:28 +01:00
})
.catch(done);
});
2018-04-06 03:05:03 +02:00
it('should migrate first time state', function (done) {
2020-11-03 00:41:28 +01:00
migration25
.migrate(firstTimeState)
.then((migratedData) => {
assert.equal(migratedData.meta.version, 25);
done();
2020-11-03 00:41:28 +01:00
})
.catch(done);
});
});