mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix clearing of account cache on vault restore
This commit is contained in:
parent
784856532c
commit
c3d1404e72
@ -51,6 +51,7 @@ IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
|
|||||||
this.configManager.setData({})
|
this.configManager.setData({})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.purgeCache()
|
||||||
this._createVault(password, null, entropy, (err) => {
|
this._createVault(password, null, entropy, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
|
|
||||||
@ -59,7 +60,6 @@ IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
|
|||||||
this.configManager.setShowSeedWords(true)
|
this.configManager.setShowSeedWords(true)
|
||||||
var seedWords = this._idmgmt.getSeed()
|
var seedWords = this._idmgmt.getSeed()
|
||||||
|
|
||||||
|
|
||||||
cb(null, seedWords)
|
cb(null, seedWords)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -72,6 +72,8 @@ IdentityStore.prototype.recoverSeed = function (cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.recoverFromSeed = function (password, seed, cb) {
|
IdentityStore.prototype.recoverFromSeed = function (password, seed, cb) {
|
||||||
|
this.purgeCache()
|
||||||
|
|
||||||
this._createVault(password, seed, null, (err) => {
|
this._createVault(password, seed, null, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
|
|
||||||
@ -500,8 +502,10 @@ IdentityStore.prototype._createIdMgmt = function (derivedKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.purgeCache = function () {
|
IdentityStore.prototype.purgeCache = function () {
|
||||||
this._getAddresses().forEach((address) => {
|
this._currentState.identities = {}
|
||||||
this._ethStore.del(ethUtil.addHexPrefix(address))
|
var accounts = Object.keys(this._ethStore._currentState.accounts)
|
||||||
|
accounts.forEach((address) => {
|
||||||
|
this._ethStore.removeAccount(address)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ describe('IdentityStore', function() {
|
|||||||
const salt = 'lightwalletSalt'
|
const salt = 'lightwalletSalt'
|
||||||
|
|
||||||
let password = 'secret!'
|
let password = 'secret!'
|
||||||
let accounts = []
|
let accounts = {}
|
||||||
let idStore
|
let idStore
|
||||||
|
|
||||||
var assertions = [
|
var assertions = [
|
||||||
@ -99,25 +99,22 @@ describe('IdentityStore', function() {
|
|||||||
idStore = new IdentityStore({
|
idStore = new IdentityStore({
|
||||||
configManager: configManagerGen(),
|
configManager: configManagerGen(),
|
||||||
ethStore: {
|
ethStore: {
|
||||||
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
|
addAccount(acct) { accounts[acct] = acct},
|
||||||
|
del(acct) { delete accounts[acct] },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
accounts = []
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should enforce seed compliance with TestRPC', function (done) {
|
it('should enforce seed compliance with TestRPC', function (done) {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
const tests = assertions.map((assertion) => {
|
const tests = assertions.map((assertion) => {
|
||||||
return function (cb) {
|
return function (cb) {
|
||||||
accounts = []
|
|
||||||
idStore.recoverFromSeed(password, assertion.seed, (err) => {
|
idStore.recoverFromSeed(password, assertion.seed, (err) => {
|
||||||
assert.ifError(err)
|
assert.ifError(err)
|
||||||
|
|
||||||
var received = accounts[0].toLowerCase()
|
|
||||||
var expected = assertion.account.toLowerCase()
|
var expected = assertion.account.toLowerCase()
|
||||||
|
var received = accounts[expected].toLowerCase()
|
||||||
assert.equal(received, expected)
|
assert.equal(received, expected)
|
||||||
|
|
||||||
idStore.tryPassword(password, function (err) {
|
idStore.tryPassword(password, function (err) {
|
||||||
@ -127,6 +124,7 @@ describe('IdentityStore', function() {
|
|||||||
idStore.submitPassword(password, function(err, account) {
|
idStore.submitPassword(password, function(err, account) {
|
||||||
assert.ifError(err)
|
assert.ifError(err)
|
||||||
assert.equal(account, expected)
|
assert.equal(account, expected)
|
||||||
|
assert.equal(Object.keys(idStore._getAddresses()).length, 1, 'only one account on restore')
|
||||||
cb()
|
cb()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user