Merge pull request #3907 from MetaMask/fix-all-migrations

migrations - back fixes
feature/default_network_editable
kumavis 7 years ago committed by GitHub
commit 90bcf9f7d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/scripts/migrations/013.js
  2. 5
      app/scripts/migrations/015.js
  3. 4
      app/scripts/migrations/016.js
  4. 3
      app/scripts/migrations/017.js
  5. 3
      app/scripts/migrations/018.js
  6. 4
      app/scripts/migrations/019.js
  7. 3
      app/scripts/migrations/022.js
  8. 4
      app/scripts/migrations/023.js
  9. 10
      test/unit/migrator-test.js

@ -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…
Cancel
Save