mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Fixed tests
This commit is contained in:
parent
fa7e466559
commit
122018a96a
@ -1,4 +1,5 @@
|
||||
const urlUtil = require('url')
|
||||
const extend = require('xtend')
|
||||
const Dnode = require('dnode')
|
||||
const eos = require('end-of-stream')
|
||||
const PortStream = require('./lib/port-stream.js')
|
||||
@ -22,7 +23,7 @@ const controller = new MetamaskController({
|
||||
})
|
||||
const idStore = controller.idStore
|
||||
|
||||
function unlockAccountMessage() {
|
||||
function unlockAccountMessage () {
|
||||
createUnlockRequestNotification({
|
||||
title: 'Account Unlock Request',
|
||||
})
|
||||
@ -37,7 +38,7 @@ function showUnconfirmedMessage (msgParams, msgId) {
|
||||
})
|
||||
}
|
||||
|
||||
function showUnconfirmedTx(txParams, txData, onTxDoneCb) {
|
||||
function showUnconfirmedTx (txParams, txData, onTxDoneCb) {
|
||||
createTxNotification({
|
||||
title: 'New Unsigned Transaction',
|
||||
txParams: txParams,
|
||||
@ -89,7 +90,7 @@ function setupControllerConnection (stream) {
|
||||
var api = controller.getApi()
|
||||
var dnode = Dnode(api)
|
||||
stream.pipe(dnode).pipe(stream)
|
||||
dnode.on('remote', function() {
|
||||
dnode.on('remote', () => {
|
||||
// push updates to popup
|
||||
controller.ethStore.on('update', controller.sendUpdate)
|
||||
idStore.on('update', controller.sendUpdate)
|
||||
@ -99,7 +100,6 @@ function setupControllerConnection (stream) {
|
||||
controller.ethStore.removeListener('update', controller.sendUpdate)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1,5 +1,4 @@
|
||||
const Migrator = require('pojo-migrator')
|
||||
const extend = require('xtend')
|
||||
const MetamaskConfig = require('../config.js')
|
||||
const migrations = require('./migrations')
|
||||
|
||||
|
@ -43,7 +43,10 @@ function IdentityStore (opts = {}) {
|
||||
|
||||
IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
|
||||
delete this._keyStore
|
||||
this.configManager.clearWallet()
|
||||
if (this.configManager) {
|
||||
this.configManager.clearWallet()
|
||||
}
|
||||
|
||||
this._createIdmgmt(password, null, entropy, (err) => {
|
||||
if (err) return cb(err)
|
||||
|
||||
@ -439,7 +442,7 @@ IdentityStore.prototype._createIdmgmt = function (password, seed, entropy, cb) {
|
||||
keyStore: keyStore,
|
||||
derivedKey: derivedKey,
|
||||
hdPathSTring: this.hdPathString,
|
||||
this.configManager,
|
||||
configManager: this.configManager,
|
||||
})
|
||||
|
||||
cb()
|
||||
|
@ -13,11 +13,13 @@ class MetamaskController {
|
||||
|
||||
constructor (opts) {
|
||||
this.configManager = new ConfigManager(opts)
|
||||
this.idStore = new IdentityStore({ configManager })
|
||||
this.messageManager = messageManager
|
||||
this.provider = this.initializeProvider(opts)
|
||||
this.ethStore = new EthStore(this.provider)
|
||||
this.idStore.setStore(this.ethStore)
|
||||
this.idStore = new IdentityStore({
|
||||
configManager: this.configManager,
|
||||
ethStore: this.ethStore,
|
||||
})
|
||||
this.messageManager = messageManager
|
||||
this.publicConfigStore = this.initPublicConfigStore()
|
||||
}
|
||||
|
||||
@ -203,7 +205,7 @@ class MetamaskController {
|
||||
}
|
||||
|
||||
setupPublicConfig (stream) {
|
||||
var storeStream = publicConfigStore.createStream()
|
||||
var storeStream = this.publicConfigStore.createStream()
|
||||
stream.pipe(storeStream).pipe(stream)
|
||||
}
|
||||
|
||||
@ -223,7 +225,7 @@ class MetamaskController {
|
||||
// config
|
||||
//
|
||||
|
||||
function agreeToDisclaimer (cb) {
|
||||
agreeToDisclaimer (cb) {
|
||||
try {
|
||||
this.configManager.setConfirmed(true)
|
||||
cb()
|
||||
@ -233,23 +235,22 @@ class MetamaskController {
|
||||
}
|
||||
|
||||
// called from popup
|
||||
function setRpcTarget (rpcTarget) {
|
||||
setRpcTarget (rpcTarget) {
|
||||
this.configManager.setRpcTarget(rpcTarget)
|
||||
chrome.runtime.reload()
|
||||
idStore.getNetwork()
|
||||
this.idStore.getNetwork()
|
||||
}
|
||||
|
||||
function setProviderType (type) {
|
||||
setProviderType (type) {
|
||||
this.configManager.setProviderType(type)
|
||||
chrome.runtime.reload()
|
||||
idStore.getNetwork()
|
||||
this.idStore.getNetwork()
|
||||
}
|
||||
|
||||
function useEtherscanProvider () {
|
||||
useEtherscanProvider () {
|
||||
this.configManager.useEtherscanProvider()
|
||||
chrome.runtime.reload()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function noop () {}
|
||||
|
57
test/lib/mock-config-manager.js
Normal file
57
test/lib/mock-config-manager.js
Normal file
@ -0,0 +1,57 @@
|
||||
var ConfigManager = require('../../app/scripts/lib/config-manager')
|
||||
const STORAGE_KEY = 'metamask-persistance-key'
|
||||
const extend = require('xtend')
|
||||
|
||||
module.exports = function() {
|
||||
return new ConfigManager({ loadData, setData })
|
||||
}
|
||||
|
||||
function loadData () {
|
||||
var oldData = getOldStyleData()
|
||||
var newData
|
||||
try {
|
||||
newData = JSON.parse(window.localStorage[STORAGE_KEY])
|
||||
} catch (e) {}
|
||||
|
||||
var data = extend({
|
||||
meta: {
|
||||
version: 0,
|
||||
},
|
||||
data: {
|
||||
config: {
|
||||
provider: {
|
||||
type: 'testnet',
|
||||
},
|
||||
},
|
||||
},
|
||||
}, oldData || null, newData || null)
|
||||
return data
|
||||
}
|
||||
|
||||
function getOldStyleData () {
|
||||
var config, wallet, seedWords
|
||||
|
||||
var result = {
|
||||
meta: { version: 0 },
|
||||
data: {},
|
||||
}
|
||||
|
||||
try {
|
||||
config = JSON.parse(window.localStorage['config'])
|
||||
result.data.config = config
|
||||
} catch (e) {}
|
||||
try {
|
||||
wallet = JSON.parse(window.localStorage['lightwallet'])
|
||||
result.data.wallet = wallet
|
||||
} catch (e) {}
|
||||
try {
|
||||
seedWords = window.localStorage['seedWords']
|
||||
result.data.seedWords = seedWords
|
||||
} catch (e) {}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function setData (data) {
|
||||
window.localStorage[STORAGE_KEY] = JSON.stringify(data)
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
var assert = require('assert')
|
||||
var ConfigManager = require('../../app/scripts/lib/config-manager')
|
||||
const extend = require('xtend')
|
||||
const STORAGE_KEY = 'metamask-persistance-key'
|
||||
var configManagerGen = require('../lib/mock-config-manager')
|
||||
var configManager
|
||||
|
||||
describe('config-manager', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
window.localStorage = {} // Hacking localStorage support into JSDom
|
||||
configManager = new ConfigManager()
|
||||
configManager = configManagerGen()
|
||||
})
|
||||
|
||||
describe('confirmation', function() {
|
||||
@ -209,3 +211,4 @@ describe('config-manager', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
var assert = require('assert')
|
||||
var IdentityStore = require('../../app/scripts/lib/idStore')
|
||||
var configManagerGen = require('../lib/mock-config-manager')
|
||||
|
||||
describe('IdentityStore', function() {
|
||||
|
||||
@ -15,6 +16,7 @@ describe('IdentityStore', function() {
|
||||
window.localStorage = {} // Hacking localStorage support into JSDom
|
||||
|
||||
idStore = new IdentityStore({
|
||||
configManager: configManagerGen(),
|
||||
ethStore: {
|
||||
addAccount(acct) { accounts.push(acct) },
|
||||
},
|
||||
@ -34,6 +36,7 @@ describe('IdentityStore', function() {
|
||||
window.localStorage = {} // Hacking localStorage support into JSDom
|
||||
|
||||
idStore = new IdentityStore({
|
||||
configManager: configManagerGen(),
|
||||
ethStore: {
|
||||
addAccount(acct) { newAccounts.push(acct) },
|
||||
},
|
||||
@ -65,6 +68,7 @@ describe('IdentityStore', function() {
|
||||
window.localStorage = {} // Hacking localStorage support into JSDom
|
||||
|
||||
idStore = new IdentityStore({
|
||||
configManager: configManagerGen(),
|
||||
ethStore: {
|
||||
addAccount(acct) { accounts.push(acct) },
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user