Merge pull request #2851 from MetaMask/i2812-seedworderrorfix

Fix condition where failing seed word checks would infinite-spin future attempts.
This commit is contained in:
Kevin Serrano 2018-01-08 11:43:43 -08:00 committed by GitHub
commit 0cf5c22178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 6 deletions

View File

@ -7,6 +7,7 @@
- Fix bug that prevented updating custom token details. - Fix bug that prevented updating custom token details.
- No longer mark long-pending transactions as failed, since we now have button to retry with higher gas. - No longer mark long-pending transactions as failed, since we now have button to retry with higher gas.
- Fix rounding error when specifying an ether amount that has too much precision. - Fix rounding error when specifying an ether amount that has too much precision.
- Fix bug where incorrectly inputting seed phrase would prevent any future attempts from succeeding.
## 3.13.3 2017-12-14 ## 3.13.3 2017-12-14

View File

@ -536,10 +536,15 @@ module.exports = class MetamaskController extends EventEmitter {
async createNewVaultAndRestore (password, seed) { async createNewVaultAndRestore (password, seed) {
const release = await this.createVaultMutex.acquire() const release = await this.createVaultMutex.acquire()
const vault = await this.keyringController.createNewVaultAndRestore(password, seed) try {
this.selectFirstIdentity(vault) const vault = await this.keyringController.createNewVaultAndRestore(password, seed)
release() this.selectFirstIdentity(vault)
return vault release()
return vault
} catch (err) {
release()
throw err
}
} }
selectFirstIdentity (vault) { selectFirstIdentity (vault) {

View File

@ -41,10 +41,12 @@ describe('MetaMaskController', function () {
beforeEach(function () { beforeEach(function () {
sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain') sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain')
sinon.spy(metamaskController.keyringController, 'createNewVaultAndRestore')
}) })
afterEach(function () { afterEach(function () {
metamaskController.keyringController.createNewVaultAndKeychain.restore() metamaskController.keyringController.createNewVaultAndKeychain.restore()
metamaskController.keyringController.createNewVaultAndRestore.restore()
}) })
describe('#getGasPrice', function () { describe('#getGasPrice', function () {
@ -74,9 +76,9 @@ describe('MetaMaskController', function () {
describe('#createNewVaultAndKeychain', function () { describe('#createNewVaultAndKeychain', function () {
it('can only create new vault on keyringController once', async function () { it('can only create new vault on keyringController once', async function () {
const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity')
const password = 'a-fake-password' const password = 'a-fake-password'
const first = await metamaskController.createNewVaultAndKeychain(password) const first = await metamaskController.createNewVaultAndKeychain(password)
@ -87,6 +89,22 @@ describe('MetaMaskController', function () {
selectStub.reset() selectStub.reset()
}) })
}) })
describe('#createNewVaultAndRestore', function () {
it('should be able to call newVaultAndRestore despite a mistake.', async function () {
// const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity')
const password = 'what-what-what'
const wrongSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadiu'
const rightSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium'
const first = await metamaskController.createNewVaultAndRestore(password, wrongSeed)
.catch((e) => {
return
})
const second = await metamaskController.createNewVaultAndRestore(password, rightSeed)
assert(metamaskController.keyringController.createNewVaultAndRestore.calledTwice)
})
})
}) })
}) })

View File

@ -149,4 +149,8 @@ RestoreVaultScreen.prototype.createNewVaultAndRestore = function () {
this.warning = null this.warning = null
this.props.dispatch(actions.displayWarning(this.warning)) this.props.dispatch(actions.displayWarning(this.warning))
this.props.dispatch(actions.createNewVaultAndRestore(password, seed)) this.props.dispatch(actions.createNewVaultAndRestore(password, seed))
.catch((err) => {
log.error(err.message)
})
} }