From 95f198550e419c598750a1717014dac6ca5091e9 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 5 Jul 2019 14:01:34 -0300 Subject: Declare variables before use (#6806) While working on #6805, I noticed that many variables were being used before they were declared. Technically this worked fine in practice because we were using the `transform-es2015-block-scoping` Babel plugin, which transforms `let` and `const` to `var`, which is hoisted. However, after removing that Babel transformation, many things broke. All instances of variables or classes being used before declared have been fixed. The `no-use-before-define` eslint rule has been added to catch these cases going forward. The rule is disabled for function declarations for the moment, because those are always hoisted. We could disable that too if we want to, but it's purely stylistic and would require a lot more changes. --- .../app/controllers/metamask-controller-test.js | 25 +++++++++++----------- test/unit/ui/app/reducers/app.spec.js | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'test/unit') diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js index 1b8cde42e..e8e407a7f 100644 --- a/test/unit/app/controllers/metamask-controller-test.js +++ b/test/unit/app/controllers/metamask-controller-test.js @@ -679,19 +679,6 @@ describe('MetaMaskController', function () { }) describe('#newUnsignedPersonalMessage', function () { - - it('errors with no from in msgParams', async () => { - const msgParams = { - 'data': data, - } - try { - await metamaskController.newUnsignedPersonalMessage(msgParams) - assert.fail('should have thrown') - } catch (error) { - assert.equal(error.message, 'MetaMask Message Signature: from field is required.') - } - }) - let msgParams, metamaskPersonalMsgs, personalMessages, msgId const address = '0xc42edfcc21ed14dda456aa0756c153f7985d8813' @@ -718,6 +705,18 @@ describe('MetaMaskController', function () { personalMessages[0].msgParams.metamaskId = parseInt(msgId) }) + it('errors with no from in msgParams', async () => { + const msgParams = { + 'data': data, + } + try { + await metamaskController.newUnsignedPersonalMessage(msgParams) + assert.fail('should have thrown') + } catch (error) { + assert.equal(error.message, 'MetaMask Message Signature: from field is required.') + } + }) + it('persists address from msg params', function () { assert.equal(metamaskPersonalMsgs[msgId].msgParams.from, address) }) diff --git a/test/unit/ui/app/reducers/app.spec.js b/test/unit/ui/app/reducers/app.spec.js index 09cf3dbf0..28f5ebb33 100644 --- a/test/unit/ui/app/reducers/app.spec.js +++ b/test/unit/ui/app/reducers/app.spec.js @@ -700,7 +700,7 @@ describe('App State', () => { }) it('hides sub loading indicator', () => { - const oldState = {...metamaskState, ...oldState} + const oldState = {...metamaskState, isSubLoading: true } const state = reduceApp(oldState, { type: actions.HIDE_SUB_LOADING_INDICATION, }) -- cgit From 1112277cd628378f8b0e659067456677ec9a45ac Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 26 Jul 2019 10:35:21 -0300 Subject: Remove `seedWords` completely from metamask state (#6920) `seedWords` used to be stored on the metamask state temporarily at certain points. This hasn't been the case since #5994, but references to this state remained. All of the logic remained for correctly updating these `seedWords`, handling them during navigation, and scrubbing them from the state. However the state was never updated in practice. The `seedWords` are still returned by `verifySeedPhrase`, and they're still stored in component state in a few places. But they aren't ever set in the Redux metadata state or the Preferences controller. All references to this state have been removed, along with any logic for interacting with this state. A few unused actions were removed as well. --- test/unit/actions/tx_test.js | 1 - .../app/controllers/metamask-controller-test.js | 32 --- .../app/controllers/preferences-controller-test.js | 15 -- test/unit/ui/app/actions.spec.js | 243 +-------------------- test/unit/ui/app/reducers/app.spec.js | 13 -- test/unit/ui/app/reducers/metamask.spec.js | 36 --- 6 files changed, 2 insertions(+), 338 deletions(-) (limited to 'test/unit') diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js index f2f8f1d1c..66378b594 100644 --- a/test/unit/actions/tx_test.js +++ b/test/unit/actions/tx_test.js @@ -35,7 +35,6 @@ describe('tx confirmation screen', function () { actions._setBackgroundConnection({ approveTransaction (_, cb) { cb('An error!') }, cancelTransaction (_, cb) { cb() }, - clearSeedWordCache (cb) { cb() }, getState (cb) { cb() }, }) done() diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js index e8e407a7f..effd7c0ce 100644 --- a/test/unit/app/controllers/metamask-controller-test.js +++ b/test/unit/app/controllers/metamask-controller-test.js @@ -497,8 +497,6 @@ describe('MetaMaskController', function () { }) describe('#verifyseedPhrase', function () { - let seedPhrase, getConfigSeed - it('errors when no keying is provided', async function () { try { await metamaskController.verifySeedPhrase() @@ -509,21 +507,6 @@ describe('MetaMaskController', function () { beforeEach(async function () { await metamaskController.createNewVaultAndKeychain('password') - seedPhrase = await metamaskController.verifySeedPhrase() - }) - - it('#placeSeedWords should match the initially created vault seed', function () { - - metamaskController.placeSeedWords((err, result) => { - if (err) { - console.log(err) - } else { - getConfigSeed = metamaskController.configManager.getSeedWords() - assert.equal(result, seedPhrase) - assert.equal(result, getConfigSeed) - } - }) - assert.equal(getConfigSeed, undefined) }) it('#addNewAccount', async function () { @@ -589,21 +572,6 @@ describe('MetaMaskController', function () { }) }) - describe('#clearSeedWordCache', function () { - it('should set seed words to null', function (done) { - sandbox.stub(metamaskController.preferencesController, 'setSeedWords') - metamaskController.clearSeedWordCache((err) => { - if (err) { - done(err) - } - - assert.ok(metamaskController.preferencesController.setSeedWords.calledOnce) - assert.deepEqual(metamaskController.preferencesController.setSeedWords.args, [[null]]) - done() - }) - }) - }) - describe('#setCurrentLocale', function () { it('checks the default currentLocale', function () { diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js index 81b152f3d..7e047a2a8 100644 --- a/test/unit/app/controllers/preferences-controller-test.js +++ b/test/unit/app/controllers/preferences-controller-test.js @@ -496,21 +496,6 @@ describe('preferences controller', function () { }) }) - describe('setSeedWords', function () { - it('should default to null', function () { - const state = preferencesController.store.getState() - assert.equal(state.seedWords, null) - }) - - it('should set the seedWords property in state', function () { - assert.equal(preferencesController.store.getState().seedWords, null) - - preferencesController.setSeedWords('foo bar baz') - - assert.equal(preferencesController.store.getState().seedWords, 'foo bar baz') - }) - }) - describe('#updateRpc', function () { it('should update the rpcDetails properly', () => { preferencesController.store.updateState({frequentRpcListDetail: [{}, { rpcUrl: 'test' }, {}]}) diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 34dd6a39b..392321481 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -134,95 +134,25 @@ describe('Actions', () => { }) }) - describe('#confirmSeedWords', () => { - - let clearSeedWordCacheSpy - - afterEach(() => { - clearSeedWordCacheSpy.restore() - }) - - it('shows account page after clearing seed word cache', () => { - - const store = mockStore({}) - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'HIDE_LOADING_INDICATION' }, - { type: 'SHOW_ACCOUNTS_PAGE' }, - ] - - clearSeedWordCacheSpy = sinon.spy(background, 'clearSeedWordCache') - - return store.dispatch(actions.confirmSeedWords()) - .then(() => { - assert.equal(clearSeedWordCacheSpy.callCount, 1) - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - - it('errors in callback will display warning', () => { - const store = mockStore({}) - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'HIDE_LOADING_INDICATION' }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - clearSeedWordCacheSpy = sinon.stub(background, 'clearSeedWordCache') - - clearSeedWordCacheSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.confirmSeedWords()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - describe('#createNewVaultAndRestore', () => { - let createNewVaultAndRestoreSpy, clearSeedWordCacheSpy + let createNewVaultAndRestoreSpy afterEach(() => { createNewVaultAndRestoreSpy.restore() }) - it('clears seed words and restores new vault', () => { + it('restores new vault', () => { const store = mockStore({}) createNewVaultAndRestoreSpy = sinon.spy(background, 'createNewVaultAndRestore') - clearSeedWordCacheSpy = sinon.spy(background, 'clearSeedWordCache') return store.dispatch(actions.createNewVaultAndRestore()) .catch(() => { - assert(clearSeedWordCacheSpy.calledOnce) assert(createNewVaultAndRestoreSpy.calledOnce) }) }) - it('errors when callback in clearSeedWordCache throws', () => { - const store = mockStore() - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - { type: 'HIDE_LOADING_INDICATION' }, - ] - - clearSeedWordCacheSpy = sinon.stub(background, 'clearSeedWordCache') - clearSeedWordCacheSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.createNewVaultAndRestore()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - it('errors when callback in createNewVaultAndRestore throws', () => { const store = mockStore({}) @@ -246,113 +176,6 @@ describe('Actions', () => { }) }) - describe('#createNewVaultAndKeychain', () => { - - let createNewVaultAndKeychainSpy, placeSeedWordsSpy - - afterEach(() => { - createNewVaultAndKeychainSpy.restore() - placeSeedWordsSpy.restore() - }) - - it('calls createNewVaultAndKeychain and placeSeedWords in background', () => { - - const store = mockStore() - - createNewVaultAndKeychainSpy = sinon.spy(background, 'createNewVaultAndKeychain') - placeSeedWordsSpy = sinon.spy(background, 'placeSeedWords') - - return store.dispatch(actions.createNewVaultAndKeychain()) - .then(() => { - assert(createNewVaultAndKeychainSpy.calledOnce) - assert(placeSeedWordsSpy.calledOnce) - }) - }) - - it('displays error and value when callback errors', () => { - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - { type: 'HIDE_LOADING_INDICATION' }, - ] - - createNewVaultAndKeychainSpy = sinon.stub(background, 'createNewVaultAndKeychain') - createNewVaultAndKeychainSpy.callsFake((_, callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.createNewVaultAndKeychain()) - .then(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - - }) - - it('errors when placeSeedWords throws', () => { - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - { type: 'HIDE_LOADING_INDICATION' }, - ] - - placeSeedWordsSpy = sinon.stub(background, 'placeSeedWords') - placeSeedWordsSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.createNewVaultAndKeychain()) - .then(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - - describe('#requestRevealSeed', () => { - - let submitPasswordSpy, placeSeedWordsSpy - - afterEach(() => { - submitPasswordSpy.restore() - }) - - it('calls submitPassword and placeSeedWords from background', () => { - - const store = mockStore() - - submitPasswordSpy = sinon.spy(background, 'submitPassword') - placeSeedWordsSpy = sinon.spy(background, 'placeSeedWords') - - return store.dispatch(actions.requestRevealSeed()) - .then(() => { - assert(submitPasswordSpy.calledOnce) - assert(placeSeedWordsSpy.calledOnce) - }) - }) - - it('displays warning error with value when callback errors', () => { - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - submitPasswordSpy = sinon.stub(background, 'submitPassword') - submitPasswordSpy.callsFake((_, callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.requestRevealSeed()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - describe('#requestRevealSeedWords', () => { let submitPasswordSpy @@ -389,68 +212,6 @@ describe('Actions', () => { }) }) - describe('#requestRevealSeed', () => { - - let submitPasswordSpy, placeSeedWordsSpy - - afterEach(() => { - submitPasswordSpy.restore() - placeSeedWordsSpy.restore() - }) - - it('calls submitPassword and placeSeedWords in background', () => { - - const store = mockStore() - - submitPasswordSpy = sinon.spy(background, 'submitPassword') - placeSeedWordsSpy = sinon.spy(background, 'placeSeedWords') - - return store.dispatch(actions.requestRevealSeed()) - .then(() => { - assert(submitPasswordSpy.calledOnce) - assert(placeSeedWordsSpy.calledOnce) - }) - }) - - it('displays warning error message when submitPassword in background errors', () => { - submitPasswordSpy = sinon.stub(background, 'submitPassword') - submitPasswordSpy.callsFake((_, callback) => { - callback(new Error('error')) - }) - - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - return store.dispatch(actions.requestRevealSeed()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - - it('errors when placeSeedWords throw', () => { - placeSeedWordsSpy = sinon.stub(background, 'placeSeedWords') - placeSeedWordsSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - return store.dispatch(actions.requestRevealSeed()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - describe('#removeAccount', () => { let removeAccountSpy diff --git a/test/unit/ui/app/reducers/app.spec.js b/test/unit/ui/app/reducers/app.spec.js index 28f5ebb33..6f8dd920c 100644 --- a/test/unit/ui/app/reducers/app.spec.js +++ b/test/unit/ui/app/reducers/app.spec.js @@ -270,18 +270,6 @@ describe('App State', () => { assert.equal(state.isLoading, true) }) - it('shows new vault seed', () => { - const state = reduceApp(metamaskState, { - type: actions.SHOW_NEW_VAULT_SEED, - value: 'test seed words', - }) - - assert.equal(state.currentView.name, 'createVaultComplete') - assert.equal(state.currentView.seedWords, 'test seed words') - assert.equal(state.transForward, true) - assert.equal(state.isLoading, false) - }) - it('shows new account screen', () => { const state = reduceApp(metamaskState, { type: actions.NEW_ACCOUNT_SCREEN, @@ -437,7 +425,6 @@ describe('App State', () => { }) assert.equal(state.currentView.name, 'accounts') - assert.equal(state.currentView.seedWords, undefined) assert.equal(state.transForward, true) assert.equal(state.isLoading, false) assert.equal(state.warning, null) diff --git a/test/unit/ui/app/reducers/metamask.spec.js b/test/unit/ui/app/reducers/metamask.spec.js index d7876bf39..39caf3e6a 100644 --- a/test/unit/ui/app/reducers/metamask.spec.js +++ b/test/unit/ui/app/reducers/metamask.spec.js @@ -9,32 +9,6 @@ describe('MetaMask Reducers', () => { assert(initState) }) - it('sets revealing seed to true and adds seed words to new state', () => { - const seedWordsState = reduceMetamask({}, { - type: actions.SHOW_NEW_VAULT_SEED, - value: 'test seed words', - }) - - assert.equal(seedWordsState.seedWords, 'test seed words') - assert.equal(seedWordsState.isRevealingSeedWords, true) - }) - - it('shows account page', () => { - const seedWordsState = { - metamask: { - seedwords: 'test seed words', - isRevealing: true, - }, - } - - const state = reduceMetamask(seedWordsState, { - type: actions.SHOW_ACCOUNTS_PAGE, - }) - - assert.equal(state.seedWords, undefined) - assert.equal(state.isRevealingSeedWords, false) - }) - it('unlocks MetaMask', () => { const state = reduceMetamask({}, { type: actions.UNLOCK_METAMASK, @@ -152,16 +126,6 @@ describe('MetaMask Reducers', () => { }) }) - it('shows new vault seed words and sets isRevealingSeedWords to true', () => { - const showNewVaultSeedState = reduceMetamask({}, { - type: actions.SHOW_NEW_VAULT_SEED, - value: 'test seed words', - }) - - assert.equal(showNewVaultSeedState.isRevealingSeedWords, true) - assert.equal(showNewVaultSeedState.seedWords, 'test seed words') - }) - it('shows account detail', () => { const state = reduceMetamask({}, { -- cgit From e9c7df28ed88f6dc3a5074cf873f3920429d1803 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Wed, 31 Jul 2019 17:26:44 -0230 Subject: Address book send plus contact list (#6914) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Style Send Header * Move Send to-row to send view and restyle * Add "Recents" group to select recipient view * Rename SendToRow to AddRecipient * Basic UI and Layout * New ENSInput component * wip - fuzzy search for input * small refactor * Add Dialog * contact list initial * initial error on invalid address * clean up edit * Click to open modal * Create AddToAddressBookModal component * Modal styling and layout * modal i18n * Add to Addressbook * ens wip * ens wip * ENS Resolution * Reset input * Send to explicit address * Happy Path Complete * Add back error checking * Reset send-to when emptying input * Add back warning object * Fix linter * Fix unit test #1 - fix import paths * Remove dead tests * One more to go * Fix all unit tests * add unit test for reducers and actions * test rendering AddRecipient * Add tests for dialog boxes in AddRecipient * Add test for validating * Fix linter * Fix e2e tests * Token send e2e fix * Style View Contact * Style edit-contact * Fix e2e * Fix from-import-beta-ui e2e spec * Make section header say "add recipient” by default * Auto-focus add recipient input * Update placeholder text * Update input title font size * Auto advance to next step if user paste a valid address * Ellipsify address when recipient is selected * Fix app header background color on desktop * Give each form row a margin of 16px * Use .container/.component naming pattern for ens-input * Auto-focus on input when add to addressbook modal is opened; Save on Enter * Fix and add unit test * Fix selectors name in e2e tests * Correct e2e test token amount for address-book-send changes * Adds e2e test for editing a transaction * Delete test/integration/lib/send-new-ui.js * Add tests for amount max button and high value error on send screen to test/e2e/metamask-ui.spec.js * lint and revert to address as object keys * add chainId based on current network to address book entry * fix test * only display contacts for the current network * Improve ENS message when not found on current network * Add error to indicate when network does not support ENS * bump gaba * address book, resolve comments * Move contact-list to its own component * De-duplicate getaddressbook selector and refactor name selection logic in contact-list-tab/ * Use contact-list component in contact-list-tab.component (i.e. in settings) * Improve/fix settings headers for popup and browser views * Lint fixes related to address book updates * Add 'My accounts' page to settings address book * Update add new contact button in settings to match floating circular design * Improve styles of view contact page * Improve styles and labels of the add-contact.component * Further lint fixes related to address book updates * Update unit tests as per address book updates * Ensure that contact list groups are sorted alphabetically * Refactor settings component to use a container for connection to redux; allow display of addressbook name in settings header * Decouple ens-input.component from send context * Add ens resolution to add contact screen in settings * Switching networks when an ens address is shown on send form removes the ens address. * Resolve send screen search for ensAddress to matching address book entry if it exists * Show resolved ens icon and address if exists (settings: add-contact.component) * Make the displayed and copied address in view-contact.component the checksummed address * Default alias state prop in AddToAddressBookModal to empty string * Use keyCode to detect enter key in AddToAddressBookModal * Ensure add-contact component properly updates after QR code detection * Fix display of all recents after clicking 'Load More' in contact list * Fix send screen contact searching after network switching * Code cleanup related to address book changes * Update unit tests for address book changes * Update ENS name not found on network message * Add ens registration error message * Cancel on edit mode takes user back to view screen * Adds support for memo to settings contact list view and edit screens * Modify designs of edit and view contact in popup environment * Update settings content list UX to show split columns in fullscreen and proper internal navigation * Correct background address book API usages in UI --- test/unit/ui/app/actions.spec.js | 2 +- test/unit/ui/app/reducers/metamask.spec.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 392321481..919bd81a6 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -869,7 +869,7 @@ describe('Actions', () => { }) it('', () => { - const store = mockStore() + const store = mockStore({ metamask: devState }) store.dispatch(actions.addToAddressBook('test')) assert(addToAddressBookSpy.calledOnce) }) diff --git a/test/unit/ui/app/reducers/metamask.spec.js b/test/unit/ui/app/reducers/metamask.spec.js index 39caf3e6a..714bd476a 100644 --- a/test/unit/ui/app/reducers/metamask.spec.js +++ b/test/unit/ui/app/reducers/metamask.spec.js @@ -309,6 +309,8 @@ describe('MetaMask Reducers', () => { errors: {}, editingTransactionId: 22, forceGasMin: '0xGas', + ensResolution: null, + ensResolutionError: '', } const sendState = reduceMetamask({}, { @@ -492,4 +494,24 @@ describe('MetaMask Reducers', () => { assert.deepEqual(state.pendingTokens, {}) }) + + it('update ensResolution', () => { + const state = reduceMetamask({}, { + type: actions.UPDATE_SEND_ENS_RESOLUTION, + payload: '0x1337', + }) + + assert.deepEqual(state.send.ensResolution, '0x1337') + assert.deepEqual(state.send.ensResolutionError, '') + }) + + it('update ensResolutionError', () => { + const state = reduceMetamask({}, { + type: actions.UPDATE_SEND_ENS_RESOLUTION_ERROR, + payload: 'ens name not found', + }) + + assert.deepEqual(state.send.ensResolutionError, 'ens name not found') + assert.deepEqual(state.send.ensResolution, null) + }) }) -- cgit From 4d88e1cf862c3ae174780cd888d7703685db23e7 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Wed, 31 Jul 2019 17:47:11 -0230 Subject: Enable indent linting via ESLint (#6936) * Enable indent linting via ESLint * yarn run lint:fix --- test/unit/app/controllers/detect-tokens-test.js | 16 +-- .../controllers/transactions/pending-tx-test.js | 90 ++++++------ .../recipient-blacklist-checker-test.js | 4 +- .../controllers/transactions/tx-controller-test.js | 100 ++++++------- .../transactions/tx-state-manager-test.js | 12 +- .../app/controllers/transactions/tx-utils-test.js | 2 +- test/unit/app/edge-encryptor-test.js | 32 ++--- test/unit/localhostState.js | 10 +- test/unit/migrations/021-test.js | 12 +- test/unit/migrations/022-test.js | 22 +-- test/unit/migrations/023-test.js | 44 +++--- test/unit/migrations/024-test.js | 24 ++-- test/unit/migrations/025-test.js | 24 ++-- test/unit/migrations/029-test.js | 24 ++-- test/unit/migrations/030-test.js | 16 +-- test/unit/migrations/031-test.js | 8 +- test/unit/migrations/migrations-test.js | 154 ++++++++++----------- test/unit/migrations/migrator-test.js | 22 +-- test/unit/migrations/template-test.js | 8 +- test/unit/ui/app/actions.spec.js | 2 +- 20 files changed, 313 insertions(+), 313 deletions(-) (limited to 'test/unit') diff --git a/test/unit/app/controllers/detect-tokens-test.js b/test/unit/app/controllers/detect-tokens-test.js index 2acc53e92..8f18406f4 100644 --- a/test/unit/app/controllers/detect-tokens-test.js +++ b/test/unit/app/controllers/detect-tokens-test.js @@ -71,8 +71,8 @@ describe('DetectTokensController', () => { controller.isUnlocked = true var stub = sandbox.stub(controller, 'detectTokenBalance') - .withArgs('0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4').returns(true) - .withArgs('0xBC86727E770de68B1060C91f6BB6945c73e10388').returns(true) + .withArgs('0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4').returns(true) + .withArgs('0xBC86727E770de68B1060C91f6BB6945c73e10388').returns(true) await controller.detectNewTokens() sandbox.assert.notCalled(stub) @@ -84,14 +84,14 @@ describe('DetectTokensController', () => { controller.isUnlocked = true sandbox.stub(controller, 'detectTokenBalance') - .withArgs('0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4') - .returns(preferences.addToken('0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', 'J8T', 8)) - .withArgs('0xBC86727E770de68B1060C91f6BB6945c73e10388') - .returns(preferences.addToken('0xbc86727e770de68b1060c91f6bb6945c73e10388', 'XNK', 18)) + .withArgs('0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4') + .returns(preferences.addToken('0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', 'J8T', 8)) + .withArgs('0xBC86727E770de68B1060C91f6BB6945c73e10388') + .returns(preferences.addToken('0xbc86727e770de68b1060c91f6bb6945c73e10388', 'XNK', 18)) await controller.detectNewTokens() assert.deepEqual(preferences.store.getState().tokens, [{address: '0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', decimals: 8, symbol: 'J8T'}, - {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}]) + {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}]) }) it('should not detect same token while in main network', async () => { @@ -108,7 +108,7 @@ describe('DetectTokensController', () => { await controller.detectNewTokens() assert.deepEqual(preferences.store.getState().tokens, [{address: '0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', decimals: 8, symbol: 'J8T'}, - {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}]) + {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}]) }) it('should trigger detect new tokens when change address', async () => { diff --git a/test/unit/app/controllers/transactions/pending-tx-test.js b/test/unit/app/controllers/transactions/pending-tx-test.js index b37ac2766..e1de5731b 100644 --- a/test/unit/app/controllers/transactions/pending-tx-test.js +++ b/test/unit/app/controllers/transactions/pending-tx-test.js @@ -7,7 +7,7 @@ const sinon = require('sinon') describe('PendingTransactionTracker', function () { let pendingTxTracker, txMeta, txMetaNoHash, providerResultStub, - provider, txMeta3, txList, knownErrors + provider, txMeta3, txList, knownErrors this.timeout(10000) beforeEach(function () { @@ -80,7 +80,7 @@ describe('PendingTransactionTracker', function () { }, { count: 1 })[0] stub = sinon.stub(pendingTxTracker, 'getCompletedTransactions') - .returns(txGen.txs) + .returns(txGen.txs) // THE EXPECTATION const spy = sinon.spy() @@ -107,18 +107,18 @@ describe('PendingTransactionTracker', function () { }) it('should emit tx:dropped with the txMetas id only after the second call', function (done) { - txMeta = { - id: 1, - hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb', - status: 'submitted', - txParams: { - from: '0x1678a085c290ebd122dc42cba69373b5953b831d', - nonce: '0x1', - value: '0xfffff', - }, - history: [{}], - rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d', - } + txMeta = { + id: 1, + hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb', + status: 'submitted', + txParams: { + from: '0x1678a085c290ebd122dc42cba69373b5953b831d', + nonce: '0x1', + value: '0xfffff', + }, + history: [{}], + rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d', + } providerResultStub['eth_getTransactionCount'] = '0x02' providerResultStub['eth_getTransactionByHash'] = {} @@ -159,8 +159,8 @@ describe('PendingTransactionTracker', function () { pendingTxTracker.getPendingTransactions = () => txList pendingTxTracker._checkPendingTx = (tx) => { tx.resolve(tx) } Promise.all(txList.map((tx) => tx.processed)) - .then(() => done()) - .catch(done) + .then(() => done()) + .catch(done) pendingTxTracker.updatePendingTxs() }) @@ -169,8 +169,8 @@ describe('PendingTransactionTracker', function () { describe('#resubmitPendingTxs', function () { const blockNumberStub = '0x0' beforeEach(function () { - const txMeta2 = txMeta3 = txMeta - txList = [txMeta, txMeta2, txMeta3].map((tx) => { + const txMeta2 = txMeta3 = txMeta + txList = [txMeta, txMeta2, txMeta3].map((tx) => { tx.processed = new Promise((resolve) => { tx.resolve = resolve }) return tx }) @@ -183,8 +183,8 @@ describe('PendingTransactionTracker', function () { pendingTxTracker.getPendingTransactions = () => txList pendingTxTracker._resubmitTx = async (tx) => { tx.resolve(tx) } Promise.all(txList.map((tx) => tx.processed)) - .then(() => done()) - .catch(done) + .then(() => done()) + .catch(done) pendingTxTracker.resubmitPendingTxs(blockNumberStub) }) it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) { @@ -209,8 +209,8 @@ describe('PendingTransactionTracker', function () { throw new Error(knownErrors.pop()) } Promise.all(txList.map((tx) => tx.processed)) - .then(() => done()) - .catch(done) + .then(() => done()) + .catch(done) pendingTxTracker.resubmitPendingTxs(blockNumberStub) }) @@ -227,8 +227,8 @@ describe('PendingTransactionTracker', function () { pendingTxTracker.getPendingTransactions = () => txList pendingTxTracker._resubmitTx = async () => { throw new TypeError('im some real error') } Promise.all(txList.map((tx) => tx.processed)) - .then(() => done()) - .catch(done) + .then(() => done()) + .catch(done) pendingTxTracker.resubmitPendingTxs(blockNumberStub) }) @@ -264,11 +264,11 @@ describe('PendingTransactionTracker', function () { // Stubbing out current account state: // Adding the fake tx: pendingTxTracker._resubmitTx(txMeta) - .then(() => done()) - .catch((err) => { - assert.ifError(err, 'should not throw an error') - done(err) - }) + .then(() => done()) + .catch((err) => { + assert.ifError(err, 'should not throw an error') + done(err) + }) assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction') }) @@ -278,11 +278,11 @@ describe('PendingTransactionTracker', function () { const mockLatestBlockNumber = '0x5' pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber) - .then(() => done()) - .catch((err) => { - assert.ifError(err, 'should not throw an error') - done(err) - }) + .then(() => done()) + .catch((err) => { + assert.ifError(err, 'should not throw an error') + done(err) + }) assert.equal(pendingTxTracker.publishTransaction.callCount, 0, 'Should NOT call publish transaction') }) @@ -292,11 +292,11 @@ describe('PendingTransactionTracker', function () { const mockLatestBlockNumber = '0x11' pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber) - .then(() => done()) - .catch((err) => { - assert.ifError(err, 'should not throw an error') - done(err) - }) + .then(() => done()) + .catch((err) => { + assert.ifError(err, 'should not throw an error') + done(err) + }) assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction') }) @@ -382,11 +382,11 @@ describe('PendingTransactionTracker', function () { value: '0xfffff', }, }) - .then((taken) => { - assert.ok(!taken) - done() - }) - .catch(done) + .then((taken) => { + assert.ok(!taken) + done() + }) + .catch(done) }) it('should return true if nonce has been taken', function (done) { @@ -400,7 +400,7 @@ describe('PendingTransactionTracker', function () { assert.ok(taken) done() }) - .catch(done) + .catch(done) }) }) }) diff --git a/test/unit/app/controllers/transactions/recipient-blacklist-checker-test.js b/test/unit/app/controllers/transactions/recipient-blacklist-checker-test.js index d3e47c67e..1d6a0eb08 100644 --- a/test/unit/app/controllers/transactions/recipient-blacklist-checker-test.js +++ b/test/unit/app/controllers/transactions/recipient-blacklist-checker-test.js @@ -31,8 +31,8 @@ describe('Recipient Blacklist Checker', function () { const networks = [ROPSTEN_CODE, RINKEYBY_CODE, KOVAN_CODE, GOERLI_CODE] for (const networkId in networks) { publicAccounts.forEach((account) => { - recipientBlackListChecker.checkAccount(networkId, account) - callCount++ + recipientBlackListChecker.checkAccount(networkId, account) + callCount++ }) } assert.equal(callCount, 40) diff --git a/test/unit/app/controllers/transactions/tx-controller-test.js b/test/unit/app/controllers/transactions/tx-controller-test.js index 8ff409207..9072dc684 100644 --- a/test/unit/app/controllers/transactions/tx-controller-test.js +++ b/test/unit/app/controllers/transactions/tx-controller-test.js @@ -129,13 +129,13 @@ describe('Transaction Controller', function () { stub = sinon.stub(txController, 'addUnapprovedTransaction').callsFake(() => { txController.emit('newUnapprovedTx', txMeta) return Promise.resolve(txController.txStateManager.addTx(txMeta)) - }) + }) - afterEach(function () { - txController.txStateManager._saveTxList([]) - stub.restore() + afterEach(function () { + txController.txStateManager._saveTxList([]) + stub.restore() + }) }) - }) it('should resolve when finished and status is submitted and resolve with the hash', function (done) { txController.once('newUnapprovedTx', (txMetaFromEmit) => { @@ -146,11 +146,11 @@ describe('Transaction Controller', function () { }) txController.newUnapprovedTransaction(txParams) - .then((hash) => { - assert(hash, 'newUnapprovedTransaction needs to return the hash') - done() - }) - .catch(done) + .then((hash) => { + assert(hash, 'newUnapprovedTransaction needs to return the hash') + done() + }) + .catch(done) }) it('should reject when finished and status is rejected', function (done) { @@ -161,10 +161,10 @@ describe('Transaction Controller', function () { }) txController.newUnapprovedTransaction(txParams) - .catch((err) => { - if (err.message === 'MetaMask Tx Signature: User denied transaction signature.') done() - else done(err) - }) + .catch((err) => { + if (err.message === 'MetaMask Tx Signature: User denied transaction signature.') done() + else done(err) + }) }) }) @@ -182,17 +182,17 @@ describe('Transaction Controller', function () { it('should add an unapproved transaction and return a valid txMeta', function (done) { txController.addUnapprovedTransaction({ from: selectedAddress }) - .then((txMeta) => { - assert(('id' in txMeta), 'should have a id') - assert(('time' in txMeta), 'should have a time stamp') - assert(('metamaskNetworkId' in txMeta), 'should have a metamaskNetworkId') - assert(('txParams' in txMeta), 'should have a txParams') - assert(('history' in txMeta), 'should have a history') - - const memTxMeta = txController.txStateManager.getTx(txMeta.id) - assert.deepEqual(txMeta, memTxMeta, `txMeta should be stored in txController after adding it\n expected: ${txMeta} \n got: ${memTxMeta}`) - done() - }).catch(done) + .then((txMeta) => { + assert(('id' in txMeta), 'should have a id') + assert(('time' in txMeta), 'should have a time stamp') + assert(('metamaskNetworkId' in txMeta), 'should have a metamaskNetworkId') + assert(('txParams' in txMeta), 'should have a txParams') + assert(('history' in txMeta), 'should have a history') + + const memTxMeta = txController.txStateManager.getTx(txMeta.id) + assert.deepEqual(txMeta, memTxMeta, `txMeta should be stored in txController after adding it\n expected: ${txMeta} \n got: ${memTxMeta}`) + done() + }).catch(done) }) it('should emit newUnapprovedTx event and pass txMeta as the first argument', function (done) { @@ -202,16 +202,16 @@ describe('Transaction Controller', function () { done() }) txController.addUnapprovedTransaction({ from: selectedAddress }) - .catch(done) + .catch(done) }) it('should fail if recipient is public', function (done) { txController.networkStore = new ObservableStore(1) txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' }) - .catch((err) => { - if (err.message === 'Recipient is a public account') done() - else done(err) - }) + .catch((err) => { + if (err.message === 'Recipient is a public account') done() + else done(err) + }) }) it('should fail if the from address isn\'t the selected address', function (done) { @@ -232,16 +232,16 @@ describe('Transaction Controller', function () { done() }) txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' }) - .catch(done) + .catch(done) }) it('should fail if netId is loading', function (done) { txController.networkStore = new ObservableStore('loading') txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' }) - .catch((err) => { - if (err.message === 'MetaMask is having trouble connecting to the network') done() - else done(err) - }) + .catch((err) => { + if (err.message === 'MetaMask is having trouble connecting to the network') done() + else done(err) + }) }) }) @@ -284,11 +284,11 @@ describe('Transaction Controller', function () { })) }) Promise.all(listeners) - .then((returnValues) => { - assert.deepEqual(returnValues.pop(), txMeta, 'last event 1:unapproved should return txMeta') - done() - }) - .catch(done) + .then((returnValues) => { + assert.deepEqual(returnValues.pop(), txMeta, 'last event 1:unapproved should return txMeta') + done() + }) + .catch(done) txController.addTx(txMeta) }) }) @@ -511,16 +511,16 @@ describe('Transaction Controller', function () { { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, ]) txController.retryTransaction(1) - .then((txMeta) => { - assert.equal(txMeta.txParams.gasPrice, '0x10642ac00', 'gasPrice should have a %10 gasPrice bump') - assert.equal(txMeta.txParams.nonce, txParams.nonce, 'nonce should be the same') - assert.equal(txMeta.txParams.from, txParams.from, 'from should be the same') - assert.equal(txMeta.txParams.to, txParams.to, 'to should be the same') - assert.equal(txMeta.txParams.data, txParams.data, 'data should be the same') - assert.ok(('lastGasPrice' in txMeta), 'should have the key `lastGasPrice`') - assert.equal(txController.txStateManager.getTxList().length, 2) - done() - }).catch(done) + .then((txMeta) => { + assert.equal(txMeta.txParams.gasPrice, '0x10642ac00', 'gasPrice should have a %10 gasPrice bump') + assert.equal(txMeta.txParams.nonce, txParams.nonce, 'nonce should be the same') + assert.equal(txMeta.txParams.from, txParams.from, 'from should be the same') + assert.equal(txMeta.txParams.to, txParams.to, 'to should be the same') + assert.equal(txMeta.txParams.data, txParams.data, 'data should be the same') + assert.ok(('lastGasPrice' in txMeta), 'should have the key `lastGasPrice`') + assert.equal(txController.txStateManager.getTxList().length, 2) + done() + }).catch(done) }) }) diff --git a/test/unit/app/controllers/transactions/tx-state-manager-test.js b/test/unit/app/controllers/transactions/tx-state-manager-test.js index 72dbbc4a1..48343bcd7 100644 --- a/test/unit/app/controllers/transactions/tx-state-manager-test.js +++ b/test/unit/app/controllers/transactions/tx-state-manager-test.js @@ -43,7 +43,7 @@ describe('TransactionStateManager', function () { }) describe('#setTxStatusRejected', function () { - it('sets the tx status to rejected and removes it from history', function () { + it('sets the tx status to rejected and removes it from history', function () { const tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} } txStateManager.addTx(tx) txStateManager.setTxStatusRejected(1) @@ -56,11 +56,11 @@ describe('TransactionStateManager', function () { const tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} } txStateManager.addTx(tx) const noop = function (err) { - if (err) { - console.log('Error: ', err) - } - assert(true, 'event listener has been triggered and noop executed') - done() + if (err) { + console.log('Error: ', err) + } + assert(true, 'event listener has been triggered and noop executed') + done() } txStateManager.on('1:rejected', noop) txStateManager.setTxStatusRejected(1) diff --git a/test/unit/app/controllers/transactions/tx-utils-test.js b/test/unit/app/controllers/transactions/tx-utils-test.js index 029fab4d5..65c8d35b0 100644 --- a/test/unit/app/controllers/transactions/tx-utils-test.js +++ b/test/unit/app/controllers/transactions/tx-utils-test.js @@ -93,6 +93,6 @@ describe('txUtils', function () { // should run txParams.from = '0x1678a085c290ebd122dc42cba69373b5953b831d' txUtils.validateFrom(txParams) - }) + }) }) }) diff --git a/test/unit/app/edge-encryptor-test.js b/test/unit/app/edge-encryptor-test.js index 52817cd09..ad873e351 100644 --- a/test/unit/app/edge-encryptor-test.js +++ b/test/unit/app/edge-encryptor-test.js @@ -65,13 +65,13 @@ describe('EdgeEncryptor', function () { edgeEncryptor.encrypt(password, data) .then(function (encryptedData) { edgeEncryptor.decrypt(password, encryptedData) - .then(function (decryptedData) { - assert.equal(decryptedData, data) - done() - }) - .catch(function (err) { - done(err) - }) + .then(function (decryptedData) { + assert.equal(decryptedData, data) + done() + }) + .catch(function (err) { + done(err) + }) }) .catch(function (err) { done(err) @@ -83,15 +83,15 @@ describe('EdgeEncryptor', function () { edgeEncryptor.encrypt(password, data) .then(function (encryptedData) { edgeEncryptor.decrypt('wrong password', encryptedData) - .then(function () { - assert.fail('could decrypt with wrong password') - done() - }) - .catch(function (err) { - assert.ok(err instanceof Error) - assert.equal(err.message, 'Incorrect password') - done() - }) + .then(function () { + assert.fail('could decrypt with wrong password') + done() + }) + .catch(function (err) { + assert.ok(err instanceof Error) + assert.equal(err.message, 'Incorrect password') + done() + }) }) .catch(function (err) { done(err) diff --git a/test/unit/localhostState.js b/test/unit/localhostState.js index f9fa157d7..71adbb859 100644 --- a/test/unit/localhostState.js +++ b/test/unit/localhostState.js @@ -10,12 +10,12 @@ */ const initialState = { config: {}, - NetworkController: { - provider: { - type: 'rpc', - rpcTarget: 'http://localhost:8545', - }, + NetworkController: { + provider: { + type: 'rpc', + rpcTarget: 'http://localhost:8545', }, + }, } module.exports = initialState diff --git a/test/unit/migrations/021-test.js b/test/unit/migrations/021-test.js index 458e9b4b5..d46b2a835 100644 --- a/test/unit/migrations/021-test.js +++ b/test/unit/migrations/021-test.js @@ -6,11 +6,11 @@ const migration21 = require('../../../app/scripts/migrations/021') describe('wallet2 is migrated successfully with out the BlacklistController', () => { it('should delete BlacklistController key', (done) => { migration21.migrate(wallet2) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 21) - assert(!migratedData.data.BlacklistController) - assert(!migratedData.data.RecentBlocks) - done() - }).catch(done) + .then((migratedData) => { + assert.equal(migratedData.meta.version, 21) + assert(!migratedData.data.BlacklistController) + assert(!migratedData.data.RecentBlocks) + done() + }).catch(done) }) }) diff --git a/test/unit/migrations/022-test.js b/test/unit/migrations/022-test.js index f8ee00e38..f7dd35b08 100644 --- a/test/unit/migrations/022-test.js +++ b/test/unit/migrations/022-test.js @@ -17,16 +17,16 @@ const storage = { describe('storage is migrated successfully where transactions that are submitted have submittedTimes', () => { it('should add submittedTime key on the txMeta if appropriate', (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) + .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) }) }) diff --git a/test/unit/migrations/023-test.js b/test/unit/migrations/023-test.js index 7da94448d..1b47dea92 100644 --- a/test/unit/migrations/023-test.js +++ b/test/unit/migrations/023-test.js @@ -57,41 +57,41 @@ storage.data.TransactionController.transactions = transactions describe('storage is migrated successfully and the proper transactions are remove from state', () => { it('should remove transactions that are unneeded', (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++ - } - }) - assert.equal(leftoverNonDeletableTxCount, nonDeletableCount, 'migration shouldnt 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) + .then((migratedData) => { + let leftoverNonDeletableTxCount = 0 + const migratedTransactions = migratedData.data.TransactionController.transactions + migratedTransactions.forEach((tx) => { + if (!deletableTxStates.find((s) => s === tx.status)) { + leftoverNonDeletableTxCount++ + } + }) + assert.equal(leftoverNonDeletableTxCount, nonDeletableCount, 'migration shouldnt 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) }) it('should not remove any transactions because 40 is the expectable limit', (done) => { storage.meta.version = 22 storage.data.TransactionController.transactions = transactions40 migration23.migrate(storage) - .then((migratedData) => { - const migratedTransactions = migratedData.data.TransactionController.transactions + .then((migratedData) => { + const migratedTransactions = migratedData.data.TransactionController.transactions - assert.equal(migratedTransactions.length, 40, 'migration shouldnt delete when at limit') - done() - }).catch(done) + assert.equal(migratedTransactions.length, 40, 'migration shouldnt delete when at limit') + done() + }).catch(done) }) it('should not remove any transactions because 20 txs is under the expectable limit', (done) => { 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 shouldnt delete when under limit') - done() - }).catch(done) + .then((migratedData) => { + const migratedTransactions = migratedData.data.TransactionController.transactions + assert.equal(migratedTransactions.length, 20, 'migration shouldnt delete when under limit') + done() + }).catch(done) }) }) diff --git a/test/unit/migrations/024-test.js b/test/unit/migrations/024-test.js index c7b0611bc..671c7f832 100644 --- a/test/unit/migrations/024-test.js +++ b/test/unit/migrations/024-test.js @@ -28,21 +28,21 @@ storage.data.TransactionController.transactions = transactions describe('storage is migrated successfully and the txParams.from are lowercase', () => { it('should lowercase the from for unapproved txs', (done) => { migration24.migrate(storage) - .then((migratedData) => { - const migratedTransactions = migratedData.data.TransactionController.transactions - migratedTransactions.forEach((tx) => { - if (tx.status === 'unapproved') assert.equal(tx.txParams.from, '0x8acce2391c0d510a6c5e5d8f819a678f79b7e675') - else assert.equal(tx.txParams.from, '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675') - }) - done() - }).catch(done) + .then((migratedData) => { + const migratedTransactions = migratedData.data.TransactionController.transactions + migratedTransactions.forEach((tx) => { + if (tx.status === 'unapproved') assert.equal(tx.txParams.from, '0x8acce2391c0d510a6c5e5d8f819a678f79b7e675') + else assert.equal(tx.txParams.from, '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675') + }) + done() + }).catch(done) }) it('should migrate first time state', (done) => { migration24.migrate(firstTimeState) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 24) - done() - }).catch(done) + .then((migratedData) => { + assert.equal(migratedData.meta.version, 24) + done() + }).catch(done) }) }) diff --git a/test/unit/migrations/025-test.js b/test/unit/migrations/025-test.js index 1e56913a1..fa89bc54f 100644 --- a/test/unit/migrations/025-test.js +++ b/test/unit/migrations/025-test.js @@ -29,21 +29,21 @@ storage.data.TransactionController.transactions = transactions describe('storage is migrated successfully and the txParams.from are lowercase', () => { it('should lowercase the from for unapproved txs', (done) => { migration25.migrate(storage) - .then((migratedData) => { - const migratedTransactions = migratedData.data.TransactionController.transactions - migratedTransactions.forEach((tx) => { - if (tx.status === 'unapproved') assert(!tx.txParams.random) - if (tx.status === 'unapproved') assert(!tx.txParams.chainId) - }) - done() - }).catch(done) + .then((migratedData) => { + const migratedTransactions = migratedData.data.TransactionController.transactions + migratedTransactions.forEach((tx) => { + if (tx.status === 'unapproved') assert(!tx.txParams.random) + if (tx.status === 'unapproved') assert(!tx.txParams.chainId) + }) + done() + }).catch(done) }) it('should migrate first time state', (done) => { migration25.migrate(firstTimeState) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 25) - done() - }).catch(done) + .then((migratedData) => { + assert.equal(migratedData.meta.version, 25) + done() + }).catch(done) }) }) diff --git a/test/unit/migrations/029-test.js b/test/unit/migrations/029-test.js index a2876487b..7f9b8a005 100644 --- a/test/unit/migrations/029-test.js +++ b/test/unit/migrations/029-test.js @@ -19,20 +19,20 @@ const storage = { describe('storage is migrated successfully where transactions that are submitted have submittedTimes', () => { it('should auto fail transactions more than 12 hours old', (done) => { migration29.migrate(storage) - .then((migratedData) => { - const txs = migratedData.data.TransactionController.transactions - const [ txMeta1 ] = txs - assert.equal(migratedData.meta.version, 29) + .then((migratedData) => { + const txs = migratedData.data.TransactionController.transactions + const [ txMeta1 ] = txs + assert.equal(migratedData.meta.version, 29) - assert.equal(txMeta1.status, 'failed', 'old tx is auto failed') - assert(txMeta1.err.message.includes('too long'), 'error message assigned') + assert.equal(txMeta1.status, 'failed', 'old tx is auto failed') + assert(txMeta1.err.message.includes('too long'), 'error message assigned') - txs.forEach((tx) => { - if (tx.id === 1) return - assert.notEqual(tx.status, 'failed', 'other tx is not auto failed') - }) + txs.forEach((tx) => { + if (tx.id === 1) return + assert.notEqual(tx.status, 'failed', 'other tx is not auto failed') + }) - done() - }).catch(done) + done() + }).catch(done) }) }) diff --git a/test/unit/migrations/030-test.js b/test/unit/migrations/030-test.js index ca410342f..a8e7b4b32 100644 --- a/test/unit/migrations/030-test.js +++ b/test/unit/migrations/030-test.js @@ -25,13 +25,13 @@ const storage = { describe('storage is migrated successfully', () => { it('should work', (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) + .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) }) }) diff --git a/test/unit/migrations/031-test.js b/test/unit/migrations/031-test.js index c85fd7af4..4fcd8b9a5 100644 --- a/test/unit/migrations/031-test.js +++ b/test/unit/migrations/031-test.js @@ -1,7 +1,7 @@ const assert = require('assert') const migration31 = require('../../../app/scripts/migrations/031') - describe('migration #31', () => { +describe('migration #31', () => { it('should set completedOnboarding to true if vault exists', done => { const oldStorage = { 'meta': {}, @@ -23,7 +23,7 @@ const migration31 = require('../../../app/scripts/migrations/031') }, } - migration31.migrate(oldStorage) + migration31.migrate(oldStorage) .then(newStorage => { assert.equal(newStorage.data.PreferencesController.completedOnboarding, true) done() @@ -31,7 +31,7 @@ const migration31 = require('../../../app/scripts/migrations/031') .catch(done) }) - it('should set completedOnboarding to false if vault does not exist', done => { + it('should set completedOnboarding to false if vault does not exist', done => { const oldStorage = { 'meta': {}, 'data': { @@ -46,7 +46,7 @@ const migration31 = require('../../../app/scripts/migrations/031') }, } - migration31.migrate(oldStorage) + migration31.migrate(oldStorage) .then(newStorage => { assert.equal(newStorage.data.PreferencesController.completedOnboarding, false) done() diff --git a/test/unit/migrations/migrations-test.js b/test/unit/migrations/migrations-test.js index 50afd9c2e..563b02a6d 100644 --- a/test/unit/migrations/migrations-test.js +++ b/test/unit/migrations/migrations-test.js @@ -27,82 +27,82 @@ describe('wallet1 is migrated successfully', () => { wallet1.data.config.provider = { type: 'etherscan', rpcTarget: null } return 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, '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, 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, null, 'old rpcTarget should not exist.') - assert.equal(fourthData.config.provider.type, 'testnet', 'config.provider should be set to testnet.') - - return migration5.migrate(vault4) - }).then((fifthResult) => { - const fifthData = fifthResult.data - assert.equal(fifthData.vault, null, 'old vault should not exist') - assert.equal(fifthData.walletNicknames, null, 'old walletNicknames should not exist') - assert.equal(fifthData.config.selectedAccount, null, 'old config.selectedAccount should not exist') - assert.equal(fifthData.KeyringController.vault, vault4.data.vault, 'KeyringController.vault should exist') - assert.equal(fifthData.KeyringController.selectedAccount, vault4.data.config.selectedAccount, 'KeyringController.selectedAccount should have moved') - assert.equal(fifthData.KeyringController.walletNicknames['0x0beb674745816b125fbc07285d39fd373e64895c'], vault4.data.walletNicknames['0x0beb674745816b125fbc07285d39fd373e64895c'], 'KeyringController.walletNicknames should have moved') - - vault5 = fifthResult - return migration6.migrate(fifthResult) - }).then((sixthResult) => { - assert.equal(sixthResult.data.KeyringController.selectedAccount, null, 'old selectedAccount should not exist') - assert.equal(sixthResult.data.PreferencesController.selectedAddress, vault5.data.KeyringController.selectedAccount, 'selectedAccount should have moved') - - vault6 = sixthResult - return migration7.migrate(sixthResult) - }).then((seventhResult) => { - assert.equal(seventhResult.data.transactions, null, 'old transactions should not exist') - assert.equal(seventhResult.data.gasMultiplier, null, 'old gasMultiplier should not exist') - assert.equal(seventhResult.data.TransactionManager.transactions[0].id, vault6.data.transactions[0].id, 'transactions should have moved') - assert.equal(seventhResult.data.TransactionManager.gasMultiplier, vault6.data.gasMultiplier, 'gasMultiplier should have moved') - - vault7 = seventhResult - return migration8.migrate(seventhResult) - }).then((eighthResult) => { - assert.equal(eighthResult.data.noticesList, null, 'old noticesList should not exist') - assert.equal(eighthResult.data.NoticeController.noticesList[0].title, vault7.data.noticesList[0].title, 'noticesList should have moved') - - vault8 = eighthResult - return migration9.migrate(eighthResult) - }).then((ninthResult) => { - assert.equal(ninthResult.data.currentFiat, null, 'old currentFiat should not exist') - assert.equal(ninthResult.data.fiatCurrency, null, 'old fiatCurrency should not exist') - assert.equal(ninthResult.data.conversionRate, null, 'old conversionRate should not exist') - assert.equal(ninthResult.data.conversionDate, null, 'old conversionDate should not exist') - - assert.equal(ninthResult.data.CurrencyController.currentCurrency, vault8.data.fiatCurrency, 'currentFiat should have moved') - assert.equal(ninthResult.data.CurrencyController.conversionRate, vault8.data.conversionRate, 'conversionRate should have moved') - assert.equal(ninthResult.data.CurrencyController.conversionDate, vault8.data.conversionDate, 'conversionDate should have moved') - - vault9 = ninthResult - return migration10.migrate(ninthResult) - }).then((tenthResult) => { - assert.equal(tenthResult.data.shapeShiftTxList, null, 'old shapeShiftTxList should not exist') - assert.equal(tenthResult.data.ShapeShiftController.shapeShiftTxList[0].transaction, vault9.data.shapeShiftTxList[0].transaction) - - return migration11.migrate(tenthResult) - }).then((eleventhResult) => { - assert.equal(eleventhResult.data.isDisclaimerConfirmed, null, 'isDisclaimerConfirmed should not exist') - assert.equal(eleventhResult.data.TOSHash, null, 'TOSHash should not exist') - - return migration12.migrate(eleventhResult) - }).then((twelfthResult) => { - assert.equal(twelfthResult.data.NoticeController.noticesList[0].body, '', 'notices that have been read should have an empty body.') - assert.equal(twelfthResult.data.NoticeController.noticesList[1].body, 'nonempty', 'notices that have not been read should not have an empty body.') - - assert.equal(twelfthResult.data.config.provider.type, 'testnet', 'network is originally testnet.') - return migration13.migrate(twelfthResult) - }).then((thirteenthResult) => { - assert.equal(thirteenthResult.data.config.provider.type, 'ropsten', 'network has been changed to ropsten.') - }) + .then((secondResult) => { + const secondData = secondResult.data + assert.equal(secondData.config.provider.type, 'rpc', 'provider should be rpc') + assert.equal(secondData.config.provider.rpcTarget, '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, 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, null, 'old rpcTarget should not exist.') + assert.equal(fourthData.config.provider.type, 'testnet', 'config.provider should be set to testnet.') + + return migration5.migrate(vault4) + }).then((fifthResult) => { + const fifthData = fifthResult.data + assert.equal(fifthData.vault, null, 'old vault should not exist') + assert.equal(fifthData.walletNicknames, null, 'old walletNicknames should not exist') + assert.equal(fifthData.config.selectedAccount, null, 'old config.selectedAccount should not exist') + assert.equal(fifthData.KeyringController.vault, vault4.data.vault, 'KeyringController.vault should exist') + assert.equal(fifthData.KeyringController.selectedAccount, vault4.data.config.selectedAccount, 'KeyringController.selectedAccount should have moved') + assert.equal(fifthData.KeyringController.walletNicknames['0x0beb674745816b125fbc07285d39fd373e64895c'], vault4.data.walletNicknames['0x0beb674745816b125fbc07285d39fd373e64895c'], 'KeyringController.walletNicknames should have moved') + + vault5 = fifthResult + return migration6.migrate(fifthResult) + }).then((sixthResult) => { + assert.equal(sixthResult.data.KeyringController.selectedAccount, null, 'old selectedAccount should not exist') + assert.equal(sixthResult.data.PreferencesController.selectedAddress, vault5.data.KeyringController.selectedAccount, 'selectedAccount should have moved') + + vault6 = sixthResult + return migration7.migrate(sixthResult) + }).then((seventhResult) => { + assert.equal(seventhResult.data.transactions, null, 'old transactions should not exist') + assert.equal(seventhResult.data.gasMultiplier, null, 'old gasMultiplier should not exist') + assert.equal(seventhResult.data.TransactionManager.transactions[0].id, vault6.data.transactions[0].id, 'transactions should have moved') + assert.equal(seventhResult.data.TransactionManager.gasMultiplier, vault6.data.gasMultiplier, 'gasMultiplier should have moved') + + vault7 = seventhResult + return migration8.migrate(seventhResult) + }).then((eighthResult) => { + assert.equal(eighthResult.data.noticesList, null, 'old noticesList should not exist') + assert.equal(eighthResult.data.NoticeController.noticesList[0].title, vault7.data.noticesList[0].title, 'noticesList should have moved') + + vault8 = eighthResult + return migration9.migrate(eighthResult) + }).then((ninthResult) => { + assert.equal(ninthResult.data.currentFiat, null, 'old currentFiat should not exist') + assert.equal(ninthResult.data.fiatCurrency, null, 'old fiatCurrency should not exist') + assert.equal(ninthResult.data.conversionRate, null, 'old conversionRate should not exist') + assert.equal(ninthResult.data.conversionDate, null, 'old conversionDate should not exist') + + assert.equal(ninthResult.data.CurrencyController.currentCurrency, vault8.data.fiatCurrency, 'currentFiat should have moved') + assert.equal(ninthResult.data.CurrencyController.conversionRate, vault8.data.conversionRate, 'conversionRate should have moved') + assert.equal(ninthResult.data.CurrencyController.conversionDate, vault8.data.conversionDate, 'conversionDate should have moved') + + vault9 = ninthResult + return migration10.migrate(ninthResult) + }).then((tenthResult) => { + assert.equal(tenthResult.data.shapeShiftTxList, null, 'old shapeShiftTxList should not exist') + assert.equal(tenthResult.data.ShapeShiftController.shapeShiftTxList[0].transaction, vault9.data.shapeShiftTxList[0].transaction) + + return migration11.migrate(tenthResult) + }).then((eleventhResult) => { + assert.equal(eleventhResult.data.isDisclaimerConfirmed, null, 'isDisclaimerConfirmed should not exist') + assert.equal(eleventhResult.data.TOSHash, null, 'TOSHash should not exist') + + return migration12.migrate(eleventhResult) + }).then((twelfthResult) => { + assert.equal(twelfthResult.data.NoticeController.noticesList[0].body, '', 'notices that have been read should have an empty body.') + assert.equal(twelfthResult.data.NoticeController.noticesList[1].body, 'nonempty', 'notices that have not been read should not have an empty body.') + + assert.equal(twelfthResult.data.config.provider.type, 'testnet', 'network is originally testnet.') + return migration13.migrate(twelfthResult) + }).then((thirteenthResult) => { + assert.equal(thirteenthResult.data.config.provider.type, 'ropsten', 'network has been changed to ropsten.') + }) }) }) diff --git a/test/unit/migrations/migrator-test.js b/test/unit/migrations/migrator-test.js index 693c5830d..3dcc5aff7 100644 --- a/test/unit/migrations/migrator-test.js +++ b/test/unit/migrations/migrator-test.js @@ -40,20 +40,20 @@ describe('Migrator', () => { const migrator = new Migrator({ migrations: stubMigrations }) it('migratedData version should be version 3', (done) => { migrator.migrateData(versionedData) - .then((migratedData) => { - assert.equal(migratedData.meta.version, stubMigrations[2].version) - done() - }).catch(done) + .then((migratedData) => { + assert.equal(migratedData.meta.version, stubMigrations[2].version) + done() + }).catch(done) }) it('should match the last version in live migrations', (done) => { const migrator = new Migrator({ migrations: liveMigrations }) migrator.migrateData(firstTimeState) - .then((migratedData) => { - const last = liveMigrations.length - 1 - assert.equal(migratedData.meta.version, liveMigrations[last].version) - done() - }).catch(done) + .then((migratedData) => { + const last = liveMigrations.length - 1 + assert.equal(migratedData.meta.version, liveMigrations[last].version) + done() + }).catch(done) }) it('should emit an error', function (done) { @@ -61,8 +61,8 @@ describe('Migrator', () => { const migrator = new Migrator({ migrations: [{ version: 1, migrate: async () => { throw new Error('test') } } ] }) migrator.on('error', () => done()) migrator.migrateData({ meta: {version: 0} }) - .then(() => { - }).catch(done) + .then(() => { + }).catch(done) }) }) diff --git a/test/unit/migrations/template-test.js b/test/unit/migrations/template-test.js index 0db69d65a..f606cce6f 100644 --- a/test/unit/migrations/template-test.js +++ b/test/unit/migrations/template-test.js @@ -8,9 +8,9 @@ const storage = { describe('storage is migrated successfully', () => { it('should work', (done) => { migrationTemplate.migrate(storage) - .then((migratedData) => { - assert.equal(migratedData.meta.version, 0) - done() - }).catch(done) + .then((migratedData) => { + assert.equal(migratedData.meta.version, 0) + done() + }).catch(done) }) }) diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 919bd81a6..5bf82a185 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -628,7 +628,7 @@ describe('Actions', () => { { type: 'DISPLAY_WARNING', value: 'error' }, { type: 'HIDE_LOADING_INDICATION' }, { type: 'LOCK_METAMASK' }, - ] + ] backgroundSetLockedSpy = sinon.stub(background, 'setLocked') backgroundSetLockedSpy.callsFake(callback => { callback(new Error('error')) -- cgit From d1e47a30bc3118cf267a9cff5049b6daabfd3105 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 1 Aug 2019 14:03:20 -0230 Subject: Add test cases for migration 34 (#6938) --- test/unit/migrations/034-test.js | 123 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 test/unit/migrations/034-test.js (limited to 'test/unit') diff --git a/test/unit/migrations/034-test.js b/test/unit/migrations/034-test.js new file mode 100644 index 000000000..1777d6067 --- /dev/null +++ b/test/unit/migrations/034-test.js @@ -0,0 +1,123 @@ +const assert = require('assert') +const migration34 = require('../../../app/scripts/migrations/034') + +describe('migration #34', () => { + it('should update the version metadata', (done) => { + const oldStorage = { + 'meta': { + 'version': 33, + }, + 'data': {}, + } + + migration34.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.meta, { + 'version': 34, + }) + done() + }) + .catch(done) + }) + + it('should set migratedPrivacyMode & privacyMode if featureFlags.privacyMode was false', (done) => { + const oldStorage = { + 'meta': {}, + 'data': { + 'PreferencesController': { + 'featureFlags': { + 'privacyMode': false, + }, + }, + }, + } + + migration34.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data.PreferencesController, { + 'migratedPrivacyMode': true, + 'featureFlags': { + 'privacyMode': true, + }, + }) + done() + }) + .catch(done) + }) + + it('should NOT change any state if migratedPrivacyMode is already set to true', (done) => { + const oldStorage = { + 'meta': {}, + 'data': { + 'PreferencesController': { + 'migratedPrivacyMode': true, + 'featureFlags': { + 'privacyMode': true, + }, + }, + }, + } + + migration34.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data, oldStorage.data) + done() + }) + .catch(done) + }) + + it('should NOT change any state if migratedPrivacyMode is already set to false', (done) => { + const oldStorage = { + 'meta': {}, + 'data': { + 'PreferencesController': { + 'migratedPrivacyMode': false, + 'featureFlags': { + 'privacyMode': true, + }, + }, + }, + } + + migration34.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data, oldStorage.data) + done() + }) + .catch(done) + }) + + it('should NOT change any state if PreferencesController is missing', (done) => { + const oldStorage = { + 'meta': {}, + 'data': {}, + } + + migration34.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data, oldStorage.data) + done() + }) + .catch(done) + }) + + it('should NOT change any state if featureFlags.privacyMode is already true', (done) => { + const oldStorage = { + 'meta': {}, + 'data': { + 'PreferencesController': { + 'featureFlags': { + 'privacyMode': true, + }, + }, + }, + } + + migration34.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data, oldStorage.data) + done() + }) + .catch(done) + }) +}) -- cgit From bb87a0b92ce2392ef0d0dc173fb094513ddb10f7 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 2 Aug 2019 10:28:25 -0230 Subject: Add migration to remove `seedWords` state (#6937) The `seedWords` state was removed from the PreferencesController recently in #6920. That state hadn't been used in some time, and there was a long period during which `seedWords` was periodically scrubbed from the state, so it's highly unlikely that it still exists in state for most users. It's hard to guarantee that it _doesn't_ though, especially if a user hasn't opened MetaMask in a few months. --- test/unit/migrations/035-test.js | 96 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 test/unit/migrations/035-test.js (limited to 'test/unit') diff --git a/test/unit/migrations/035-test.js b/test/unit/migrations/035-test.js new file mode 100644 index 000000000..a6ab09864 --- /dev/null +++ b/test/unit/migrations/035-test.js @@ -0,0 +1,96 @@ +const assert = require('assert') +const migration35 = require('../../../app/scripts/migrations/035') + +describe('migration #35', () => { + it('should update the version metadata', (done) => { + const oldStorage = { + meta: { + version: 34, + }, + data: {}, + } + + migration35.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.meta, { + 'version': 35, + }) + done() + }) + .catch(done) + }) + + it('should delete seedWords', (done) => { + const oldStorage = { + meta: {}, + data: { + PreferencesController: { + seedWords: 'seed words', + }, + }, + } + + migration35.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data.PreferencesController, {}) + done() + }) + .catch(done) + }) + + it('should delete falsy seedWords', (done) => { + const oldStorage = { + meta: {}, + data: { + PreferencesController: { + seedWords: '', + }, + }, + } + + migration35.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data.PreferencesController, {}) + done() + }) + .catch(done) + }) + + it('should leave state without seedWords unchanged', (done) => { + const oldStorage = { + meta: {}, + data: { + PreferencesController: { + frequentRpcListDetail: [], + currentAccountTab: 'history', + accountTokens: {}, + assetImages: {}, + tokens: [], + suggestedTokens: {}, + useBlockie: false, + knownMethodData: {}, + participateInMetaMetrics: null, + firstTimeFlowType: null, + currentLocale: 'en', + identities: {}, + lostIdentities: {}, + forgottenPassword: false, + preferences: { + useNativeCurrencyAsPrimaryCurrency: true, + }, + completedOnboarding: false, + migratedPrivacyMode: false, + metaMetricsId: null, + metaMetricsSendCount: 0, + }, + }, + } + + migration35.migrate(oldStorage) + .then((newStorage) => { + assert.deepEqual(newStorage.data, oldStorage.data) + done() + }) + .catch(done) + }) +}) -- cgit