aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/keyring-controller-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/keyring-controller-test.js')
-rw-r--r--test/unit/keyring-controller-test.js110
1 files changed, 72 insertions, 38 deletions
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index 0076d9ebe..37fd7175e 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -2,6 +2,7 @@ var assert = require('assert')
var KeyringController = require('../../app/scripts/keyring-controller')
var configManagerGen = require('../lib/mock-config-manager')
const ethUtil = require('ethereumjs-util')
+const BN = ethUtil.BN
const async = require('async')
const mockEncryptor = require('../lib/mock-encryptor')
const MockSimpleKeychain = require('../lib/mock-simple-keychain')
@@ -11,7 +12,6 @@ describe('KeyringController', function() {
let keyringController, state
let password = 'password123'
- let entropy = 'entripppppyy duuude'
let seedWords = 'puzzle seed penalty soldier say clay field arctic metal hen cage runway'
let addresses = ['eF35cA8EbB9669A35c31b5F6f249A9941a812AC1'.toLowerCase()]
let accounts = []
@@ -23,6 +23,10 @@ describe('KeyringController', function() {
keyringController = new KeyringController({
configManager: configManagerGen(),
+ txManager: {
+ getTxList: () => [],
+ getUnapprovedTxList: () => []
+ },
ethStore: {
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
},
@@ -32,8 +36,8 @@ describe('KeyringController', function() {
// Browser crypto is tested in the integration test suite.
keyringController.encryptor = mockEncryptor
- keyringController.createNewVaultAndKeychain(password, null, function (err, newState) {
- assert.ifError(err)
+ keyringController.createNewVaultAndKeychain(password)
+ .then(function (newState) {
state = newState
done()
})
@@ -50,43 +54,46 @@ describe('KeyringController', function() {
it('should set a vault on the configManager', function(done) {
keyringController.configManager.setVault(null)
assert(!keyringController.configManager.getVault(), 'no previous vault')
- keyringController.createNewVaultAndKeychain(password, null, (err, state) => {
- assert.ifError(err)
+ keyringController.createNewVaultAndKeychain(password)
+ .then(() => {
const vault = keyringController.configManager.getVault()
assert(vault, 'vault created')
done()
})
+ .catch((reason) => {
+ assert.ifError(reason)
+ done()
+ })
})
})
describe('#restoreKeyring', function() {
- it(`should pass a keyring's serialized data back to the correct type.`, function() {
+ it(`should pass a keyring's serialized data back to the correct type.`, function(done) {
const mockSerialized = {
type: 'HD Key Tree',
data: {
mnemonic: seedWords,
- n: 1,
+ numberOfAccounts: 1,
}
}
const mock = this.sinon.mock(keyringController)
- mock.expects('loadBalanceAndNickname')
+ mock.expects('getBalanceAndNickname')
.exactly(1)
- var keyring = keyringController.restoreKeyring(mockSerialized)
- assert.equal(keyring.wallets.length, 1, 'one wallet restored')
- assert.equal(keyring.getAccounts()[0], addresses[0])
- mock.verify()
- })
-
- })
-
- describe('#migrateAndGetKey', function() {
- it('should return the key for that password', function(done) {
- keyringController.migrateAndGetKey(password)
- .then((key) => {
- assert(key, 'a key is returned')
+ keyringController.restoreKeyring(mockSerialized)
+ .then((keyring) => {
+ assert.equal(keyring.wallets.length, 1, 'one wallet restored')
+ return keyring.getAccounts()
+ })
+ .then((accounts) => {
+ assert.equal(accounts[0], addresses[0])
+ mock.verify()
+ done()
+ })
+ .catch((reason) => {
+ assert.ifError(reason)
done()
})
})
@@ -106,14 +113,21 @@ describe('KeyringController', function() {
})
describe('#saveAccountLabel', function() {
- it ('sets the nickname', function() {
+ it ('sets the nickname', function(done) {
const account = addresses[0]
var nick = 'Test nickname'
- const label = keyringController.saveAccountLabel(account, nick)
- assert.equal(label, nick)
-
- const persisted = keyringController.configManager.nicknameForWallet(account)
- assert.equal(persisted, nick)
+ keyringController.identities[ethUtil.addHexPrefix(account)] = {}
+ keyringController.saveAccountLabel(account, nick)
+ .then((label) => {
+ assert.equal(label, nick)
+ const persisted = keyringController.configManager.nicknameForWallet(account)
+ assert.equal(persisted, nick)
+ done()
+ })
+ .catch((reason) => {
+ assert.ifError(reason)
+ done()
+ })
})
this.timeout(10000)
@@ -121,10 +135,8 @@ describe('KeyringController', function() {
const account = addresses[0]
var nick = 'Test nickname'
keyringController.configManager.setNicknameForWallet(account, nick)
- console.log('calling to restore')
- keyringController.createNewVaultAndRestore(password, seedWords, (err, state) => {
- console.dir({err})
- assert.ifError(err)
+ keyringController.createNewVaultAndRestore(password, seedWords)
+ .then((state) => {
const identity = keyringController.identities['0x' + account]
assert.equal(identity.name, nick)
@@ -132,24 +144,46 @@ describe('KeyringController', function() {
assert(accounts)
done()
})
+ .catch((reason) => {
+ assert.ifError(reason)
+ done()
+ })
})
})
describe('#getAccounts', function() {
it('returns the result of getAccounts for each keyring', function() {
keyringController.keyrings = [
- { getAccounts() { return [1,2,3] } },
- { getAccounts() { return [4,5,6] } },
+ { getAccounts() { return Promise.resolve([1,2,3]) } },
+ { getAccounts() { return Promise.resolve([4,5,6]) } },
]
- const result = keyringController.getAccounts()
- assert.deepEqual(result, [1,2,3,4,5,6])
+ keyringController.getAccounts()
+ .then((result) => {
+ assert.deepEqual(result, [1,2,3,4,5,6])
+ done()
+ })
})
})
-})
-
-
+ describe('#addGasBuffer', function() {
+ it('adds 100k gas buffer to estimates', function() {
+ const gas = '0x04ee59' // Actual estimated gas example
+ const tooBigOutput = '0x80674f9' // Actual bad output
+ const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
+ const correctBuffer = new BN('100000', 10)
+ const correct = bnGas.add(correctBuffer)
+ const tooBig = new BN(tooBigOutput, 16)
+ const result = keyringController.addGasBuffer(gas)
+ const bnResult = new BN(ethUtil.stripHexPrefix(result), 16)
+ assert.equal(result.indexOf('0x'), 0, 'included hex prefix')
+ assert(bnResult.gt(bnGas), 'Estimate increased in value.')
+ assert.equal(bnResult.sub(bnGas).toString(10), '100000', 'added 100k gas')
+ assert.equal(result, '0x' + correct.toString(16), 'Added the right amount')
+ assert.notEqual(result, tooBigOutput, 'not that bad estimate')
+ })
+ })
+})