mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #3907 from MetaMask/fix-all-migrations
migrations - back fixes
This commit is contained in:
commit
90bcf9f7d2
@ -27,8 +27,11 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
if (newState.config.provider.type === 'testnet') {
|
||||
const { config } = newState
|
||||
if ( config && config.provider ) {
|
||||
if (config.provider.type === 'testnet') {
|
||||
newState.config.provider.type = 'ropsten'
|
||||
}
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
@ -28,11 +28,14 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
const transactions = newState.TransactionController.transactions
|
||||
const { TransactionController } = newState
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
const transactions = TransactionController.transactions
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
if (!txMeta.err) return txMeta
|
||||
else if (txMeta.err.message === 'Gave up submitting tx.') txMeta.status = 'failed'
|
||||
return txMeta
|
||||
})
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
const { TransactionController } = newState
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
const transactions = newState.TransactionController.transactions
|
||||
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
if (!txMeta.err) return txMeta
|
||||
if (txMeta.err === 'transaction with the same hash was already imported.') {
|
||||
@ -37,5 +40,6 @@ function transformState (state) {
|
||||
}
|
||||
return txMeta
|
||||
})
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
const { TransactionController } = newState
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
const transactions = newState.TransactionController.transactions
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
if (!txMeta.status === 'failed') return txMeta
|
||||
@ -36,5 +38,6 @@ function transformState (state) {
|
||||
}
|
||||
return txMeta
|
||||
})
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
const { TransactionController } = newState
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
const transactions = newState.TransactionController.transactions
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
// no history: initialize
|
||||
@ -48,5 +50,6 @@ function transformState (state) {
|
||||
txMeta.history = newHistory
|
||||
return txMeta
|
||||
})
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
const { TransactionController } = newState
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
|
||||
const transactions = newState.TransactionController.transactions
|
||||
|
||||
newState.TransactionController.transactions = transactions.map((txMeta, _, txList) => {
|
||||
@ -55,6 +58,7 @@ function transformState (state) {
|
||||
}
|
||||
return txMeta
|
||||
})
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
const { TransactionController } = newState
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
const transactions = newState.TransactionController.transactions
|
||||
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
@ -35,5 +37,6 @@ function transformState (state) {
|
||||
txMeta.submittedTime = (new Date()).getTime()
|
||||
return txMeta
|
||||
})
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ module.exports = {
|
||||
|
||||
function transformState (state) {
|
||||
const newState = state
|
||||
|
||||
const { TransactionController } = newState
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
const transactions = newState.TransactionController.transactions
|
||||
|
||||
if (transactions.length <= 40) return newState
|
||||
@ -46,5 +49,6 @@ function transformState (state) {
|
||||
}
|
||||
|
||||
newState.TransactionController.transactions = reverseTxList.reverse()
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
@ -50,11 +50,19 @@ describe('Migrator', () => {
|
||||
const migrator = new Migrator({ migrations: liveMigrations })
|
||||
migrator.migrateData(firstTimeState)
|
||||
.then((migratedData) => {
|
||||
console.log(migratedData)
|
||||
const last = liveMigrations.length - 1
|
||||
assert.equal(migratedData.meta.version, liveMigrations[last].version)
|
||||
done()
|
||||
}).catch(done)
|
||||
})
|
||||
|
||||
it('should emit an error', function (done) {
|
||||
this.timeout(15000)
|
||||
const migrator = new Migrator({ migrations: [{ version: 1, migrate: async () => { throw new Error('test') } } ] })
|
||||
migrator.on('error', () => done())
|
||||
migrator.migrateData({ meta: {version: 0} })
|
||||
.then((migratedData) => {
|
||||
}).catch(done)
|
||||
})
|
||||
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user