aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-09-28 01:44:52 +0800
committerGitHub <noreply@github.com>2017-09-28 01:44:52 +0800
commitca0dff06f5d9283e57b452dcc7e85c31b248b8aa (patch)
tree44243d257dfb7f787882578fa14df8f01900fb45
parent6ca519e97c4c282023ab6b7788715ff8d7ec8189 (diff)
parent1877c0766c1f3ab46ec89dad0200fb8f75f52bae (diff)
downloadtangerine-wallet-browser-ca0dff06f5d9283e57b452dcc7e85c31b248b8aa.tar.gz
tangerine-wallet-browser-ca0dff06f5d9283e57b452dcc7e85c31b248b8aa.tar.zst
tangerine-wallet-browser-ca0dff06f5d9283e57b452dcc7e85c31b248b8aa.zip
Merge pull request #2153 from MetaMask/BreakOutKeyringController
Break out keyring controller into separate module
-rw-r--r--app/scripts/metamask-controller.js2
-rw-r--r--app/scripts/migrations/_multi-keyring.js2
-rw-r--r--package.json4
-rw-r--r--test/unit/keyring-controller-test.js164
4 files changed, 3 insertions, 169 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 0f850b7f5..bbac5ed08 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -14,7 +14,7 @@ const createOriginMiddleware = require('./lib/createOriginMiddleware')
const createLoggerMiddleware = require('./lib/createLoggerMiddleware')
const createProviderMiddleware = require('./lib/createProviderMiddleware')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
-const KeyringController = require('./keyring-controller')
+const KeyringController = require('eth-keyring-controller')
const NetworkController = require('./controllers/network')
const PreferencesController = require('./controllers/preferences')
const CurrencyController = require('./controllers/currency')
diff --git a/app/scripts/migrations/_multi-keyring.js b/app/scripts/migrations/_multi-keyring.js
index 253aa3d9d..7a4578ea7 100644
--- a/app/scripts/migrations/_multi-keyring.js
+++ b/app/scripts/migrations/_multi-keyring.js
@@ -10,7 +10,7 @@ which we dont have access to at the time of this writing.
const ObservableStore = require('obs-store')
const ConfigManager = require('../../app/scripts/lib/config-manager')
const IdentityStoreMigrator = require('../../app/scripts/lib/idStore-migrator')
-const KeyringController = require('../../app/scripts/lib/keyring-controller')
+const KeyringController = require('eth-keyring-controller')
const password = 'obviously not correct'
diff --git a/package.json b/package.json
index 182ae9900..c3d086194 100644
--- a/package.json
+++ b/package.json
@@ -53,10 +53,8 @@
"async": "^2.5.0",
"await-semaphore": "^0.1.1",
"babel-runtime": "^6.23.0",
- "bip39": "^2.2.0",
"bluebird": "^3.5.0",
"bn.js": "^4.11.7",
- "browser-passworder": "^2.0.3",
"browserify-derequire": "^0.9.4",
"client-sw-ready-event": "^3.3.0",
"clone": "^2.1.1",
@@ -70,8 +68,8 @@
"ensnare": "^1.0.0",
"eth-bin-to-ops": "^1.0.1",
"eth-contract-metadata": "^1.1.4",
- "eth-hd-keyring": "^1.1.1",
"eth-json-rpc-filters": "^1.1.0",
+ "eth-keyring-controller": "^1.0.1",
"eth-phishing-detect": "^1.1.4",
"eth-query": "^2.1.2",
"eth-sig-util": "^1.2.2",
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
deleted file mode 100644
index 135edf365..000000000
--- a/test/unit/keyring-controller-test.js
+++ /dev/null
@@ -1,164 +0,0 @@
-const assert = require('assert')
-const KeyringController = require('../../app/scripts/keyring-controller')
-const configManagerGen = require('../lib/mock-config-manager')
-const ethUtil = require('ethereumjs-util')
-const BN = ethUtil.BN
-const mockEncryptor = require('../lib/mock-encryptor')
-const sinon = require('sinon')
-
-describe('KeyringController', function () {
- let keyringController
- const password = 'password123'
- const seedWords = 'puzzle seed penalty soldier say clay field arctic metal hen cage runway'
- const addresses = ['eF35cA8EbB9669A35c31b5F6f249A9941a812AC1'.toLowerCase()]
- const accounts = []
- // let originalKeystore
-
- beforeEach(function (done) {
- this.sinon = sinon.sandbox.create()
- window.localStorage = {} // Hacking localStorage support into JSDom
-
- keyringController = new KeyringController({
- configManager: configManagerGen(),
- txManager: {
- getTxList: () => [],
- getUnapprovedTxList: () => [],
- },
- accountTracker: {
- addAccount (acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
- },
- encryptor: mockEncryptor,
- })
-
- keyringController.createNewVaultAndKeychain(password)
- .then(function (newState) {
- newState
- done()
- })
- .catch((err) => {
- done(err)
- })
- })
-
- afterEach(function () {
- // Cleanup mocks
- this.sinon.restore()
- })
-
- describe('#createNewVaultAndKeychain', function () {
- this.timeout(10000)
-
- it('should set a vault on the configManager', function (done) {
- keyringController.store.updateState({ vault: null })
- assert(!keyringController.store.getState().vault, 'no previous vault')
- keyringController.createNewVaultAndKeychain(password)
- .then(() => {
- const vault = keyringController.store.getState().vault
- assert(vault, 'vault created')
- done()
- })
- .catch((reason) => {
- done(reason)
- })
- })
- })
-
- describe('#restoreKeyring', 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,
- numberOfAccounts: 1,
- },
- }
- const mock = this.sinon.mock(keyringController)
-
- mock.expects('getBalanceAndNickname')
- .exactly(1)
-
- 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) => {
- done(reason)
- })
- })
- })
-
- describe('#createNickname', function () {
- it('should add the address to the identities hash', function () {
- const fakeAddress = '0x12345678'
- keyringController.createNickname(fakeAddress)
- const identities = keyringController.memStore.getState().identities
- const identity = identities[fakeAddress]
- assert.equal(identity.address, fakeAddress)
- })
- })
-
- describe('#saveAccountLabel', function () {
- it('sets the nickname', function (done) {
- const account = addresses[0]
- var nick = 'Test nickname'
- const identities = keyringController.memStore.getState().identities
- identities[ethUtil.addHexPrefix(account)] = {}
- keyringController.memStore.updateState({ identities })
- keyringController.saveAccountLabel(account, nick)
- .then((label) => {
- try {
- assert.equal(label, nick)
- const persisted = keyringController.store.getState().walletNicknames[account]
- assert.equal(persisted, nick)
- done()
- } catch (err) {
- done()
- }
- })
- .catch((reason) => {
- done(reason)
- })
- })
- })
-
- describe('#getAccounts', function () {
- it('returns the result of getAccounts for each keyring', function (done) {
- keyringController.keyrings = [
- { getAccounts () { return Promise.resolve([1, 2, 3]) } },
- { getAccounts () { return Promise.resolve([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')
- })
- })
-})