mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
migration for adding submittedTime to the txMeta (#3727)
* test for migration 022 * write migration 022 adding submittedTime to txMetas whove been submitted
This commit is contained in:
parent
a6af5fad96
commit
5a61a6d57a
39
app/scripts/migrations/022.js
Normal file
39
app/scripts/migrations/022.js
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
const version = 22
|
||||
|
||||
/*
|
||||
|
||||
This migration adds submittedTime to the txMeta if it is not their
|
||||
|
||||
*/
|
||||
|
||||
const clone = require('clone')
|
||||
|
||||
module.exports = {
|
||||
version,
|
||||
|
||||
migrate: function (originalVersionedData) {
|
||||
const versionedData = clone(originalVersionedData)
|
||||
versionedData.meta.version = version
|
||||
try {
|
||||
const state = versionedData.data
|
||||
const newState = transformState(state)
|
||||
versionedData.data = newState
|
||||
} catch (err) {
|
||||
console.warn(`MetaMask Migration #${version}` + err.stack)
|
||||
}
|
||||
return Promise.resolve(versionedData)
|
||||
},
|
||||
}
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
const transactions = newState.TransactionController.transactions
|
||||
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
if (txMeta.status !== 'submitted' || txMeta.submittedTime) return txMeta
|
||||
txMeta.submittedTime = (new Date()).getTime()
|
||||
return txMeta
|
||||
})
|
||||
return newState
|
||||
}
|
32
test/unit/migrations/022-test.js
Normal file
32
test/unit/migrations/022-test.js
Normal file
@ -0,0 +1,32 @@
|
||||
const assert = require('assert')
|
||||
const migration22 = require('../../../app/scripts/migrations/022')
|
||||
const properTime = (new Date()).getTime()
|
||||
const storage = {
|
||||
"meta": {},
|
||||
"data": {
|
||||
"TransactionController": {
|
||||
"transactions": [
|
||||
{ "status": "submitted" },
|
||||
{ "status": "submitted", "submittedTime": properTime },
|
||||
{"status": "confirmed"},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
describe('storage is migrated successfully where transactions that are submitted have submittedTimes', () => {
|
||||
it('should add submittedTime key on the txMeta if appropriate', (done) => {
|
||||
migration22.migrate(storage)
|
||||
.then((migratedData) => {
|
||||
const [txMeta1, txMeta2, txMeta3] = migratedData.data.TransactionController.transactions
|
||||
assert.equal(migratedData.meta.version, 22)
|
||||
// should have written a submitted time
|
||||
assert(txMeta1.submittedTime)
|
||||
// should not have written a submitted time because it already has one
|
||||
assert.equal(txMeta2.submittedTime, properTime)
|
||||
// should not have written a submitted time
|
||||
assert(!txMeta3.submittedTime)
|
||||
done()
|
||||
}).catch(done)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user