2016-03-25 20:41:18 +01:00
|
|
|
var assert = require('assert')
|
2016-03-25 22:51:19 +01:00
|
|
|
var IdentityStore = require('../../app/scripts/lib/idStore')
|
2016-06-25 01:13:27 +02:00
|
|
|
var configManagerGen = require('../lib/mock-config-manager')
|
2016-03-25 01:51:46 +01:00
|
|
|
|
|
|
|
describe('IdentityStore', function() {
|
|
|
|
|
2016-03-25 20:41:18 +01:00
|
|
|
describe('#createNewVault', function () {
|
|
|
|
let idStore
|
|
|
|
let password = 'password123'
|
|
|
|
let entropy = 'entripppppyy duuude'
|
|
|
|
let seedWords
|
|
|
|
let accounts = []
|
|
|
|
let originalKeystore
|
|
|
|
|
|
|
|
before(function(done) {
|
|
|
|
window.localStorage = {} // Hacking localStorage support into JSDom
|
|
|
|
|
|
|
|
idStore = new IdentityStore({
|
2016-06-25 01:13:27 +02:00
|
|
|
configManager: configManagerGen(),
|
2016-04-28 03:14:59 +02:00
|
|
|
ethStore: {
|
|
|
|
addAccount(acct) { accounts.push(acct) },
|
|
|
|
},
|
2016-03-25 20:41:18 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
idStore.createNewVault(password, entropy, (err, seeds) => {
|
|
|
|
seedWords = seeds
|
|
|
|
originalKeystore = idStore._idmgmt.keyStore
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#recoverFromSeed', function() {
|
2016-03-25 23:38:20 +01:00
|
|
|
let newAccounts = []
|
2016-03-25 20:41:18 +01:00
|
|
|
|
|
|
|
before(function() {
|
|
|
|
window.localStorage = {} // Hacking localStorage support into JSDom
|
|
|
|
|
|
|
|
idStore = new IdentityStore({
|
2016-06-25 01:13:27 +02:00
|
|
|
configManager: configManagerGen(),
|
2016-04-28 03:14:59 +02:00
|
|
|
ethStore: {
|
|
|
|
addAccount(acct) { newAccounts.push(acct) },
|
|
|
|
},
|
2016-03-25 20:41:18 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-03-25 22:51:19 +01:00
|
|
|
it('should return the expected keystore', function (done) {
|
2016-03-25 20:41:18 +01:00
|
|
|
|
|
|
|
idStore.recoverFromSeed(password, seedWords, (err) => {
|
|
|
|
assert.ifError(err)
|
|
|
|
|
|
|
|
let newKeystore = idStore._idmgmt.keyStore
|
2016-03-25 23:38:20 +01:00
|
|
|
assert.equal(newAccounts[0], accounts[0])
|
2016-03-25 22:51:19 +01:00
|
|
|
done()
|
2016-03-25 20:41:18 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 22:51:19 +01:00
|
|
|
|
|
|
|
describe('#recoverFromSeed BIP44 compliance', function() {
|
|
|
|
let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague'
|
2016-03-25 23:38:20 +01:00
|
|
|
let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a'
|
|
|
|
|
2016-03-25 22:51:19 +01:00
|
|
|
let password = 'secret!'
|
|
|
|
let accounts = []
|
|
|
|
let idStore
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
window.localStorage = {} // Hacking localStorage support into JSDom
|
|
|
|
|
|
|
|
idStore = new IdentityStore({
|
2016-06-25 01:13:27 +02:00
|
|
|
configManager: configManagerGen(),
|
2016-04-28 03:14:59 +02:00
|
|
|
ethStore: {
|
|
|
|
addAccount(acct) { accounts.push(acct) },
|
2016-03-25 22:51:19 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the expected first account', function (done) {
|
|
|
|
|
|
|
|
idStore.recoverFromSeed(password, seedWords, (err) => {
|
|
|
|
assert.ifError(err)
|
|
|
|
|
|
|
|
let newKeystore = idStore._idmgmt.keyStore
|
|
|
|
assert.equal(accounts[0], firstAccount)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 20:41:18 +01:00
|
|
|
})
|