diff --git a/.eslintrc.js b/.eslintrc.js index 14d5482de..ca9fe4677 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -133,6 +133,7 @@ module.exports = { 'ui/__mocks__/*.js', 'shared/**/*.test.js', 'development/**/*.test.js', + 'app/scripts/migrations/*.test.js', ], extends: ['@metamask/eslint-config-mocha'], rules: { @@ -155,6 +156,7 @@ module.exports = { 'ui/__mocks__/*.js', 'shared/**/*.test.js', 'development/**/*.test.js', + 'app/scripts/migrations/*.test.js', ], extends: ['@metamask/eslint-config-jest'], rules: { diff --git a/app/scripts/migrations/021.test.js b/app/scripts/migrations/021.test.js index 261d40f81..0e6413966 100644 --- a/app/scripts/migrations/021.test.js +++ b/app/scripts/migrations/021.test.js @@ -1,17 +1,11 @@ -import { strict as assert } from 'assert'; import wallet2 from '../../../test/lib/migrations/002.json'; import migration21 from './021'; -describe('wallet2 is migrated successfully with out the BlacklistController', function () { - it('should delete BlacklistController key', function (done) { - migration21 - .migrate(wallet2) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 21); - assert(!migratedData.data.BlacklistController); - assert(!migratedData.data.RecentBlocks); - done(); - }) - .catch(done); +describe('wallet2 is migrated successfully with out the BlacklistController', () => { + it('should delete BlacklistController key', async () => { + const migratedData = await migration21.migrate(wallet2); + expect(migratedData.meta.version).toStrictEqual(21); + expect(!migratedData.data.BlacklistController).toStrictEqual(true); + expect(!migratedData.data.RecentBlocks).toStrictEqual(true); }); }); diff --git a/app/scripts/migrations/022.test.js b/app/scripts/migrations/022.test.js index 425bfeb91..c4e91aac5 100644 --- a/app/scripts/migrations/022.test.js +++ b/app/scripts/migrations/022.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import migration22 from './022'; @@ -16,25 +15,21 @@ const storage = { }, }; -describe('storage is migrated successfully where transactions that are submitted have submittedTimes', function () { - it('should add submittedTime key on the txMeta if appropriate', function (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); +describe('storage is migrated successfully where transactions that are submitted have submittedTimes', () => { + it('should add submittedTime key on the txMeta if appropriate', async () => { + const migratedData = await migration22.migrate(storage); + const [ + txMeta1, + txMeta2, + txMeta3, + ] = migratedData.data.TransactionController.transactions; + + expect(migratedData.meta.version).toStrictEqual(22); + // should have written a submitted time + expect.anything(txMeta1.submittedTime); + // should not have written a submitted time because it already has one + expect(txMeta2.submittedTime).toStrictEqual(properTime); + // should not have written a submitted time + expect(!txMeta3.submittedTime).toStrictEqual(true); }); }); diff --git a/app/scripts/migrations/023.test.js b/app/scripts/migrations/023.test.js index 0ef74beb6..8fe2e5ff8 100644 --- a/app/scripts/migrations/023.test.js +++ b/app/scripts/migrations/023.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import migration23 from './023'; @@ -52,67 +51,43 @@ while (transactions20.length < 20) { storage.data.TransactionController.transactions = transactions; -describe('storage is migrated successfully and the proper transactions are remove from state', function () { - it('should remove transactions that are unneeded', function (done) { - migration23 - .migrate(storage) - .then((migratedData) => { - let leftoverNonDeletableTxCount = 0; - const migratedTransactions = - migratedData.data.TransactionController.transactions; - migratedTransactions.forEach((tx) => { - if (!deletableTxStates.find((s) => s === tx.status)) { - leftoverNonDeletableTxCount += 1; - } - }); - assert.equal( - leftoverNonDeletableTxCount, - nonDeletableCount, - "migration shouldn't delete transactions we want to keep", - ); - assert( - migratedTransactions.length >= 40, - `should be equal or greater to 40 if they are non deletable states got ${migratedTransactions.length} transactions`, - ); - done(); - }) - .catch(done); +describe('storage is migrated successfully and the proper transactions are remove from state', () => { + it('should remove transactions that are unneeded', async () => { + const migratedData = await migration23.migrate(storage); + + let leftoverNonDeletableTxCount = 0; + const migratedTransactions = + migratedData.data.TransactionController.transactions; + migratedTransactions.forEach((tx) => { + if (!deletableTxStates.find((s) => s === tx.status)) { + leftoverNonDeletableTxCount += 1; + } + }); + + expect(leftoverNonDeletableTxCount).toStrictEqual(nonDeletableCount); + + expect(migratedTransactions.length >= 40).toStrictEqual(true); }); - it('should not remove any transactions because 40 is the expected limit', function (done) { + it('should not remove any transactions because 40 is the expected limit', async () => { storage.meta.version = 22; storage.data.TransactionController.transactions = transactions40; - migration23 - .migrate(storage) - .then((migratedData) => { - const migratedTransactions = - migratedData.data.TransactionController.transactions; - assert.equal( - migratedTransactions.length, - 40, - "migration shouldn't delete when at limit", - ); - done(); - }) - .catch(done); + const migratedData = await migration23.migrate(storage); + const migratedTransactions = + migratedData.data.TransactionController.transactions; + + expect(migratedTransactions).toHaveLength(40); }); - it('should not remove any transactions because 20 txs is under the expected limit', function (done) { + it('should not remove any transactions because 20 txs is under the expected limit', async () => { storage.meta.version = 22; storage.data.TransactionController.transactions = transactions20; - migration23 - .migrate(storage) - .then((migratedData) => { - const migratedTransactions = - migratedData.data.TransactionController.transactions; - assert.equal( - migratedTransactions.length, - 20, - "migration shouldn't delete when under limit", - ); - done(); - }) - .catch(done); + + const migratedData = await migration23.migrate(storage); + const migratedTransactions = + migratedData.data.TransactionController.transactions; + + expect(migratedTransactions).toHaveLength(20); }); }); diff --git a/app/scripts/migrations/024.test.js b/app/scripts/migrations/024.test.js index f87e45748..c1bc709fb 100644 --- a/app/scripts/migrations/024.test.js +++ b/app/scripts/migrations/024.test.js @@ -1,4 +1,4 @@ -import { strict as assert } from 'assert'; +/* eslint-disable jest/no-conditional-expect */ import data from '../first-time-state'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import migration24 from './024'; @@ -31,38 +31,27 @@ while (transactions.length <= 10) { storage.data.TransactionController.transactions = transactions; -describe('storage is migrated successfully and the txParams.from are lowercase', function () { - it('should lowercase the from for unapproved txs', function (done) { - migration24 - .migrate(storage) - .then((migratedData) => { - const migratedTransactions = - migratedData.data.TransactionController.transactions; - migratedTransactions.forEach((tx) => { - if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) { - assert.equal( - tx.txParams.from, - '0x8acce2391c0d510a6c5e5d8f819a678f79b7e675', - ); - } else { - assert.equal( - tx.txParams.from, - '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675', - ); - } - }); - done(); - }) - .catch(done); +describe('storage is migrated successfully and the txParams.from are lowercase', () => { + it('should lowercase the from for unapproved txs', async () => { + const migratedData = await migration24.migrate(storage); + const migratedTransactions = + migratedData.data.TransactionController.transactions; + + migratedTransactions.forEach((tx) => { + if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) { + expect(tx.txParams.from).toStrictEqual( + '0x8acce2391c0d510a6c5e5d8f819a678f79b7e675', + ); + } else { + expect(tx.txParams.from).toStrictEqual( + '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675', + ); + } + }); }); - it('should migrate first time state', function (done) { - migration24 - .migrate(firstTimeState) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 24); - done(); - }) - .catch(done); + it('should migrate first time state', async () => { + const migratedData = await migration24.migrate(firstTimeState); + expect(migratedData.meta.version).toStrictEqual(24); }); }); diff --git a/app/scripts/migrations/025.test.js b/app/scripts/migrations/025.test.js index 9e0ff846b..81e000d68 100644 --- a/app/scripts/migrations/025.test.js +++ b/app/scripts/migrations/025.test.js @@ -1,4 +1,4 @@ -import { strict as assert } from 'assert'; +/* eslint-disable jest/no-conditional-expect */ import data from '../first-time-state'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import migration25 from './025'; @@ -36,33 +36,25 @@ while (transactions.length <= 10) { storage.data.TransactionController.transactions = transactions; -describe('storage is migrated successfully and the txParams.from are lowercase', function () { - it('should lowercase the from for unapproved txs', function (done) { - migration25 - .migrate(storage) - .then((migratedData) => { - const migratedTransactions = - migratedData.data.TransactionController.transactions; - migratedTransactions.forEach((tx) => { - if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) { - assert(!tx.txParams.random); - } - if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) { - assert(!tx.txParams.chainId); - } - }); - done(); - }) - .catch(done); +describe('storage is migrated successfully and the txParams.from are lowercase', () => { + it('should lowercase the from for unapproved txs', async () => { + const migratedData = await migration25.migrate(storage); + + const migratedTransactions = + migratedData.data.TransactionController.transactions; + migratedTransactions.forEach((tx) => { + if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) { + expect(!tx.txParams.random).toStrictEqual(true); + } + if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) { + expect(!tx.txParams.chainId).toStrictEqual(true); + } + }); }); - it('should migrate first time state', function (done) { - migration25 - .migrate(firstTimeState) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 25); - done(); - }) - .catch(done); + it('should migrate first time state', async () => { + const migratedData = await migration25.migrate(firstTimeState); + + expect(migratedData.meta.version).toStrictEqual(25); }); }); diff --git a/app/scripts/migrations/026.test.js b/app/scripts/migrations/026.test.js index ca4ac9a64..9ab1b3382 100644 --- a/app/scripts/migrations/026.test.js +++ b/app/scripts/migrations/026.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import firstTimeState from '../first-time-state'; import migration26 from './026'; @@ -15,35 +14,25 @@ const oldStorage = { }, }; -describe('migration #26', function () { - it('should move the identities from KeyringController', function (done) { - migration26 - .migrate(oldStorage) - .then((newStorage) => { - const { identities } = newStorage.data.PreferencesController; - assert.deepEqual(identities, { - '0x1e77e2': { name: 'Test Account 1', address: '0x1e77e2' }, - '0x7e57e2': { name: 'Test Account 2', address: '0x7e57e2' }, - }); - assert.strictEqual( - newStorage.data.KeyringController.walletNicknames, - undefined, - ); - done(); - }) - .catch(done); +describe('migration #26', () => { + it('should move the identities from KeyringController', async () => { + const newStorage = await migration26.migrate(oldStorage); + + const { identities } = newStorage.data.PreferencesController; + + expect(identities).toStrictEqual({ + '0x1e77e2': { name: 'Test Account 1', address: '0x1e77e2' }, + '0x7e57e2': { name: 'Test Account 2', address: '0x7e57e2' }, + }); + + expect(newStorage.data.KeyringController.walletNicknames).toBeUndefined(); }); - it('should successfully migrate first time state', function (done) { - migration26 - .migrate({ - meta: {}, - data: firstTimeState, - }) - .then((migratedData) => { - assert.equal(migratedData.meta.version, migration26.version); - done(); - }) - .catch(done); + it('should successfully migrate first time state', async () => { + const migratedData = await migration26.migrate({ + meta: {}, + data: firstTimeState, + }); + expect(migratedData.meta.version).toStrictEqual(migration26.version); }); }); diff --git a/app/scripts/migrations/027.test.js b/app/scripts/migrations/027.test.js index 29df2dfb0..006bec019 100644 --- a/app/scripts/migrations/027.test.js +++ b/app/scripts/migrations/027.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import firstTimeState from '../first-time-state'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import migration27 from './027'; @@ -22,38 +21,27 @@ while (transactions.length < 9) { oldStorage.data.TransactionController.transactions = transactions; -describe('migration #27', function () { - it('should remove rejected transactions', function (done) { - migration27 - .migrate(oldStorage) - .then((newStorage) => { - const newTransactions = - newStorage.data.TransactionController.transactions; - assert.equal( - newTransactions.length, - 6, - 'transactions is expected to have the length of 6', - ); - newTransactions.forEach((txMeta) => { - if (txMeta.status === TRANSACTION_STATUSES.REJECTED) { - done(new Error('transaction was found with a status of rejected')); - } - }); - done(); - }) - .catch(done); +describe('migration #27', () => { + it('should remove rejected transactions', async () => { + const newStorage = await migration27.migrate(oldStorage); + + const newTransactions = newStorage.data.TransactionController.transactions; + + expect(newTransactions).toHaveLength(6); + + newTransactions.forEach((txMeta) => { + if (txMeta.status === TRANSACTION_STATUSES.REJECTED) { + throw new Error('transaction was found with a status of rejected'); + } + }); }); - it('should successfully migrate first time state', function (done) { - migration27 - .migrate({ - meta: {}, - data: firstTimeState, - }) - .then((migratedData) => { - assert.equal(migratedData.meta.version, migration27.version); - done(); - }) - .catch(done); + it('should successfully migrate first time state', async () => { + const migratedData = await migration27.migrate({ + meta: {}, + data: firstTimeState, + }); + + expect(migratedData.meta.version).toStrictEqual(migration27.version); }); }); diff --git a/app/scripts/migrations/028.test.js b/app/scripts/migrations/028.test.js index 5d755f50c..7a65a7b90 100644 --- a/app/scripts/migrations/028.test.js +++ b/app/scripts/migrations/028.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import firstTimeState from '../first-time-state'; import migration28 from './028'; @@ -18,64 +17,37 @@ const oldStorage = { }, }; -describe('migration #28', function () { - it('should add corresponding tokens to accountTokens', function (done) { - migration28 - .migrate(oldStorage) - .then((newStorage) => { - const newTokens = newStorage.data.PreferencesController.tokens; - const newAccountTokens = - newStorage.data.PreferencesController.accountTokens; +describe('migration #28', () => { + it('should add corresponding tokens to accountTokens', async () => { + const newStorage = await migration28.migrate(oldStorage); - 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); + 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 }, + ]; + expect(newTokens).toHaveLength(0); + + expect(newAccountTokens['0x6d14'].mainnet).toHaveLength(2); + + expect(newAccountTokens['0x3695'].mainnet).toHaveLength(2); + + expect(Object.keys(newAccountTokens)).toHaveLength(2); + + expect(newAccountTokens['0x6d14'].mainnet).toStrictEqual(testTokens); + + expect(newAccountTokens['0x3695'].mainnet).toStrictEqual(testTokens); }); - it('should successfully migrate first time state', function (done) { - migration28 - .migrate({ - meta: {}, - data: firstTimeState, - }) - .then((migratedData) => { - assert.equal(migratedData.meta.version, migration28.version); - done(); - }) - .catch(done); + it('should successfully migrate first time state', async () => { + const migratedData = await migration28.migrate({ + meta: {}, + data: firstTimeState, + }); + + expect(migratedData.meta.version).toStrictEqual(migration28.version); }); }); diff --git a/app/scripts/migrations/029.test.js b/app/scripts/migrations/029.test.js index 53ce28695..e5ba056b8 100644 --- a/app/scripts/migrations/029.test.js +++ b/app/scripts/migrations/029.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import migration29 from './029'; @@ -30,38 +29,20 @@ const storage = { }, }; -describe('storage is migrated successfully where transactions that are submitted have submittedTimes', function () { - it('should auto fail transactions more than 12 hours old', function (done) { - migration29 - .migrate(storage) - .then((migratedData) => { - const txs = migratedData.data.TransactionController.transactions; - const [txMeta1] = txs; - assert.equal(migratedData.meta.version, 29); +describe('storage is migrated successfully where transactions that are submitted have submittedTimes', () => { + it('should auto fail transactions more than 12 hours old', async () => { + const migratedData = await migration29.migrate(storage); + const txs = migratedData.data.TransactionController.transactions; + const [txMeta1] = txs; - assert.equal( - txMeta1.status, - TRANSACTION_STATUSES.FAILED, - 'old tx is auto failed', - ); - assert( - txMeta1.err.message.includes('too long'), - 'error message assigned', - ); + expect(migratedData.meta.version).toStrictEqual(29); + expect(txMeta1.status).toStrictEqual(TRANSACTION_STATUSES.FAILED); - txs.forEach((tx) => { - if (tx.id === 1) { - return; - } - assert.notEqual( - tx.status, - TRANSACTION_STATUSES.FAILED, - 'other tx is not auto failed', - ); - }); - - done(); - }) - .catch(done); + txs.forEach((tx) => { + if (tx.id === 1) { + return; + } + expect(tx.status).not.toStrictEqual(TRANSACTION_STATUSES.FAILED); + }); }); }); diff --git a/app/scripts/migrations/030.test.js b/app/scripts/migrations/030.test.js index f03f51231..fdf7ca9d3 100644 --- a/app/scripts/migrations/030.test.js +++ b/app/scripts/migrations/030.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import migrationTemplate from './030'; const storage = { @@ -33,29 +32,20 @@ const storage = { }, }; -describe('storage is migrated successfully', function () { - it('should work', function (done) { - migrationTemplate - .migrate(storage) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 30); - assert.equal( - migratedData.data.PreferencesController.frequentRpcListDetail[0] - .chainId, - undefined, - ); - assert.equal( - migratedData.data.PreferencesController.frequentRpcListDetail[1] - .chainId, - '1', - ); - assert.equal( - migratedData.data.NetworkController.provider.chainId, - undefined, - ); - assert.equal(migratedData.data.NetworkController.network, undefined); - done(); - }) - .catch(done); +describe('storage is migrated successfully', () => { + it('should work', async () => { + const migratedData = await migrationTemplate.migrate(storage); + + expect(migratedData.meta.version).toStrictEqual(30); + expect( + migratedData.data.PreferencesController.frequentRpcListDetail[0].chainId, + ).toBeUndefined(); + expect( + migratedData.data.PreferencesController.frequentRpcListDetail[1].chainId, + ).toStrictEqual('1'); + expect( + migratedData.data.NetworkController.provider.chainId, + ).toBeUndefined(); + expect(migratedData.data.NetworkController.network).toBeUndefined(); }); }); diff --git a/app/scripts/migrations/031.test.js b/app/scripts/migrations/031.test.js index 62216e85d..12029e334 100644 --- a/app/scripts/migrations/031.test.js +++ b/app/scripts/migrations/031.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration31 from './031'; -describe('migration #31', function () { - it('should set completedOnboarding to true if vault exists', function (done) { +describe('migration #31', () => { + it('should set completedOnboarding to true if vault exists', async () => { const oldStorage = { meta: {}, data: { @@ -26,19 +25,14 @@ describe('migration #31', function () { }, }; - migration31 - .migrate(oldStorage) - .then((newStorage) => { - assert.equal( - newStorage.data.PreferencesController.completedOnboarding, - true, - ); - done(); - }) - .catch(done); + const newStorage = await migration31.migrate(oldStorage); + + expect( + newStorage.data.PreferencesController.completedOnboarding, + ).toStrictEqual(true); }); - it('should set completedOnboarding to false if vault does not exist', function (done) { + it('should set completedOnboarding to false if vault does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -56,15 +50,9 @@ describe('migration #31', function () { }, }; - migration31 - .migrate(oldStorage) - .then((newStorage) => { - assert.equal( - newStorage.data.PreferencesController.completedOnboarding, - false, - ); - done(); - }) - .catch(done); + const newStorage = await migration31.migrate(oldStorage); + expect( + newStorage.data.PreferencesController.completedOnboarding, + ).toStrictEqual(false); }); }); diff --git a/app/scripts/migrations/033.test.js b/app/scripts/migrations/033.test.js index 382622d39..672f138e8 100644 --- a/app/scripts/migrations/033.test.js +++ b/app/scripts/migrations/033.test.js @@ -1,7 +1,6 @@ -import { strict as assert } from 'assert'; import migration33 from './033'; -describe('Migration to delete notice controller', function () { +describe('Migration to delete notice controller', () => { const oldStorage = { meta: {}, data: { @@ -31,9 +30,8 @@ describe('Migration to delete notice controller', function () { }, }; - it('removes notice controller from state', function () { - migration33.migrate(oldStorage).then((newStorage) => { - assert.equal(newStorage.data.NoticeController, undefined); - }); + it('removes notice controller from state', async () => { + const newStorage = await migration33.migrate(oldStorage); + expect(newStorage.data.NoticeController).toBeUndefined(); }); }); diff --git a/app/scripts/migrations/034.test.js b/app/scripts/migrations/034.test.js index 7902b5f13..7e9c5434f 100644 --- a/app/scripts/migrations/034.test.js +++ b/app/scripts/migrations/034.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration34 from './034'; -describe('migration #34', function () { - it('should update the version metadata', function (done) { +describe('migration #34', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 33, @@ -10,18 +9,11 @@ describe('migration #34', function () { data: {}, }; - migration34 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 34, - }); - done(); - }) - .catch(done); + const newStorage = await migration34.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(34); }); - it('should set migratedPrivacyMode & privacyMode if featureFlags.privacyMode was false', function (done) { + it('should set migratedPrivacyMode & privacyMode if featureFlags.privacyMode was false', async () => { const oldStorage = { meta: {}, data: { @@ -33,21 +25,16 @@ describe('migration #34', function () { }, }; - migration34 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.PreferencesController, { - migratedPrivacyMode: true, - featureFlags: { - privacyMode: true, - }, - }); - done(); - }) - .catch(done); + const newStorage = await migration34.migrate(oldStorage); + expect(newStorage.data.PreferencesController).toStrictEqual({ + migratedPrivacyMode: true, + featureFlags: { + privacyMode: true, + }, + }); }); - it('should NOT change any state if migratedPrivacyMode is already set to true', function (done) { + it('should NOT change any state if migratedPrivacyMode is already set to true', async () => { const oldStorage = { meta: {}, data: { @@ -60,16 +47,11 @@ describe('migration #34', function () { }, }; - migration34 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration34.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if migratedPrivacyMode is already set to false', function (done) { + it('should NOT change any state if migratedPrivacyMode is already set to false', async () => { const oldStorage = { meta: {}, data: { @@ -82,31 +64,21 @@ describe('migration #34', function () { }, }; - migration34 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration34.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if PreferencesController is missing', function (done) { + it('should NOT change any state if PreferencesController is missing', async () => { const oldStorage = { meta: {}, data: {}, }; - migration34 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration34.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(newStorage.data); }); - it('should NOT change any state if featureFlags.privacyMode is already true', function (done) { + it('should NOT change any state if featureFlags.privacyMode is already true', async () => { const oldStorage = { meta: {}, data: { @@ -118,12 +90,7 @@ describe('migration #34', function () { }, }; - migration34 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration34.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); }); diff --git a/app/scripts/migrations/035.test.js b/app/scripts/migrations/035.test.js index 03454b2ea..186296576 100644 --- a/app/scripts/migrations/035.test.js +++ b/app/scripts/migrations/035.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration35 from './035'; -describe('migration #35', function () { - it('should update the version metadata', function (done) { +describe('migration #35', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 34, @@ -10,18 +9,11 @@ describe('migration #35', function () { data: {}, }; - migration35 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 35, - }); - done(); - }) - .catch(done); + const newStorage = await migration35.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(35); }); - it('should delete seedWords', function (done) { + it('should delete seedWords', async () => { const oldStorage = { meta: {}, data: { @@ -31,16 +23,11 @@ describe('migration #35', function () { }, }; - migration35 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.PreferencesController, {}); - done(); - }) - .catch(done); + const newStorage = await migration35.migrate(oldStorage); + expect(newStorage.data.PreferencesController).toStrictEqual({}); }); - it('should delete falsy seedWords', function (done) { + it('should delete falsy seedWords', async () => { const oldStorage = { meta: {}, data: { @@ -50,16 +37,11 @@ describe('migration #35', function () { }, }; - migration35 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.PreferencesController, {}); - done(); - }) - .catch(done); + const newStorage = await migration35.migrate(oldStorage); + expect(newStorage.data.PreferencesController).toStrictEqual({}); }); - it('should leave state without seedWords unchanged', function (done) { + it('should leave state without seedWords unchanged', async () => { const oldStorage = { meta: {}, data: { @@ -88,12 +70,7 @@ describe('migration #35', function () { }, }; - migration35 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration35.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); }); diff --git a/app/scripts/migrations/036.test.js b/app/scripts/migrations/036.test.js index ecc44c557..a79ad43f5 100644 --- a/app/scripts/migrations/036.test.js +++ b/app/scripts/migrations/036.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration36 from './036'; -describe('migration #36', function () { - it('should update the version metadata', function (done) { +describe('migration #36', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 35, @@ -10,18 +9,11 @@ describe('migration #36', function () { data: {}, }; - migration36 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 36, - }); - done(); - }) - .catch(done); + const newStorage = await migration36.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(36); }); - it('should remove privacyMode if featureFlags.privacyMode was false', function (done) { + it('should remove privacyMode if featureFlags.privacyMode was false', async () => { const oldStorage = { meta: {}, data: { @@ -33,18 +25,13 @@ describe('migration #36', function () { }, }; - migration36 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.PreferencesController, { - featureFlags: {}, - }); - done(); - }) - .catch(done); + const newStorage = await migration36.migrate(oldStorage); + expect(newStorage.data.PreferencesController).toStrictEqual({ + featureFlags: {}, + }); }); - it('should remove privacyMode if featureFlags.privacyMode was true', function (done) { + it('should remove privacyMode if featureFlags.privacyMode was true', async () => { const oldStorage = { meta: {}, data: { @@ -56,18 +43,13 @@ describe('migration #36', function () { }, }; - migration36 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.PreferencesController, { - featureFlags: {}, - }); - done(); - }) - .catch(done); + const newStorage = await migration36.migrate(oldStorage); + expect(newStorage.data.PreferencesController).toStrictEqual({ + featureFlags: {}, + }); }); - it('should NOT change any state if privacyMode does not exist', function (done) { + it('should NOT change any state if privacyMode does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -78,31 +60,21 @@ describe('migration #36', function () { }, }; - migration36 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration36.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if PreferencesController is missing', function (done) { + it('should NOT change any state if PreferencesController is missing', async () => { const oldStorage = { meta: {}, data: {}, }; - migration36 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration36.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if featureFlags is missing', function (done) { + it('should NOT change any state if featureFlags is missing', async () => { const oldStorage = { meta: {}, data: { @@ -110,12 +82,7 @@ describe('migration #36', function () { }, }; - migration36 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration36.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); }); diff --git a/app/scripts/migrations/037.test.js b/app/scripts/migrations/037.test.js index 688f66a9a..0a0d935a8 100644 --- a/app/scripts/migrations/037.test.js +++ b/app/scripts/migrations/037.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration37 from './037'; -describe('migration #37', function () { - it('should update the version metadata', function (done) { +describe('migration #37', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 36, @@ -10,18 +9,11 @@ describe('migration #37', function () { data: {}, }; - migration37 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 37, - }); - done(); - }) - .catch(done); + const newStorage = await migration37.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(37); }); - it('should transform old state to new format', function (done) { + it('should transform old state to new format', async () => { const oldStorage = { meta: {}, data: { @@ -51,42 +43,37 @@ describe('migration #37', function () { }, }; - migration37 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.AddressBookController.addressBook, { - 4: { - '0x1De7e54679bfF0c23856FbF547b2394e723FCA91': { - address: '0x1De7e54679bfF0c23856FbF547b2394e723FCA91', - chainId: '4', - isEns: false, - memo: '', - name: 'account 3', - }, - '0x32Be343B94f860124dC4fEe278FDCBD38C102D88': { - address: '0x32Be343B94f860124dC4fEe278FDCBD38C102D88', - chainId: '4', - isEns: false, - memo: '', - name: 'account 2', - }, - }, - 2: { - '0x1De7e54679bfF0c23856FbF547b2394e723FCA93': { - address: '0x1De7e54679bfF0c23856FbF547b2394e723FCA93', - chainId: '2', - isEns: false, - memo: '', - name: 'account 2', - }, - }, - }); - done(); - }) - .catch(done); + const newStorage = await migration37.migrate(oldStorage); + expect(newStorage.data.AddressBookController.addressBook).toStrictEqual({ + 4: { + '0x1De7e54679bfF0c23856FbF547b2394e723FCA91': { + address: '0x1De7e54679bfF0c23856FbF547b2394e723FCA91', + chainId: '4', + isEns: false, + memo: '', + name: 'account 3', + }, + '0x32Be343B94f860124dC4fEe278FDCBD38C102D88': { + address: '0x32Be343B94f860124dC4fEe278FDCBD38C102D88', + chainId: '4', + isEns: false, + memo: '', + name: 'account 2', + }, + }, + 2: { + '0x1De7e54679bfF0c23856FbF547b2394e723FCA93': { + address: '0x1De7e54679bfF0c23856FbF547b2394e723FCA93', + chainId: '2', + isEns: false, + memo: '', + name: 'account 2', + }, + }, + }); }); - it('ens validation test', function (done) { + it('ens validation test', async () => { const oldStorage = { meta: {}, data: { @@ -103,22 +90,17 @@ describe('migration #37', function () { }, }; - migration37 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.AddressBookController.addressBook, { - 4: { - '0x1De7e54679bfF0c23856FbF547b2394e723FCA91': { - address: '0x1De7e54679bfF0c23856FbF547b2394e723FCA91', - chainId: '4', - isEns: true, - memo: '', - name: 'metamask.eth', - }, - }, - }); - done(); - }) - .catch(done); + const newStorage = await migration37.migrate(oldStorage); + expect(newStorage.data.AddressBookController.addressBook).toStrictEqual({ + 4: { + '0x1De7e54679bfF0c23856FbF547b2394e723FCA91': { + address: '0x1De7e54679bfF0c23856FbF547b2394e723FCA91', + chainId: '4', + isEns: true, + memo: '', + name: 'metamask.eth', + }, + }, + }); }); }); diff --git a/app/scripts/migrations/038.test.js b/app/scripts/migrations/038.test.js index 93d826f78..5b8f8c8b7 100644 --- a/app/scripts/migrations/038.test.js +++ b/app/scripts/migrations/038.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration38 from './038'; -describe('migration #38', function () { - it('should update the version metadata', function (done) { +describe('migration #38', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 37, @@ -10,36 +9,23 @@ describe('migration #38', function () { data: {}, }; - migration38 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 38, - }); - done(); - }) - .catch(done); + const newStorage = await migration38.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(38); }); - it('should add a fullScreenVsPopup property set to either "control" or "fullScreen"', function (done) { + it('should add a fullScreenVsPopup property set to either "control" or "fullScreen"', async () => { const oldStorage = { meta: {}, data: {}, }; - migration38 - .migrate(oldStorage) - .then((newStorage) => { - assert.equal( - newStorage.data.ABTestController.abTests.fullScreenVsPopup, - 'control', - ); - done(); - }) - .catch(done); + const newStorage = await migration38.migrate(oldStorage); + expect( + newStorage.data.ABTestController?.abTests?.fullScreenVsPopup, + ).toStrictEqual('control'); }); - it('should leave the fullScreenVsPopup property unchanged if it exists', function (done) { + it('should leave the fullScreenVsPopup property unchanged if it exists', async () => { const oldStorage = { meta: {}, data: { @@ -51,16 +37,9 @@ describe('migration #38', function () { }, }; - migration38 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.ABTestController, { - abTests: { - fullScreenVsPopup: 'fullScreen', - }, - }); - done(); - }) - .catch(done); + const newStorage = await migration38.migrate(oldStorage); + expect( + newStorage.data.ABTestController?.abTests?.fullScreenVsPopup, + ).toStrictEqual('fullScreen'); }); }); diff --git a/app/scripts/migrations/039.test.js b/app/scripts/migrations/039.test.js index 3efbbf49d..f7a8fc422 100644 --- a/app/scripts/migrations/039.test.js +++ b/app/scripts/migrations/039.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration39 from './039'; -describe('migration #39', function () { - it('should update the version metadata', function (done) { +describe('migration #39', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 38, @@ -10,18 +9,11 @@ describe('migration #39', function () { data: {}, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 39, - }); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(39); }); - it('should update old DAI token symbol to SAI in tokens', function (done) { + it('should update old DAI token symbol to SAI in tokens', async () => { const oldStorage = { meta: {}, data: { @@ -47,34 +39,29 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.PreferencesController, { - tokens: [ - { - address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', - decimals: 18, - symbol: 'SAI', - }, - { - address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef', - symbol: 'BAT', - decimals: 18, - }, - { - address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4', - symbol: 'META', - decimals: 18, - }, - ], - }); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data.PreferencesController).toStrictEqual({ + tokens: [ + { + address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', + decimals: 18, + symbol: 'SAI', + }, + { + address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef', + symbol: 'BAT', + decimals: 18, + }, + { + address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4', + symbol: 'META', + decimals: 18, + }, + ], + }); }); - it('should update old DAI token symbol to SAI in accountTokens', function (done) { + it('should update old DAI token symbol to SAI in accountTokens', async () => { const oldStorage = { meta: {}, data: { @@ -118,52 +105,47 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data.PreferencesController, { - accountTokens: { - '0x7250739de134d33ec7ab1ee592711e15098c9d2d': { - mainnet: [ - { - address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', - decimals: 18, - symbol: 'SAI', - }, - ], + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data.PreferencesController).toStrictEqual({ + accountTokens: { + '0x7250739de134d33ec7ab1ee592711e15098c9d2d': { + mainnet: [ + { + address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', + decimals: 18, + symbol: 'SAI', }, - '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': { - mainnet: [], - rinkeby: [], + ], + }, + '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': { + mainnet: [], + rinkeby: [], + }, + '0x8e5d75d60224ea0c33d1041e75de68b1c3cb6dd5': {}, + '0xb3958fb96c8201486ae20be1d5c9f58083df343a': { + mainnet: [ + { + address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', + decimals: 18, + symbol: 'SAI', }, - '0x8e5d75d60224ea0c33d1041e75de68b1c3cb6dd5': {}, - '0xb3958fb96c8201486ae20be1d5c9f58083df343a': { - mainnet: [ - { - address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', - decimals: 18, - symbol: 'SAI', - }, - { - address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef', - decimals: 18, - symbol: 'BAT', - }, - { - address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4', - decimals: 18, - symbol: 'META', - }, - ], + { + address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef', + decimals: 18, + symbol: 'BAT', }, - }, - }); - done(); - }) - .catch(done); + { + address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4', + decimals: 18, + symbol: 'META', + }, + ], + }, + }, + }); }); - it('should NOT change any state if accountTokens is not an object', function (done) { + it('should NOT change any state if accountTokens is not an object', async () => { const oldStorage = { meta: {}, data: { @@ -173,16 +155,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if accountTokens is an object with invalid values', function (done) { + it('should NOT change any state if accountTokens is an object with invalid values', async () => { const oldStorage = { meta: {}, data: { @@ -205,16 +182,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if accountTokens includes the new DAI token', function (done) { + it('should NOT change any state if accountTokens includes the new DAI token', async () => { const oldStorage = { meta: {}, data: { @@ -258,16 +230,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if tokens includes the new DAI token', function (done) { + it('should NOT change any state if tokens includes the new DAI token', async () => { const oldStorage = { meta: {}, data: { @@ -288,16 +255,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if tokens does not include DAI', function (done) { + it('should NOT change any state if tokens does not include DAI', async () => { const oldStorage = { meta: {}, data: { @@ -318,16 +280,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if a tokens property has invalid entries', function (done) { + it('should NOT change any state if a tokens property has invalid entries', async () => { const oldStorage = { meta: {}, data: { @@ -337,16 +294,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if a tokens property is not an array', function (done) { + it('should NOT change any state if a tokens property is not an array', async () => { const oldStorage = { meta: {}, data: { @@ -356,16 +308,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if a tokens property is null', function (done) { + it('should NOT change any state if a tokens property is null', async () => { const oldStorage = { meta: {}, data: { @@ -375,16 +322,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if a tokens property is missing', function (done) { + it('should NOT change any state if a tokens property is missing', async () => { const oldStorage = { meta: {}, data: { @@ -392,16 +334,11 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if a accountTokens property is missing', function (done) { + it('should NOT change any state if a accountTokens property is missing', async () => { const oldStorage = { meta: {}, data: { @@ -409,27 +346,17 @@ describe('migration #39', function () { }, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should NOT change any state if PreferencesController is missing', function (done) { + it('should NOT change any state if PreferencesController is missing', async () => { const oldStorage = { meta: {}, data: {}, }; - migration39 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, oldStorage.data); - done(); - }) - .catch(done); + const newStorage = await migration39.migrate(oldStorage); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); }); diff --git a/app/scripts/migrations/040.test.js b/app/scripts/migrations/040.test.js index ba10e4b75..47e5809b9 100644 --- a/app/scripts/migrations/040.test.js +++ b/app/scripts/migrations/040.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration40 from './040'; -describe('migration #40', function () { - it('should update the version metadata', function (done) { +describe('migration #40', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 39, @@ -10,18 +9,11 @@ describe('migration #40', function () { data: {}, }; - migration40 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 40, - }); - done(); - }) - .catch(done); + const newStorage = await migration40.migrate(oldStorage); + expect(newStorage.meta?.version).toStrictEqual(40); }); - it('should delete ProviderApprovalController storage key', function (done) { + it('should delete ProviderApprovalController storage key', async () => { const oldStorage = { meta: {}, data: { @@ -30,27 +22,21 @@ describe('migration #40', function () { }, }; - migration40 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { foo: 'bar' }); - done(); - }) - .catch(done); + const newStorage = await migration40.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + foo: 'bar', + }); }); - it('should do nothing if no ProviderApprovalController storage key', function (done) { + it('should do nothing if no ProviderApprovalController storage key', async () => { const oldStorage = { meta: {}, data: { foo: 'bar' }, }; - migration40 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { foo: 'bar' }); - done(); - }) - .catch(done); + const newStorage = await migration40.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + foo: 'bar', + }); }); }); diff --git a/app/scripts/migrations/041.test.js b/app/scripts/migrations/041.test.js index f1a06a151..9a4e74acd 100644 --- a/app/scripts/migrations/041.test.js +++ b/app/scripts/migrations/041.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration41 from './041'; -describe('migration #41', function () { - it('should update the version metadata', function (done) { +describe('migration #41', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 40, @@ -10,18 +9,11 @@ describe('migration #41', function () { data: {}, }; - migration41 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 41, - }); - done(); - }) - .catch(done); + const newStorage = await migration41.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(41); }); - it('should rename autoLogoutTimeLimit storage key', function (done) { + it('should rename autoLogoutTimeLimit storage key', async () => { const oldStorage = { meta: {}, data: { @@ -36,25 +28,20 @@ describe('migration #41', function () { }, }; - migration41 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - PreferencesController: { - preferences: { - autoLockTimeLimit: 42, - fizz: 'buzz', - }, - bar: 'baz', - }, - foo: 'bar', - }); - done(); - }) - .catch(done); + const newStorage = await migration41.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + PreferencesController: { + preferences: { + autoLockTimeLimit: 42, + fizz: 'buzz', + }, + bar: 'baz', + }, + foo: 'bar', + }); }); - it('should do nothing if no PreferencesController key', function (done) { + it('should do nothing if no PreferencesController key', async () => { const oldStorage = { meta: {}, data: { @@ -62,18 +49,13 @@ describe('migration #41', function () { }, }; - migration41 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - foo: 'bar', - }); - done(); - }) - .catch(done); + const newStorage = await migration41.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + foo: 'bar', + }); }); - it('should do nothing if no preferences key', function (done) { + it('should do nothing if no preferences key', async () => { const oldStorage = { meta: {}, data: { @@ -84,17 +66,12 @@ describe('migration #41', function () { }, }; - migration41 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - PreferencesController: { - bar: 'baz', - }, - foo: 'bar', - }); - done(); - }) - .catch(done); + const newStorage = await migration41.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + PreferencesController: { + bar: 'baz', + }, + foo: 'bar', + }); }); }); diff --git a/app/scripts/migrations/042.test.js b/app/scripts/migrations/042.test.js index 8c1a46513..4f18c3c30 100644 --- a/app/scripts/migrations/042.test.js +++ b/app/scripts/migrations/042.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration42 from './042'; -describe('migration #42', function () { - it('should update the version metadata', function (done) { +describe('migration #42', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 41, @@ -10,18 +9,11 @@ describe('migration #42', function () { data: {}, }; - migration42 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 42, - }); - done(); - }) - .catch(done); + const newStorage = await migration42.migrate(oldStorage); + expect(newStorage.meta.version).toStrictEqual(42); }); - it('should set connectedStatusPopoverHasBeenShown to false', function (done) { + it('should set connectedStatusPopoverHasBeenShown to false', async () => { const oldStorage = { meta: {}, data: { @@ -33,22 +25,17 @@ describe('migration #42', function () { }, }; - migration42 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - AppStateController: { - connectedStatusPopoverHasBeenShown: false, - bar: 'baz', - }, - foo: 'bar', - }); - done(); - }) - .catch(done); + const newStorage = await migration42.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + AppStateController: { + connectedStatusPopoverHasBeenShown: false, + bar: 'baz', + }, + foo: 'bar', + }); }); - it('should initialize AppStateController if it does not exist', function (done) { + it('should initialize AppStateController if it does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -56,17 +43,12 @@ describe('migration #42', function () { }, }; - migration42 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - foo: 'bar', - AppStateController: { - connectedStatusPopoverHasBeenShown: false, - }, - }); - done(); - }) - .catch(done); + const newStorage = await migration42.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + foo: 'bar', + AppStateController: { + connectedStatusPopoverHasBeenShown: false, + }, + }); }); }); diff --git a/app/scripts/migrations/043.test.js b/app/scripts/migrations/043.test.js index aa37f13d7..387cf8d25 100644 --- a/app/scripts/migrations/043.test.js +++ b/app/scripts/migrations/043.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration43 from './043'; -describe('migration #43', function () { - it('should update the version metadata', async function () { +describe('migration #43', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 42, @@ -11,12 +10,12 @@ describe('migration #43', function () { }; const newStorage = await migration43.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 43, }); }); - it('should delete currentAccountTab state', async function () { + it('should delete currentAccountTab state', async () => { const oldStorage = { meta: {}, data: { @@ -29,7 +28,7 @@ describe('migration #43', function () { }; const newStorage = await migration43.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { bar: 'baz', }, @@ -37,7 +36,7 @@ describe('migration #43', function () { }); }); - it('should do nothing if currentAccountTab state does not exist', async function () { + it('should do nothing if currentAccountTab state does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -49,6 +48,6 @@ describe('migration #43', function () { }; const newStorage = await migration43.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/044.test.js b/app/scripts/migrations/044.test.js index 35b95762d..8d8d8503a 100644 --- a/app/scripts/migrations/044.test.js +++ b/app/scripts/migrations/044.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration44 from './044'; -describe('migration #44', function () { - it('should update the version metadata', async function () { +describe('migration #44', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 43, @@ -11,12 +10,12 @@ describe('migration #44', function () { }; const newStorage = await migration44.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 44, }); }); - it('should delete mkrMigrationReminderTimestamp state', async function () { + it('should delete mkrMigrationReminderTimestamp state', async () => { const oldStorage = { meta: {}, data: { @@ -29,7 +28,7 @@ describe('migration #44', function () { }; const newStorage = await migration44.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ AppStateController: { bar: 'baz', }, @@ -37,7 +36,7 @@ describe('migration #44', function () { }); }); - it('should delete mkrMigrationReminderTimestamp state if it is null', async function () { + it('should delete mkrMigrationReminderTimestamp state if it is null', async () => { const oldStorage = { meta: {}, data: { @@ -50,7 +49,7 @@ describe('migration #44', function () { }; const newStorage = await migration44.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ AppStateController: { bar: 'baz', }, @@ -58,7 +57,7 @@ describe('migration #44', function () { }); }); - it('should do nothing if mkrMigrationReminderTimestamp state does not exist', async function () { + it('should do nothing if mkrMigrationReminderTimestamp state does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -70,6 +69,6 @@ describe('migration #44', function () { }; const newStorage = await migration44.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/045.test.js b/app/scripts/migrations/045.test.js index de47bef32..f8e819c50 100644 --- a/app/scripts/migrations/045.test.js +++ b/app/scripts/migrations/045.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration45 from './045'; -describe('migration #45', function () { - it('should update the version metadata', function (done) { +describe('migration #45', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 44, @@ -10,18 +9,13 @@ describe('migration #45', function () { data: {}, }; - migration45 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.meta, { - version: 45, - }); - done(); - }) - .catch(done); + const newStorage = await migration45.migrate(oldStorage); + expect(newStorage.meta).toStrictEqual({ + version: 45, + }); }); - it('should update ipfsGateway value if outdated', function (done) { + it('should update ipfsGateway value if outdated', async () => { const oldStorage = { meta: {}, data: { @@ -33,22 +27,17 @@ describe('migration #45', function () { }, }; - migration45 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - PreferencesController: { - ipfsGateway: 'dweb.link', - bar: 'baz', - }, - foo: 'bar', - }); - done(); - }) - .catch(done); + const newStorage = await migration45.migrate(oldStorage); + expect(newStorage.data).toStrictEqual({ + PreferencesController: { + ipfsGateway: 'dweb.link', + bar: 'baz', + }, + foo: 'bar', + }); }); - it('should not update ipfsGateway value if custom set', function (done) { + it('should not update ipfsGateway value if custom set', async () => { const oldStorage = { meta: {}, data: { @@ -60,22 +49,18 @@ describe('migration #45', function () { }, }; - migration45 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - PreferencesController: { - ipfsGateway: 'blah', - bar: 'baz', - }, - foo: 'bar', - }); - done(); - }) - .catch(done); + const newStorage = await migration45.migrate(oldStorage); + + expect(newStorage.data).toStrictEqual({ + PreferencesController: { + ipfsGateway: 'blah', + bar: 'baz', + }, + foo: 'bar', + }); }); - it('should do nothing if no PreferencesController key', function (done) { + it('should do nothing if no PreferencesController key', async () => { const oldStorage = { meta: {}, data: { @@ -83,14 +68,10 @@ describe('migration #45', function () { }, }; - migration45 - .migrate(oldStorage) - .then((newStorage) => { - assert.deepEqual(newStorage.data, { - foo: 'bar', - }); - done(); - }) - .catch(done); + const newStorage = await migration45.migrate(oldStorage); + + expect(newStorage.data).toStrictEqual({ + foo: 'bar', + }); }); }); diff --git a/app/scripts/migrations/046.test.js b/app/scripts/migrations/046.test.js index 05e3b93dd..8c18950c1 100644 --- a/app/scripts/migrations/046.test.js +++ b/app/scripts/migrations/046.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration46 from './046'; -describe('migration #46', function () { - it('should update the version metadata', async function () { +describe('migration #46', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 45, @@ -11,12 +10,12 @@ describe('migration #46', function () { }; const newStorage = await migration46.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 46, }); }); - it('should delete ABTestController state', async function () { + it('should delete ABTestController state', async () => { const oldStorage = { meta: {}, data: { @@ -30,12 +29,12 @@ describe('migration #46', function () { }; const newStorage = await migration46.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ foo: 'bar', }); }); - it('should do nothing if ABTestController state does not exist', async function () { + it('should do nothing if ABTestController state does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -47,6 +46,6 @@ describe('migration #46', function () { }; const newStorage = await migration46.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/047.test.js b/app/scripts/migrations/047.test.js index 7124a274c..8285d3a2b 100644 --- a/app/scripts/migrations/047.test.js +++ b/app/scripts/migrations/047.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration47 from './047'; -describe('migration #47', function () { - it('should update the version metadata', async function () { +describe('migration #47', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 46, @@ -11,12 +10,12 @@ describe('migration #47', function () { }; const newStorage = await migration47.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 47, }); }); - it('should stringify transactions metamaskNetworkId values', async function () { + it('should stringify transactions metamaskNetworkId values', async () => { const oldStorage = { meta: {}, data: { @@ -33,7 +32,7 @@ describe('migration #47', function () { }; const newStorage = await migration47.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: [ { foo: 'bar', metamaskNetworkId: '2' }, @@ -46,7 +45,7 @@ describe('migration #47', function () { }); }); - it('should do nothing if transactions metamaskNetworkId values are already strings', async function () { + it('should do nothing if transactions metamaskNetworkId values are already strings', async () => { const oldStorage = { meta: {}, data: { @@ -63,10 +62,10 @@ describe('migration #47', function () { }; const newStorage = await migration47.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); - it('should do nothing if transactions state does not exist', async function () { + it('should do nothing if transactions state does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -78,10 +77,10 @@ describe('migration #47', function () { }; const newStorage = await migration47.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); - it('should do nothing if transactions state is empty', async function () { + it('should do nothing if transactions state is empty', async () => { const oldStorage = { meta: {}, data: { @@ -94,16 +93,16 @@ describe('migration #47', function () { }; const newStorage = await migration47.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); - it('should do nothing if state is empty', async function () { + it('should do nothing if state is empty', async () => { const oldStorage = { meta: {}, data: {}, }; const newStorage = await migration47.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/048.test.js b/app/scripts/migrations/048.test.js index 0b02a814b..881d4abd7 100644 --- a/app/scripts/migrations/048.test.js +++ b/app/scripts/migrations/048.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import migration48 from './048'; const localhostNetwork = { @@ -18,8 +17,8 @@ const expectedPreferencesState = { }, }; -describe('migration #48', function () { - it('should update the version metadata', async function () { +describe('migration #48', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 47, @@ -28,12 +27,12 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 48, }); }); - it('should delete NetworkController.settings', async function () { + it('should delete NetworkController.settings', async () => { const oldStorage = { meta: {}, data: { @@ -50,7 +49,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, NetworkController: { provider: { @@ -61,7 +60,7 @@ describe('migration #48', function () { }); }); - it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (1)', async function () { + it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (1)', async () => { const oldStorage = { meta: {}, data: { @@ -78,7 +77,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, NetworkController: { provider: { @@ -95,7 +94,7 @@ describe('migration #48', function () { }); }); - it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (2)', async function () { + it('should migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is invalid (2)', async () => { const oldStorage = { meta: {}, data: { @@ -112,7 +111,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, NetworkController: { provider: { @@ -129,7 +128,7 @@ describe('migration #48', function () { }); }); - it('should not migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is valid', async function () { + it('should not migrate NetworkController.provider to Rinkeby if the type is "rpc" and the chainId is valid', async () => { const oldStorage = { meta: {}, data: { @@ -146,7 +145,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, NetworkController: { provider: { @@ -160,7 +159,7 @@ describe('migration #48', function () { }); }); - it('should migrate NetworkController.provider to Rinkeby if the type is "localhost"', async function () { + it('should migrate NetworkController.provider to Rinkeby if the type is "localhost"', async () => { const oldStorage = { meta: {}, data: { @@ -176,7 +175,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, NetworkController: { provider: { @@ -193,7 +192,7 @@ describe('migration #48', function () { }); }); - it('should re-key NetworkController.provider.rpcTarget to rpcUrl if the type is not "rpc" or "localhost"', async function () { + it('should re-key NetworkController.provider.rpcTarget to rpcUrl if the type is not "rpc" or "localhost"', async () => { const oldStorage = { meta: {}, data: { @@ -210,7 +209,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, NetworkController: { foo: 'bar', @@ -224,7 +223,7 @@ describe('migration #48', function () { }); }); - it('should do nothing to NetworkController if affected state does not exist', async function () { + it('should do nothing to NetworkController if affected state does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -238,13 +237,13 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual( - { ...expectedPreferencesState, ...oldStorage.data }, - { ...expectedPreferencesState, ...newStorage.data }, - ); + expect({ ...expectedPreferencesState, ...oldStorage.data }).toStrictEqual({ + ...expectedPreferencesState, + ...newStorage.data, + }); }); - it('should add frequentRpcListDetail item to beginning of list', async function () { + it('should add frequentRpcListDetail item to beginning of list', async () => { const existingList = [ { rpcUrl: 'foo', chainId: '0x1' }, { rpcUrl: 'bar', chainId: '0x2' }, @@ -261,7 +260,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { frequentRpcListDetail: [{ ...localhostNetwork }, ...existingList], }, @@ -269,7 +268,7 @@ describe('migration #48', function () { }); }); - it('should delete CachedBalancesController.cachedBalances', async function () { + it('should delete CachedBalancesController.cachedBalances', async () => { const oldStorage = { meta: {}, data: { @@ -286,7 +285,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, CachedBalancesController: { bar: { @@ -297,7 +296,7 @@ describe('migration #48', function () { }); }); - it('should convert hex transaction metamaskNetworkId values to decimal', async function () { + it('should convert hex transaction metamaskNetworkId values to decimal', async () => { const oldStorage = { meta: {}, data: { @@ -323,7 +322,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, TransactionController: { transactions: [ @@ -346,7 +345,7 @@ describe('migration #48', function () { }); }); - it('should migrate the address book', async function () { + it('should migrate the address book', async () => { const oldStorage = { meta: {}, data: { @@ -380,7 +379,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, AddressBookController: { addressBook: { @@ -411,7 +410,7 @@ describe('migration #48', function () { }); }); - it('should migrate the address book and merge entries', async function () { + it('should migrate the address book and merge entries', async () => { const oldStorage = { meta: {}, data: { @@ -452,7 +451,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, AddressBookController: { addressBook: { @@ -483,7 +482,7 @@ describe('migration #48', function () { }); }); - it('should not modify address book if all entries are valid or un-parseable', async function () { + it('should not modify address book if all entries are valid or un-parseable', async () => { const oldStorage = { meta: {}, data: { @@ -501,7 +500,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, AddressBookController: { addressBook: { @@ -516,7 +515,7 @@ describe('migration #48', function () { }); }); - it('should delete localhost key in IncomingTransactionsController', async function () { + it('should delete localhost key in IncomingTransactionsController', async () => { const oldStorage = { meta: {}, data: { @@ -532,7 +531,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, IncomingTransactionsController: { incomingTxLastFetchedBlocksByNetwork: { @@ -544,7 +543,7 @@ describe('migration #48', function () { }); }); - it('should not modify IncomingTransactionsController state if affected key is missing', async function () { + it('should not modify IncomingTransactionsController state if affected key is missing', async () => { const oldStorage = { meta: {}, data: { @@ -560,7 +559,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ ...expectedPreferencesState, IncomingTransactionsController: { incomingTxLastFetchedBlocksByNetwork: { @@ -573,7 +572,7 @@ describe('migration #48', function () { }); }); - it('should merge localhost token list into rpc token list', async function () { + it('should merge localhost token list into rpc token list', async () => { const oldStorage = { meta: {}, data: { @@ -604,7 +603,7 @@ describe('migration #48', function () { }; const newStorage = await migration48.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountTokens: { address1: { diff --git a/app/scripts/migrations/049.test.js b/app/scripts/migrations/049.test.js index f3c89d66b..f6be8f5db 100644 --- a/app/scripts/migrations/049.test.js +++ b/app/scripts/migrations/049.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration49 from './049'; -describe('migration #49', function () { - it('should update the version metadata', async function () { +describe('migration #49', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 48, @@ -11,12 +10,12 @@ describe('migration #49', function () { }; const newStorage = await migration49.migrate(oldStorage); - assert.deepStrictEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 49, }); }); - it('should move metaMetricsId to MetaMetricsController', async function () { + it('should move metaMetricsId to MetaMetricsController', async () => { const oldStorage = { meta: {}, data: { @@ -29,7 +28,7 @@ describe('migration #49', function () { }; const newStorage = await migration49.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { bar: 'baz', }, @@ -40,7 +39,7 @@ describe('migration #49', function () { }); }); - it('should move participateInMetaMetrics to MetaMetricsController', async function () { + it('should move participateInMetaMetrics to MetaMetricsController', async () => { const oldStorage = { meta: {}, data: { @@ -53,7 +52,7 @@ describe('migration #49', function () { }; const newStorage = await migration49.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { bar: 'baz', }, @@ -64,7 +63,7 @@ describe('migration #49', function () { }); }); - it('should move metaMetricsSendCount to MetaMetricsController', async function () { + it('should move metaMetricsSendCount to MetaMetricsController', async () => { const oldStorage = { meta: {}, data: { @@ -77,7 +76,7 @@ describe('migration #49', function () { }; const newStorage = await migration49.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { bar: 'baz', }, @@ -88,7 +87,7 @@ describe('migration #49', function () { }); }); - it('should move all metaMetrics fields to MetaMetricsController', async function () { + it('should move all metaMetrics fields to MetaMetricsController', async () => { const oldStorage = { meta: {}, data: { @@ -103,7 +102,7 @@ describe('migration #49', function () { }; const newStorage = await migration49.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { bar: 'baz', }, @@ -116,7 +115,7 @@ describe('migration #49', function () { }); }); - it('should do nothing if no PreferencesController key', async function () { + it('should do nothing if no PreferencesController key', async () => { const oldStorage = { meta: {}, data: { @@ -125,7 +124,7 @@ describe('migration #49', function () { }; const newStorage = await migration49.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ foo: 'bar', }); }); diff --git a/app/scripts/migrations/050.test.js b/app/scripts/migrations/050.test.js index fd942ee87..83d585dca 100644 --- a/app/scripts/migrations/050.test.js +++ b/app/scripts/migrations/050.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import sinon from 'sinon'; import migration50 from './050'; @@ -14,18 +13,21 @@ const LEGACY_LOCAL_STORAGE_KEYS = [ 'GAS_API_ESTIMATES', ]; -describe('migration #50', function () { +describe('migration #50', () => { let mockLocalStorageRemoveItem; - beforeEach(function () { - mockLocalStorageRemoveItem = sinon.stub(window.localStorage, 'removeItem'); + beforeEach(() => { + mockLocalStorageRemoveItem = jest + // eslint-disable-next-line no-undef + .spyOn(Storage.prototype, 'removeItem') + .mockImplementation(); }); - afterEach(function () { + afterEach(() => { sinon.restore(); }); - it('should update the version metadata', async function () { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 49, @@ -34,12 +36,12 @@ describe('migration #50', function () { }; const newStorage = await migration50.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 50, }); }); - it('should call window.localStorage.removeItem for each legacy key', async function () { + it('should call window.localStorage.removeItem for each legacy key', async () => { const oldStorage = { meta: { version: 49, @@ -48,41 +50,32 @@ describe('migration #50', function () { }; await migration50.migrate(oldStorage); - assert.equal(mockLocalStorageRemoveItem.callCount, 9); - assert.equal( - mockLocalStorageRemoveItem.getCall(0).args[0], + expect(mockLocalStorageRemoveItem.mock.calls).toHaveLength(9); + expect(mockLocalStorageRemoveItem.mock.calls[0][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[0], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(1).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[1][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[1], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(2).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[2][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[2], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(3).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[3][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[3], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(4).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[4][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[4], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(5).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[5][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[5], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(6).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[6][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[6], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(7).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[7][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[7], ); - assert.equal( - mockLocalStorageRemoveItem.getCall(8).args[0], + expect(mockLocalStorageRemoveItem.mock.calls[8][0]).toStrictEqual( LEGACY_LOCAL_STORAGE_KEYS[8], ); }); diff --git a/app/scripts/migrations/051.test.js b/app/scripts/migrations/051.test.js index 8d32fbf2c..6dab2c0e3 100644 --- a/app/scripts/migrations/051.test.js +++ b/app/scripts/migrations/051.test.js @@ -1,12 +1,11 @@ -import { strict as assert } from 'assert'; import { INFURA_PROVIDER_TYPES, NETWORK_TYPE_TO_ID_MAP, } from '../../../shared/constants/network'; import migration51 from './051'; -describe('migration #51', function () { - it('should update the version metadata', async function () { +describe('migration #51', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 50, @@ -15,14 +14,14 @@ describe('migration #51', function () { }; const newStorage = await migration51.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 51, }); }); - describe('setting chainId', function () { + describe('setting chainId', () => { INFURA_PROVIDER_TYPES.forEach(function (type) { - it(`should correctly set the chainId for the Infura network "${type}", if no chainId is set`, async function () { + it(`should correctly set the chainId for the Infura network "${type}", if no chainId is set`, async () => { const oldStorage = { meta: {}, data: { @@ -38,7 +37,7 @@ describe('migration #51', function () { }, }; const newStorage = await migration51.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ NetworkController: { settings: { fizz: 'buzz', @@ -52,7 +51,7 @@ describe('migration #51', function () { }); }); - it(`should correctly set the chainId for the Infura network "${type}", if an incorrect chainId is set`, async function () { + it(`should correctly set the chainId for the Infura network "${type}", if an incorrect chainId is set`, async () => { const oldStorage = { meta: {}, data: { @@ -69,7 +68,7 @@ describe('migration #51', function () { }, }; const newStorage = await migration51.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ NetworkController: { settings: { fizz: 'buzz', @@ -84,7 +83,7 @@ describe('migration #51', function () { }); }); - it('should not set the chainId for a non-Infura network that does not have chainId set', async function () { + it('should not set the chainId for a non-Infura network that does not have chainId set', async () => { const oldStorage = { meta: {}, data: { @@ -99,10 +98,10 @@ describe('migration #51', function () { }, }; const newStorage = await migration51.migrate(oldStorage); - assert.deepEqual(newStorage.data, oldStorage.data); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); - it('should not set the chainId for a non-Infura network that does have chainId set', async function () { + it('should not set the chainId for a non-Infura network that does have chainId set', async () => { const oldStorage = { meta: {}, data: { @@ -118,7 +117,7 @@ describe('migration #51', function () { }, }; const newStorage = await migration51.migrate(oldStorage); - assert.deepEqual(newStorage.data, oldStorage.data); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); }); }); diff --git a/app/scripts/migrations/052.test.js b/app/scripts/migrations/052.test.js index 3896d0a77..1a78374cb 100644 --- a/app/scripts/migrations/052.test.js +++ b/app/scripts/migrations/052.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import { GOERLI, GOERLI_CHAIN_ID, @@ -19,8 +18,8 @@ const TOKEN2 = { symbol: 'TXT', address: '0x11', decimals: 18 }; const TOKEN3 = { symbol: 'TVT', address: '0x12', decimals: 18 }; const TOKEN4 = { symbol: 'TAT', address: '0x13', decimals: 18 }; -describe('migration #52', function () { - it('should update the version metadata', async function () { +describe('migration #52', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 52, @@ -29,12 +28,12 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 52, }); }); - it(`should move ${MAINNET} tokens and hidden tokens to be keyed by ${MAINNET_CHAIN_ID} for each address`, async function () { + it(`should move ${MAINNET} tokens and hidden tokens to be keyed by ${MAINNET_CHAIN_ID} for each address`, async () => { const oldStorage = { meta: {}, data: { @@ -62,7 +61,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountHiddenTokens: { '0x1111': { @@ -86,7 +85,7 @@ describe('migration #52', function () { }); }); - it(`should move ${RINKEBY} tokens and hidden tokens to be keyed by ${RINKEBY_CHAIN_ID} for each address`, async function () { + it(`should move ${RINKEBY} tokens and hidden tokens to be keyed by ${RINKEBY_CHAIN_ID} for each address`, async () => { const oldStorage = { meta: {}, data: { @@ -114,7 +113,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountHiddenTokens: { '0x1111': { @@ -138,7 +137,7 @@ describe('migration #52', function () { }); }); - it(`should move ${KOVAN} tokens and hidden tokens to be keyed by ${KOVAN_CHAIN_ID} for each address`, async function () { + it(`should move ${KOVAN} tokens and hidden tokens to be keyed by ${KOVAN_CHAIN_ID} for each address`, async () => { const oldStorage = { meta: {}, data: { @@ -166,7 +165,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountHiddenTokens: { '0x1111': { @@ -190,7 +189,7 @@ describe('migration #52', function () { }); }); - it(`should move ${GOERLI} tokens and hidden tokens to be keyed by ${GOERLI_CHAIN_ID} for each address`, async function () { + it(`should move ${GOERLI} tokens and hidden tokens to be keyed by ${GOERLI_CHAIN_ID} for each address`, async () => { const oldStorage = { meta: {}, data: { @@ -218,7 +217,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountHiddenTokens: { '0x1111': { @@ -242,7 +241,7 @@ describe('migration #52', function () { }); }); - it(`should move ${ROPSTEN} tokens and hidden tokens to be keyed by ${ROPSTEN_CHAIN_ID} for each address`, async function () { + it(`should move ${ROPSTEN} tokens and hidden tokens to be keyed by ${ROPSTEN_CHAIN_ID} for each address`, async () => { const oldStorage = { meta: {}, data: { @@ -270,7 +269,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountHiddenTokens: { '0x1111': { @@ -294,7 +293,7 @@ describe('migration #52', function () { }); }); - it(`should duplicate ${NETWORK_TYPE_RPC} tokens and hidden tokens to all custom networks for each address`, async function () { + it(`should duplicate ${NETWORK_TYPE_RPC} tokens and hidden tokens to all custom networks for each address`, async () => { const oldStorage = { meta: {}, data: { @@ -327,7 +326,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { frequentRpcListDetail: [ { chainId: '0xab' }, @@ -364,7 +363,7 @@ describe('migration #52', function () { }); }); - it(`should overwrite ${NETWORK_TYPE_RPC} tokens with built in networks if chainIds match`, async function () { + it(`should overwrite ${NETWORK_TYPE_RPC} tokens with built in networks if chainIds match`, async () => { const oldStorage = { meta: {}, data: { @@ -389,7 +388,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { frequentRpcListDetail: [{ chainId: '0x1' }], accountHiddenTokens: { @@ -408,7 +407,7 @@ describe('migration #52', function () { }); }); - it('should do nothing if no PreferencesController key', async function () { + it('should do nothing if no PreferencesController key', async () => { const oldStorage = { meta: {}, data: { @@ -417,7 +416,7 @@ describe('migration #52', function () { }; const newStorage = await migration52.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ foo: 'bar', }); }); diff --git a/app/scripts/migrations/053.test.js b/app/scripts/migrations/053.test.js index 324fa3741..e8f4651a9 100644 --- a/app/scripts/migrations/053.test.js +++ b/app/scripts/migrations/053.test.js @@ -1,11 +1,10 @@ -import { strict as assert } from 'assert'; import { TRANSACTION_TYPES } from '../../../shared/constants/transaction'; import migration53 from './053'; const SENT_ETHER = 'sentEther'; // a legacy transaction type replaced now by TRANSACTION_TYPES.SIMPLE_SEND -describe('migration #53', function () { - it('should update the version metadata', async function () { +describe('migration #53', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 52, @@ -14,12 +13,12 @@ describe('migration #53', function () { }; const newStorage = await migration53.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 53, }); }); - it('should update type of standard transactions', async function () { + it('should update type of standard transactions', async () => { const oldStorage = { meta: {}, data: { @@ -62,7 +61,7 @@ describe('migration #53', function () { }; const newStorage = await migration53.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: [ { type: TRANSACTION_TYPES.CANCEL, txParams: { foo: 'bar' } }, @@ -91,7 +90,7 @@ describe('migration #53', function () { }); }); - it('should do nothing if transactions state does not exist', async function () { + it('should do nothing if transactions state does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -106,10 +105,10 @@ describe('migration #53', function () { }; const newStorage = await migration53.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); - it('should do nothing if transactions state is empty', async function () { + it('should do nothing if transactions state is empty', async () => { const oldStorage = { meta: {}, data: { @@ -126,16 +125,16 @@ describe('migration #53', function () { }; const newStorage = await migration53.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); - it('should do nothing if state is empty', async function () { + it('should do nothing if state is empty', async () => { const oldStorage = { meta: {}, data: {}, }; const newStorage = await migration53.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/054.test.js b/app/scripts/migrations/054.test.js index b0d78bcfd..0e7cde9ae 100644 --- a/app/scripts/migrations/054.test.js +++ b/app/scripts/migrations/054.test.js @@ -1,12 +1,11 @@ -import { strict as assert } from 'assert'; import { MAINNET_CHAIN_ID, ROPSTEN_CHAIN_ID, } from '../../../shared/constants/network'; import migration54 from './054'; -describe('migration #54', function () { - it('should update the version metadata', async function () { +describe('migration #54', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 53, @@ -15,12 +14,12 @@ describe('migration #54', function () { }; const newStorage = await migration54.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 54, }); }); - it('should retype instance of 0 decimal values to numbers [tokens]', async function () { + it('should retype instance of 0 decimal values to numbers [tokens]', async () => { const oldStorage = { meta: {}, data: { @@ -53,7 +52,7 @@ describe('migration #54', function () { }; const newStorage = await migration54.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { tokens: [ { @@ -82,7 +81,7 @@ describe('migration #54', function () { }); }); - it('should do nothing if all decimal value typings are correct [tokens]', async function () { + it('should do nothing if all decimal value typings are correct [tokens]', async () => { const oldStorage = { meta: {}, data: { @@ -115,7 +114,7 @@ describe('migration #54', function () { }; const newStorage = await migration54.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { tokens: [ { @@ -144,7 +143,7 @@ describe('migration #54', function () { }); }); - it('should retype instance of 0 decimal values to numbers [accountTokens]', async function () { + it('should retype instance of 0 decimal values to numbers [accountTokens]', async () => { const oldStorage = { meta: {}, data: { @@ -205,7 +204,7 @@ describe('migration #54', function () { }; const newStorage = await migration54.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountTokens: { '0x1111': { @@ -262,7 +261,7 @@ describe('migration #54', function () { }); }); - it('should do nothing if all decimal value typings are correct [accountTokens]', async function () { + it('should do nothing if all decimal value typings are correct [accountTokens]', async () => { const oldStorage = { meta: {}, data: { @@ -323,7 +322,7 @@ describe('migration #54', function () { }; const newStorage = await migration54.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountTokens: { '0x1111': { @@ -380,7 +379,7 @@ describe('migration #54', function () { }); }); - it('should retype instance of 0 decimal values to numbers [accountTokens and tokens]', async function () { + it('should retype instance of 0 decimal values to numbers [accountTokens and tokens]', async () => { const oldStorage = { meta: {}, data: { @@ -462,7 +461,7 @@ describe('migration #54', function () { }; const newStorage = await migration54.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountTokens: { '0x1111': { @@ -540,7 +539,7 @@ describe('migration #54', function () { }); }); - it('should retype instance of 0 decimal values to numbers, and remove tokens with corrupted decimal values [accountTokens and tokens]', async function () { + it('should retype instance of 0 decimal values to numbers, and remove tokens with corrupted decimal values [accountTokens and tokens]', async () => { const oldStorage = { meta: {}, data: { @@ -622,7 +621,7 @@ describe('migration #54', function () { }; const newStorage = await migration54.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { accountTokens: { '0x1111': { diff --git a/app/scripts/migrations/055.test.js b/app/scripts/migrations/055.test.js index 449c6291f..a481579b4 100644 --- a/app/scripts/migrations/055.test.js +++ b/app/scripts/migrations/055.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import { GOERLI, GOERLI_CHAIN_ID, @@ -13,8 +12,8 @@ import { } from '../../../shared/constants/network'; import migration55 from './055'; -describe('migration #55', function () { - it('should update the version metadata', async function () { +describe('migration #55', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 54, @@ -23,12 +22,12 @@ describe('migration #55', function () { }; const newStorage = await migration55.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 55, }); }); - it('should replace incomingTxLastFetchedBlocksByNetwork with incomingTxLastFetchedBlockByChainId, and carry over old values', async function () { + it('should replace incomingTxLastFetchedBlocksByNetwork with incomingTxLastFetchedBlockByChainId, and carry over old values', async () => { const oldStorage = { meta: {}, data: { @@ -54,7 +53,7 @@ describe('migration #55', function () { }; const newStorage = await migration55.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ IncomingTransactionsController: { incomingTransactions: oldStorage.data.IncomingTransactionsController.incomingTransactions, @@ -70,7 +69,7 @@ describe('migration #55', function () { }); }); - it('should do nothing if incomingTxLastFetchedBlocksByNetwork key is not populated', async function () { + it('should do nothing if incomingTxLastFetchedBlocksByNetwork key is not populated', async () => { const oldStorage = { meta: {}, data: { @@ -82,15 +81,15 @@ describe('migration #55', function () { }; const newStorage = await migration55.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); - it('should do nothing if state is empty', async function () { + it('should do nothing if state is empty', async () => { const oldStorage = { meta: {}, data: {}, }; const newStorage = await migration55.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/056.test.js b/app/scripts/migrations/056.test.js index 927997fbe..3ea04ece6 100644 --- a/app/scripts/migrations/056.test.js +++ b/app/scripts/migrations/056.test.js @@ -1,12 +1,11 @@ -import { strict as assert } from 'assert'; import migration56 from './056'; const BAD_TOKEN_DATA = { symbol: null, decimals: null }; const TOKEN2 = { symbol: 'TXT', address: '0x11', decimals: 18 }; const TOKEN3 = { symbol: 'TVT', address: '0x12', decimals: 18 }; -describe('migration #56', function () { - it('should update the version metadata', async function () { +describe('migration #56', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 55, @@ -21,12 +20,12 @@ describe('migration #56', function () { }; const newStorage = await migration56.migrate(oldStorage); - assert.deepStrictEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 56, }); }); - it(`should filter out tokens without a valid address property`, async function () { + it(`should filter out tokens without a valid address property`, async () => { const oldStorage = { meta: {}, data: { @@ -39,13 +38,13 @@ describe('migration #56', function () { }; const newStorage = await migration56.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data.PreferencesController.tokens, [ + expect(newStorage.data.PreferencesController.tokens).toStrictEqual([ TOKEN2, TOKEN3, ]); }); - it(`should not filter any tokens when all token information is valid`, async function () { + it(`should not filter any tokens when all token information is valid`, async () => { const oldStorage = { meta: {}, data: { @@ -58,13 +57,13 @@ describe('migration #56', function () { }; const newStorage = await migration56.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data.PreferencesController.tokens, [ + expect(newStorage.data.PreferencesController.tokens).toStrictEqual([ TOKEN2, TOKEN3, ]); }); - it(`should filter out accountTokens without a valid address property`, async function () { + it(`should filter out accountTokens without a valid address property`, async () => { const originalAccountTokens = { '0x1111111111111111111111111': { '0x1': [TOKEN2, TOKEN3, BAD_TOKEN_DATA], @@ -98,13 +97,12 @@ describe('migration #56', function () { desiredResult['0x1111111111111111111111111']['0x4'] = []; desiredResult['0x1111111111111111111111112']['0x4'] = []; - assert.deepStrictEqual( - newStorage.data.PreferencesController.accountTokens, + expect(newStorage.data.PreferencesController.accountTokens).toStrictEqual( desiredResult, ); }); - it(`should remove a bad assetImages key`, async function () { + it(`should remove a bad assetImages key`, async () => { const desiredAssetImages = { '0x514910771af9ca656af840dff83e8264ecf986ca': 'images/contract/chainlink.svg', @@ -121,13 +119,12 @@ describe('migration #56', function () { }; const newStorage = await migration56.migrate(oldStorage); - assert.deepStrictEqual( - newStorage.data.PreferencesController.assetImages, + expect(newStorage.data.PreferencesController.assetImages).toStrictEqual( desiredAssetImages, ); }); - it(`token data with no problems should preserve all data`, async function () { + it(`token data with no problems should preserve all data`, async () => { const perfectData = { tokens: [TOKEN2, TOKEN3], accountTokens: { @@ -150,6 +147,6 @@ describe('migration #56', function () { }; const newStorage = await migration56.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data.PreferencesController, perfectData); + expect(newStorage.data.PreferencesController).toStrictEqual(perfectData); }); }); diff --git a/app/scripts/migrations/057.test.js b/app/scripts/migrations/057.test.js index 825a78993..6a40ae9c3 100644 --- a/app/scripts/migrations/057.test.js +++ b/app/scripts/migrations/057.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration57 from './057'; -describe('migration #57', function () { - it('should update the version metadata', async function () { +describe('migration #57', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 56, @@ -11,12 +10,12 @@ describe('migration #57', function () { }; const newStorage = await migration57.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 57, }); }); - it('should transactions array into an object keyed by id', async function () { + it('should transactions array into an object keyed by id', async () => { const oldStorage = { meta: {}, data: { @@ -45,7 +44,7 @@ describe('migration #57', function () { }; const newStorage = await migration57.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: { 0: { @@ -67,7 +66,7 @@ describe('migration #57', function () { }); }); - it('should handle transactions without an id, just in case', async function () { + it('should handle transactions without an id, just in case', async () => { const oldStorage = { meta: {}, data: { @@ -98,24 +97,22 @@ describe('migration #57', function () { newStorage.data.TransactionController.transactions, )) { // Make sure each transaction now has an id. - assert.ok( - typeof transaction.id !== 'undefined', - 'transaction id is undefined', - ); + expect(typeof transaction.id !== 'undefined').toStrictEqual(true); // Build expected transaction object expectedTransactions[transaction.id] = transaction; } // Ensure that we got the correct number of transactions - assert.equal( - Object.keys(expectedTransactions).length, + expect(Object.keys(expectedTransactions)).toHaveLength( oldStorage.data.TransactionController.transactions.length, ); // Ensure that the one transaction with id is preserved, even though it is // a falsy id. - assert.equal(newStorage.data.TransactionController.transactions[0].id, 0); + expect( + newStorage.data.TransactionController.transactions[0].id, + ).toStrictEqual(0); }); - it('should not blow up if transactions are not an array', async function () { + it('should not blow up if transactions are not an array', async () => { const storageWithTransactionsAsString = { meta: {}, data: { @@ -140,11 +137,13 @@ describe('migration #57', function () { storageWithTransactionsAsArrayOfString, ); - assert.deepEqual(storageWithTransactionsAsString.data, result1.data); - assert.deepEqual(storageWithTransactionsAsArrayOfString.data, result2.data); + expect(storageWithTransactionsAsString.data).toStrictEqual(result1.data); + expect(storageWithTransactionsAsArrayOfString.data).toStrictEqual( + result2.data, + ); }); - it('should do nothing if transactions state does not exist', async function () { + it('should do nothing if transactions state does not exist', async () => { const oldStorage = { meta: {}, data: { @@ -156,10 +155,10 @@ describe('migration #57', function () { }; const newStorage = await migration57.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); - it('should convert empty array into empty object', async function () { + it('should convert empty array into empty object', async () => { const oldStorage = { meta: {}, data: { @@ -172,7 +171,7 @@ describe('migration #57', function () { }; const newStorage = await migration57.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: {}, bar: 'baz', @@ -181,13 +180,13 @@ describe('migration #57', function () { }); }); - it('should do nothing if state is empty', async function () { + it('should do nothing if state is empty', async () => { const oldStorage = { meta: {}, data: {}, }; const newStorage = await migration57.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/058.test.js b/app/scripts/migrations/058.test.js index 02efdcdd7..35a98f3fc 100644 --- a/app/scripts/migrations/058.test.js +++ b/app/scripts/migrations/058.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import migration58 from './058'; describe('migration #58', function () { @@ -11,7 +10,7 @@ describe('migration #58', function () { }; const newStorage = await migration58.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 58, }); }); @@ -29,7 +28,7 @@ describe('migration #58', function () { }, }; const newStorage = await migration58.migrate(oldStorage); - assert.deepEqual(newStorage.data.AppStateController, { bar: 'baz' }); + expect(newStorage.data.AppStateController).toStrictEqual({ bar: 'baz' }); }); it('should not modify state if the AppStateController does not exist', async function () { @@ -40,7 +39,7 @@ describe('migration #58', function () { }, }; const newStorage = await migration58.migrate(oldStorage); - assert.deepEqual(newStorage.data, oldStorage.data); + expect(newStorage.data).toStrictEqual(oldStorage.data); }); }); }); diff --git a/app/scripts/migrations/059.test.js b/app/scripts/migrations/059.test.js index a9a06c2fd..f7fd23e5d 100644 --- a/app/scripts/migrations/059.test.js +++ b/app/scripts/migrations/059.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import { cloneDeep } from 'lodash'; import { KOVAN_CHAIN_ID, @@ -133,7 +132,7 @@ describe('migration #59', function () { }; const newStorage = await migration59.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 59, }); }); @@ -152,7 +151,7 @@ describe('migration #59', function () { const newStorage = await migration59.migrate(oldStorage); const EXPECTED = cloneDeep(ERRONEOUS_TRANSACTION_STATE); delete EXPECTED['0']; - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: EXPECTED, }, @@ -184,7 +183,7 @@ describe('migration #59', function () { oldStorage.data.TransactionController.transactions, ); delete EXPECTED['0']; - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: EXPECTED, }, @@ -211,7 +210,7 @@ describe('migration #59', function () { }; const newStorage = await migration59.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: oldStorage.data.TransactionController.transactions, }, @@ -233,7 +232,7 @@ describe('migration #59', function () { const newStorage = await migration59.migrate(oldStorage); const EXPECTED = cloneDeep(ERRONEOUS_TRANSACTION_STATE_RETRY); delete EXPECTED['0']; - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: EXPECTED, }, @@ -265,7 +264,7 @@ describe('migration #59', function () { oldStorage.data.TransactionController.transactions, ); delete EXPECTED['0']; - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: EXPECTED, }, @@ -292,7 +291,7 @@ describe('migration #59', function () { }; const newStorage = await migration59.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: oldStorage.data.TransactionController.transactions, }, @@ -317,7 +316,7 @@ describe('migration #59', function () { // transactions we expect to be missing. const EXPECTED = cloneDeep(ERRONEOUS_TRANSACTION_STATE); delete EXPECTED['0']; - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TransactionController: { transactions: EXPECTED, }, @@ -340,7 +339,7 @@ describe('migration #59', function () { }; const newStorage = await migration59.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); it('should do nothing if transactions state is empty', async function () { @@ -356,7 +355,7 @@ describe('migration #59', function () { }; const newStorage = await migration59.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); it('should do nothing if transactions state is not an object', async function () { @@ -372,7 +371,7 @@ describe('migration #59', function () { }; const newStorage = await migration59.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); it('should do nothing if state is empty', async function () { @@ -382,6 +381,6 @@ describe('migration #59', function () { }; const newStorage = await migration59.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/060.test.js b/app/scripts/migrations/060.test.js index c0116c9a7..3387c0e71 100644 --- a/app/scripts/migrations/060.test.js +++ b/app/scripts/migrations/060.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import migration60 from './060'; describe('migration #60', function () { @@ -11,7 +10,7 @@ describe('migration #60', function () { }; const newStorage = await migration60.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 60, }); }); @@ -56,10 +55,10 @@ describe('migration #60', function () { const newStorage = await migration60.migrate(oldStorage); const { notifications } = newStorage.data.NotificationController; const notificationKeys = Object.keys(notifications); - // Assert support notification is removed - assert.equal(notificationKeys.length, 3); + // Expect support notification is removed + expect(notificationKeys).toHaveLength(3); notificationKeys.forEach((key) => { - assert.notEqual(notifications[key].date, '2020-08-31'); + expect(notifications[key].date).not.toStrictEqual('2020-08-31'); }); }); @@ -97,7 +96,7 @@ describe('migration #60', function () { }; const newStorage = await migration60.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); it('does not modify state when NotificationsController is undefined', async function () { @@ -110,7 +109,7 @@ describe('migration #60', function () { }; const newStorage = await migration60.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); it('does not modify state when notifications are undefined', async function () { @@ -124,7 +123,7 @@ describe('migration #60', function () { }; const newStorage = await migration60.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); it('does not modify state when notifications are not an object', async function () { @@ -138,6 +137,6 @@ describe('migration #60', function () { }; const newStorage = await migration60.migrate(oldStorage); - assert.deepEqual(oldStorage.data, newStorage.data); + expect(oldStorage.data).toStrictEqual(newStorage.data); }); }); diff --git a/app/scripts/migrations/061.test.js b/app/scripts/migrations/061.test.js index 2c0c45510..53cfeca0c 100644 --- a/app/scripts/migrations/061.test.js +++ b/app/scripts/migrations/061.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import sinon from 'sinon'; import migration61 from './061'; @@ -22,7 +21,7 @@ describe('migration #61', function () { }; const newStorage = await migration61.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 61, }); }); @@ -38,7 +37,7 @@ describe('migration #61', function () { }; const newStorage = await migration61.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ AppStateController: { recoveryPhraseReminderHasBeenShown: false, recoveryPhraseReminderLastShown: 1621580400000, @@ -56,7 +55,7 @@ describe('migration #61', function () { }; const newStorage = await migration61.migrate(oldStorage); - assert.deepEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ existingProperty: 'foo', AppStateController: { recoveryPhraseReminderHasBeenShown: false, diff --git a/app/scripts/migrations/062.test.js b/app/scripts/migrations/062.test.js index 44229ac1d..7f0ed7253 100644 --- a/app/scripts/migrations/062.test.js +++ b/app/scripts/migrations/062.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import migration62 from './062'; describe('migration #62', function () { @@ -11,7 +10,7 @@ describe('migration #62', function () { }; const newStorage = await migration62.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 62, }); }); @@ -29,7 +28,7 @@ describe('migration #62', function () { }; const newStorage = await migration62.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ MetaMetricsController: { bar: 'baz', }, @@ -50,7 +49,7 @@ describe('migration #62', function () { }; const newStorage = await migration62.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ MetaMetricsController: { bar: 'baz', }, @@ -70,7 +69,7 @@ describe('migration #62', function () { }; const newStorage = await migration62.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ MetaMetricsController: { bar: 'baz', }, diff --git a/app/scripts/migrations/063.test.js b/app/scripts/migrations/063.test.js index 30804a35c..f99a18fc4 100644 --- a/app/scripts/migrations/063.test.js +++ b/app/scripts/migrations/063.test.js @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import migration63 from './063'; -describe('migration #63', function () { - it('should update the version metadata', async function () { +describe('migration #63', () => { + it('should update the version metadata', async () => { const oldStorage = { meta: { version: 62, @@ -11,12 +10,12 @@ describe('migration #63', function () { }; const newStorage = await migration63.migrate(oldStorage); - assert.deepEqual(newStorage.meta, { + expect(newStorage.meta).toStrictEqual({ version: 63, }); }); - it('should move accountTokens data from PreferencesController to TokensController allTokens field and rotate structure from [accountAddress][chainId] to [chainId][accountAddress]', async function () { + it('should move accountTokens data from PreferencesController to TokensController allTokens field and rotate structure from [accountAddress][chainId] to [chainId][accountAddress]', async () => { const oldAccountTokens = { '0x00000000000': { '0x1': [ @@ -155,7 +154,7 @@ describe('migration #63', function () { }; const newStorage = await migration63.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TokensController: { allTokens: expectedTokens, allIgnoredTokens: {}, @@ -167,7 +166,7 @@ describe('migration #63', function () { }); }); - it('should move accountHiddenTokens data from PreferencesController to TokensController allIgnoredTokens field and rotate structure from [accountAddress][chainId] to [chainId][accountAddress]', async function () { + it('should move accountHiddenTokens data from PreferencesController to TokensController allIgnoredTokens field and rotate structure from [accountAddress][chainId] to [chainId][accountAddress]', async () => { const oldStorage = { meta: {}, data: { @@ -193,7 +192,7 @@ describe('migration #63', function () { }; const newStorage = await migration63.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ TokensController: { allTokens: {}, allIgnoredTokens: { @@ -219,7 +218,7 @@ describe('migration #63', function () { }); }); - it('should should remove all token related state from the preferences controller', async function () { + it('should should remove all token related state from the preferences controller', async () => { const oldStorage = { meta: {}, data: { @@ -237,7 +236,7 @@ describe('migration #63', function () { }; const newStorage = await migration63.migrate(oldStorage); - assert.deepStrictEqual(newStorage.data, { + expect(newStorage.data).toStrictEqual({ PreferencesController: { completedOnboarding: true, dismissSeedBackUpReminder: false, diff --git a/app/scripts/migrations/migrations.test.js b/app/scripts/migrations/migrations.test.js index 82d15f501..f1f860d90 100644 --- a/app/scripts/migrations/migrations.test.js +++ b/app/scripts/migrations/migrations.test.js @@ -1,4 +1,4 @@ -import { strict as assert } from 'assert'; +/* eslint-disable jest/valid-expect-in-promise */ import wallet1 from '../../../test/lib/migrations/001.json'; import vault4 from '../../../test/lib/migrations/004.json'; import migration2 from './002'; @@ -19,233 +19,140 @@ let vault5, vault6, vault7, vault8, vault9; // vault10, vault11 const oldTestRpc = 'https://rawtestrpc.metamask.io/'; const newTestRpc = 'https://testrpc.metamask.io/'; -describe('wallet1 is migrated successfully', function () { - it('should convert providers', function () { +describe('wallet1 is migrated successfully', () => { + it('should convert providers', () => { wallet1.data.config.provider = { type: 'etherscan', rpcTarget: null }; - return migration2 + migration2 .migrate(wallet1) .then((secondResult) => { const secondData = secondResult.data; - assert.equal( - secondData.config.provider.type, - 'rpc', - 'provider should be rpc', - ); - assert.equal( - secondData.config.provider.rpcTarget, + expect(secondData.config.provider.type).toStrictEqual('rpc'); + expect(secondData.config.provider.rpcTarget).toStrictEqual( 'https://rpc.metamask.io/', - 'main provider should be our rpc', ); secondResult.data.config.provider.rpcTarget = oldTestRpc; return migration3.migrate(secondResult); }) .then((thirdResult) => { - assert.equal( - thirdResult.data.config.provider.rpcTarget, + expect(thirdResult.data.config.provider.rpcTarget).toStrictEqual( newTestRpc, - 'config.provider.rpcTarget should be set to the proper testrpc url.', ); return migration4.migrate(thirdResult); }) .then((fourthResult) => { const fourthData = fourthResult.data; - assert.equal( - fourthData.config.provider.rpcTarget, - undefined, - 'old rpcTarget should not exist.', - ); - assert.equal( - fourthData.config.provider.type, - 'testnet', - 'config.provider should be set to testnet.', - ); + expect(fourthData.config.provider.rpcTarget).toBeUndefined(); + expect(fourthData.config.provider.type).toStrictEqual('testnet'); return migration5.migrate(vault4); }) .then((fifthResult) => { const fifthData = fifthResult.data; - assert.equal(fifthData.vault, undefined, 'old vault should not exist'); - assert.equal( - fifthData.walletNicknames, - undefined, - 'old walletNicknames should not exist', - ); - assert.equal( - fifthData.config.selectedAccount, - undefined, - 'old config.selectedAccount should not exist', - ); - assert.equal( - fifthData.KeyringController.vault, + expect(fifthData.vault).toBeUndefined(); + expect(fifthData.walletNicknames).toBeUndefined(); + expect(fifthData.config.selectedAccount).toBeUndefined(); + expect(fifthData.KeyringController.vault).toStrictEqual( vault4.data.vault, - 'KeyringController.vault should exist', ); - assert.equal( - fifthData.KeyringController.selectedAccount, + expect(fifthData.KeyringController.selectedAccount).toStrictEqual( vault4.data.config.selectedAccount, - 'KeyringController.selectedAccount should have moved', ); - assert.equal( + expect( fifthData.KeyringController.walletNicknames[ '0x0beb674745816b125fbc07285d39fd373e64895c' ], + ).toStrictEqual( vault4.data.walletNicknames[ '0x0beb674745816b125fbc07285d39fd373e64895c' ], - 'KeyringController.walletNicknames should have moved', ); vault5 = fifthResult; return migration6.migrate(fifthResult); }) .then((sixthResult) => { - assert.equal( + expect( sixthResult.data.KeyringController.selectedAccount, - undefined, - 'old selectedAccount should not exist', - ); - assert.equal( + ).toBeUndefined(); + expect( sixthResult.data.PreferencesController.selectedAddress, - vault5.data.KeyringController.selectedAccount, - 'selectedAccount should have moved', - ); + ).toStrictEqual(vault5.data.KeyringController.selectedAccount); vault6 = sixthResult; return migration7.migrate(sixthResult); }) .then((seventhResult) => { - assert.equal( - seventhResult.data.transactions, - undefined, - 'old transactions should not exist', - ); - assert.equal( - seventhResult.data.gasMultiplier, - undefined, - 'old gasMultiplier should not exist', - ); - assert.equal( + expect(seventhResult.data.transactions).toBeUndefined(); + expect(seventhResult.data.gasMultiplier).toBeUndefined(); + expect( seventhResult.data.TransactionManager.transactions[0].id, - vault6.data.transactions[0].id, - 'transactions should have moved', - ); - assert.equal( + ).toStrictEqual(vault6.data.transactions[0].id); + expect( seventhResult.data.TransactionManager.gasMultiplier, - vault6.data.gasMultiplier, - 'gasMultiplier should have moved', - ); + ).toStrictEqual(vault6.data.gasMultiplier); vault7 = seventhResult; return migration8.migrate(seventhResult); }) .then((eighthResult) => { - assert.equal( - eighthResult.data.noticesList, - undefined, - 'old noticesList should not exist', - ); - assert.equal( + expect(eighthResult.data.noticesList).toBeUndefined(); + expect( eighthResult.data.NoticeController.noticesList[0].title, - vault7.data.noticesList[0].title, - 'noticesList should have moved', - ); + ).toStrictEqual(vault7.data.noticesList[0].title); vault8 = eighthResult; return migration9.migrate(eighthResult); }) .then((ninthResult) => { - assert.equal( - ninthResult.data.currentFiat, - undefined, - 'old currentFiat should not exist', - ); - assert.equal( - ninthResult.data.fiatCurrency, - undefined, - 'old fiatCurrency should not exist', - ); - assert.equal( - ninthResult.data.conversionRate, - undefined, - 'old conversionRate should not exist', - ); - assert.equal( - ninthResult.data.conversionDate, - undefined, - 'old conversionDate should not exist', - ); + expect(ninthResult.data.currentFiat).toBeUndefined(); + expect(ninthResult.data.fiatCurrency).toBeUndefined(); + expect(ninthResult.data.conversionRate).toBeUndefined(); + expect(ninthResult.data.conversionDate).toBeUndefined(); - assert.equal( + expect( ninthResult.data.CurrencyController.currentCurrency, - vault8.data.fiatCurrency, - 'currentFiat should have moved', - ); - assert.equal( + ).toStrictEqual(vault8.data.fiatCurrency); + expect( ninthResult.data.CurrencyController.conversionRate, - vault8.data.conversionRate, - 'conversionRate should have moved', - ); - assert.equal( + ).toStrictEqual(vault8.data.conversionRate); + expect( ninthResult.data.CurrencyController.conversionDate, - vault8.data.conversionDate, - 'conversionDate should have moved', - ); + ).toStrictEqual(vault8.data.conversionDate); vault9 = ninthResult; return migration10.migrate(ninthResult); }) .then((tenthResult) => { - assert.equal( - tenthResult.data.shapeShiftTxList, - undefined, - 'old shapeShiftTxList should not exist', - ); - assert.equal( + expect(tenthResult.data.shapeShiftTxList).toBeUndefined(); + expect( tenthResult.data.ShapeShiftController.shapeShiftTxList[0].transaction, - vault9.data.shapeShiftTxList[0].transaction, - ); + ).toStrictEqual(vault9.data.shapeShiftTxList[0].transaction); return migration11.migrate(tenthResult); }) .then((eleventhResult) => { - assert.equal( - eleventhResult.data.isDisclaimerConfirmed, - undefined, - 'isDisclaimerConfirmed should not exist', - ); - assert.equal( - eleventhResult.data.TOSHash, - undefined, - 'TOSHash should not exist', - ); + expect(eleventhResult.data.isDisclaimerConfirmed).toBeUndefined(); + expect(eleventhResult.data.TOSHash).toBeUndefined(); return migration12.migrate(eleventhResult); }) .then((twelfthResult) => { - assert.equal( + expect( twelfthResult.data.NoticeController.noticesList[0].body, - '', - 'notices that have been read should have an empty body.', - ); - assert.equal( + ).toStrictEqual(''); + expect( twelfthResult.data.NoticeController.noticesList[1].body, - 'nonempty', - 'notices that have not been read should not have an empty body.', - ); + ).toStrictEqual('nonempty'); - assert.equal( - twelfthResult.data.config.provider.type, + expect(twelfthResult.data.config.provider.type).toStrictEqual( 'testnet', - 'network is originally testnet.', ); return migration13.migrate(twelfthResult); }) .then((thirteenthResult) => { - assert.equal( - thirteenthResult.data.config.provider.type, + expect(thirteenthResult.data.config.provider.type).toStrictEqual( 'ropsten', - 'network has been changed to ropsten.', ); }); }); diff --git a/app/scripts/migrations/template.test.js b/app/scripts/migrations/template.test.js index 5277b86ba..f24dc1bca 100644 --- a/app/scripts/migrations/template.test.js +++ b/app/scripts/migrations/template.test.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import migrationTemplate from './template'; const storage = { @@ -6,14 +5,9 @@ const storage = { data: {}, }; -describe('storage is migrated successfully', function () { - it('should work', function (done) { - migrationTemplate - .migrate(storage) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 0); - done(); - }) - .catch(done); +describe('storage is migrated successfully', () => { + it('should work', async () => { + const migratedData = await migrationTemplate.migrate(storage); + expect(migratedData.meta.version).toStrictEqual(0); }); }); diff --git a/jest.config.js b/jest.config.js index 1c0d0692a..9c15faa41 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,4 @@ module.exports = { - displayName: '/ui, /shared', collectCoverageFrom: ['/ui/**/*.js', '/shared/**/*.js'], coverageDirectory: './jest-coverage/main', coveragePathIgnorePatterns: ['.stories.js', '.snap'], @@ -17,6 +16,10 @@ module.exports = { restoreMocks: true, setupFiles: ['/test/setup.js', '/test/env.js'], setupFilesAfterEnv: ['/test/jest/setup.js'], - testMatch: ['/ui/**/*.test.js', '/shared/**/*.test.js'], + testMatch: [ + '/ui/**/*.test.js', + '/shared/**/*.test.js', + '/app/scripts/migrations/*.test.js', + ], testTimeout: 2500, }; diff --git a/package.json b/package.json index 210f5f8dd..17f6e85a8 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "test:unit": "mocha --exit --require test/env.js --require test/setup.js --recursive './app/**/*.test.js'", "test:unit:global": "mocha --exit --require test/env.js --require test/setup.js --recursive test/unit-global/*.test.js", "test:unit:jest": "./test/run-jest.sh", - "test:unit:lax": "mocha --exit --require test/env.js --require test/setup.js --ignore './app/scripts/controllers/permissions/*.test.js' --recursive './app/**/*.test.js'", + "test:unit:lax": "mocha --exit --require test/env.js --require test/setup.js --ignore './app/scripts/controllers/permissions/*.test.js' --ignore './app/scripts/migrations/*.test.js' --recursive './app/**/*.test.js'", "test:unit:strict": "mocha --exit --require test/env.js --require test/setup.js --recursive './app/scripts/controllers/permissions/*.test.js'", "test:unit:path": "mocha --exit --require test/env.js --require test/setup.js --recursive", "test:e2e:chrome": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js", diff --git a/test/helpers/setup-helper.js b/test/helpers/setup-helper.js index 6e371a790..f9d2112aa 100644 --- a/test/helpers/setup-helper.js +++ b/test/helpers/setup-helper.js @@ -4,6 +4,8 @@ import Adapter from 'enzyme-adapter-react-16'; import log from 'loglevel'; import { JSDOM } from 'jsdom'; +process.env.IN_TEST = true; + nock.disableNetConnect(); nock.enableNetConnect('localhost');