aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2018-08-10 05:24:38 +0800
committerGitHub <noreply@github.com>2018-08-10 05:24:38 +0800
commitbe1d5a7dd959f061b52f475bf8500b943ade786c (patch)
tree574850fcd9bba8ce9c6545bd319ede2e56d0d92c
parent0442e5dfd7b22fead7bef3beace58703594dbddc (diff)
parentd263d60b4c37bca5f95253965999d541375cc04b (diff)
downloadtangerine-wallet-browser-be1d5a7dd959f061b52f475bf8500b943ade786c.tar
tangerine-wallet-browser-be1d5a7dd959f061b52f475bf8500b943ade786c.tar.gz
tangerine-wallet-browser-be1d5a7dd959f061b52f475bf8500b943ade786c.tar.bz2
tangerine-wallet-browser-be1d5a7dd959f061b52f475bf8500b943ade786c.tar.lz
tangerine-wallet-browser-be1d5a7dd959f061b52f475bf8500b943ade786c.tar.xz
tangerine-wallet-browser-be1d5a7dd959f061b52f475bf8500b943ade786c.tar.zst
tangerine-wallet-browser-be1d5a7dd959f061b52f475bf8500b943ade786c.zip
Merge pull request #5020 from MetaMask/FixMigration28v4.9.2v4.9.1
Fixes migration 28
-rw-r--r--app/scripts/migrations/028.js4
-rw-r--r--test/unit/migrations/028-test.js46
2 files changed, 48 insertions, 2 deletions
diff --git a/app/scripts/migrations/028.js b/app/scripts/migrations/028.js
index 6553a1052..9e995ee1a 100644
--- a/app/scripts/migrations/028.js
+++ b/app/scripts/migrations/028.js
@@ -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) {
diff --git a/test/unit/migrations/028-test.js b/test/unit/migrations/028-test.js
new file mode 100644
index 000000000..a9c7dcdf1
--- /dev/null
+++ b/test/unit/migrations/028-test.js
@@ -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)
+ })
+})