Skip to content

Commit

Permalink
Merge pull request #5020 from MetaMask/FixMigration28
Browse files Browse the repository at this point in the history
Fixes migration 28
  • Loading branch information
danfinlay authored Aug 9, 2018
2 parents 0442e5d + d263d60 commit be1d5a7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/scripts/migrations/028.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function transformState (state) {
const newState = state

if (newState.PreferencesController) {
if (newState.PreferencesController.tokens) {
const identities = newState.TransactionController.identities
if (newState.PreferencesController.tokens && newState.PreferencesController.identities) {
const identities = newState.PreferencesController.identities
const tokens = newState.PreferencesController.tokens
newState.PreferencesController.accountTokens = {}
for (const identity in identities) {
Expand Down
46 changes: 46 additions & 0 deletions test/unit/migrations/028-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const assert = require('assert')
const migration28 = require('../../../app/scripts/migrations/028')

const oldStorage = {
'meta': {},
'data': {
'PreferencesController': {
'tokens': [{address: '0xa', symbol: 'A', decimals: 4}, {address: '0xb', symbol: 'B', decimals: 4}],
'identities': {
'0x6d14': {},
'0x3695': {},
},
},
},
}

describe('migration #28', () => {
it('should add corresponding tokens to accountTokens', (done) => {
migration28.migrate(oldStorage)
.then((newStorage) => {
const newTokens = newStorage.data.PreferencesController.tokens
const newAccountTokens = newStorage.data.PreferencesController.accountTokens

const testTokens = [{address: '0xa', symbol: 'A', decimals: 4}, {address: '0xb', symbol: 'B', decimals: 4}]
assert.equal(newTokens.length, 0, 'tokens is expected to have the length of 0')
assert.equal(newAccountTokens['0x6d14']['mainnet'].length, 2, 'tokens for address is expected to have the length of 2')
assert.equal(newAccountTokens['0x3695']['mainnet'].length, 2, 'tokens for address is expected to have the length of 2')
assert.equal(Object.keys(newAccountTokens).length, 2, 'account tokens should be created for all identities')
assert.deepEqual(newAccountTokens['0x6d14']['mainnet'], testTokens, 'tokens for address should be the same than before')
assert.deepEqual(newAccountTokens['0x3695']['mainnet'], testTokens, 'tokens for address should be the same than before')
done()
})
.catch(done)
})

it('should successfully migrate first time state', (done) => {
migration28.migrate({
meta: {},
data: require('../../../app/scripts/first-time-state'),
})
.then((migratedData) => {
assert.equal(migratedData.meta.version, migration28.version)
done()
}).catch(done)
})
})

0 comments on commit be1d5a7

Please sign in to comment.