A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/test/unit/idStore-test.js

127 lines
3.6 KiB

var assert = require('assert')
var IdentityStore = require('../../app/scripts/lib/idStore')
9 years ago
var configManagerGen = require('../lib/mock-config-manager')
const ethUtil = require('ethereumjs-util')
const async = require('async')
describe('IdentityStore', function() {
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({
9 years ago
configManager: configManagerGen(),
9 years ago
ethStore: {
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
9 years ago
},
})
idStore.createNewVault(password, entropy, (err, seeds) => {
assert.ifError(err, 'createNewVault threw error')
seedWords = seeds
originalKeystore = idStore._idmgmt.keyStore
done()
})
})
describe('#recoverFromSeed', function() {
let newAccounts = []
before(function() {
window.localStorage = {} // Hacking localStorage support into JSDom
idStore = new IdentityStore({
9 years ago
configManager: configManagerGen(),
9 years ago
ethStore: {
addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) },
9 years ago
},
})
})
it('should return the expected keystore', function (done) {
idStore.recoverFromSeed(password, seedWords, (err) => {
assert.ifError(err)
let newKeystore = idStore._idmgmt.keyStore
assert.equal(newAccounts[0], accounts[0])
done()
})
})
})
})
describe('#recoverFromSeed BIP44 compliance', function() {
8 years ago
const salt = 'lightwalletSalt'
let password = 'secret!'
let accounts = []
let idStore
var assertions = [
{
seed: 'picnic injury awful upper eagle junk alert toss flower renew silly vague',
account: '0x5d8de92c205279c10e5669f797b853ccef4f739a',
},
{
seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release',
account: '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9',
},
{
seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing',
account: '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2',
},
{
seed: 'recycle tag bird palace blue village anxiety census cook soldier example music',
account: '0xab34a45920afe4af212b96ec51232aaa6a33f663',
},
{
seed: 'half glimpse tape cute harvest sweet bike voyage actual floor poet lazy',
account: '0x28e9044597b625ac4beda7250011670223de43b2',
}
]
before(function() {
window.localStorage = {} // Hacking localStorage support into JSDom
idStore = new IdentityStore({
9 years ago
configManager: configManagerGen(),
9 years ago
ethStore: {
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
},
})
})
beforeEach(function() {
accounts = []
})
it('should enforce seed compliance with TestRPC', function (done) {
const tests = assertions.map((assertion) => {
return function (cb) {
idStore.recoverFromSeed(password, assertion.seed, (err) => {
assert.ifError(err)
console.log('comparing %s to %s', accounts[0], assertion.account)
assert.equal(accounts[0], assertion.account)
cb()
})
}
})
async.series(tests, function(err, results) {
8 years ago
assert.ifError(err)
done()
})
})
})
})