1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/test/unit/idStore-migration-test.js

84 lines
2.7 KiB
JavaScript
Raw Normal View History

2016-10-28 22:26:14 +02:00
const async = require('async')
const assert = require('assert')
2017-01-25 04:47:00 +01:00
const ObservableStore = require('obs-store')
2016-10-28 22:26:14 +02:00
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
const ConfigManager = require('../../app/scripts/lib/config-manager')
const firstTimeState = require('../../app/scripts/first-time-state')
2016-10-28 22:26:14 +02:00
const delegateCallCode = require('../lib/example-code.json').delegateCallCode
const clone = require('clone')
2016-10-28 22:26:14 +02:00
// The old way:
const IdentityStore = require('../../app/scripts/lib/idStore')
const STORAGE_KEY = 'metamask-config'
2016-10-28 22:26:14 +02:00
// The new ways:
var KeyringController = require('../../app/scripts/keyring-controller')
const mockEncryptor = require('../lib/mock-encryptor')
const MockSimpleKeychain = require('../lib/mock-simple-keychain')
const sinon = require('sinon')
const mockVault = {
seed: 'picnic injury awful upper eagle junk alert toss flower renew silly vague',
account: '0x5d8de92c205279c10e5669f797b853ccef4f739a',
}
const badVault = {
seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release',
}
2016-10-28 22:26:14 +02:00
describe('IdentityStore to KeyringController migration', function() {
// The stars of the show:
let idStore, keyringController, seedWords, configManager
2016-10-28 22:26:14 +02:00
let password = 'password123'
let entropy = 'entripppppyy duuude'
let accounts = []
let newAccounts = []
let originalKeystore
// This is a lot of setup, I know!
// We have to create an old style vault, populate it,
// and THEN create a new one, before we can run tests on it.
beforeEach(function(done) {
this.sinon = sinon.sandbox.create()
let store = new ObservableStore(clone(firstTimeState))
2017-01-12 04:26:56 +01:00
configManager = new ConfigManager({ store })
2016-10-28 22:26:14 +02:00
idStore = new IdentityStore({
configManager: configManager,
2016-10-28 22:26:14 +02:00
ethStore: {
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
del(acct) { delete accounts[acct] },
},
})
idStore._createVault(password, mockVault.seed, (err) => {
2016-10-28 22:26:14 +02:00
assert.ifError(err, 'createNewVault threw error')
originalKeystore = idStore._idmgmt.keyStore
idStore.setLocked((err) => {
2016-10-28 22:26:14 +02:00
assert.ifError(err, 'createNewVault threw error')
keyringController = new KeyringController({
configManager,
ethStore: {
addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) },
del(acct) { delete newAccounts[acct] },
2016-10-28 22:26:14 +02:00
},
txManager: {
getTxList: () => [],
getUnapprovedTxList: () => []
},
2016-10-28 22:26:14 +02:00
})
// Stub out the browser crypto for a mock encryptor.
// Browser crypto is tested in the integration test suite.
keyringController.encryptor = mockEncryptor
done()
})
})
})
})