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/ui/app/actions.spec.js | 243 +---------------------------- test/unit/ui/app/reducers/app.spec.js | 13 -- test/unit/ui/app/reducers/metamask.spec.js | 36 ----- 3 files changed, 2 insertions(+), 290 deletions(-) (limited to 'test/unit/ui/app') 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