1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
var assert = require('assert')
var KeyringController = require('../../app/scripts/keyring-controller')
var configManagerGen = require('../lib/mock-config-manager')
const ethUtil = require('ethereumjs-util')
const async = require('async')
const mockEncryptor = require('../lib/mock-encryptor')
const MockSimpleKeychain = require('../lib/mock-simple-keychain')
const sinon = require('sinon')
describe('KeyringController', function() {
let keyringController
let password = 'password123'
let entropy = 'entripppppyy duuude'
let seedWords
let accounts = []
let originalKeystore
beforeEach(function(done) {
this.sinon = sinon.sandbox.create()
window.localStorage = {} // Hacking localStorage support into JSDom
keyringController = new KeyringController({
configManager: configManagerGen(),
ethStore: {
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
},
})
// Stub out the browser crypto for a mock encryptor.
// Browser crypto is tested in the integration test suite.
keyringController.encryptor = mockEncryptor
keyringController.createNewVault(password, null, function (err, state) {
done()
})
})
afterEach(function() {
// Cleanup mocks
this.sinon.restore()
})
describe('#createNewVault', function () {
it('should set a vault on the configManager', function(done) {
keyringController.configManager.setVault(null)
assert(!keyringController.configManager.getVault(), 'no previous vault')
keyringController.createNewVault(password, null, function (err, state) {
assert.ifError(err)
const vault = keyringController.configManager.getVault()
assert(vault, 'vault created')
done()
})
})
})
describe('#restoreKeyring', function(done) {
it(`should pass a keyring's serialized data back to the correct type.`, function() {
keyringController.keyringTypes = [ MockSimpleKeychain ]
const mockSerialized = {
type: MockSimpleKeychain.type(),
data: [ '0x123456null788890abcdef' ],
}
const mock = this.sinon.mock(keyringController)
mock.expects('loadBalanceAndNickname')
.exactly(1)
var keyring = keyringController.restoreKeyring(0, mockSerialized)
assert.equal(keyring.wallets.length, 1, 'one wallet restored')
mock.verify()
})
})
})
|