mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
tx cont - add argument for provider constructor
This commit is contained in:
parent
5b9a6bd367
commit
4445ba1569
@ -28,9 +28,9 @@ module.exports = class NetworkController extends EventEmitter {
|
||||
this._provider = provider
|
||||
}
|
||||
|
||||
initializeProvider (opts) {
|
||||
initializeProvider (opts, providerContructor = MetaMaskProvider) {
|
||||
this.providerInit = opts
|
||||
this._provider = MetaMaskProvider(opts)
|
||||
this._provider = providerContructor(opts)
|
||||
this._proxy = new Proxy(this._provider, {
|
||||
get: (obj, name) => {
|
||||
if (name === 'on') return this._on.bind(this)
|
||||
@ -38,6 +38,7 @@ module.exports = class NetworkController extends EventEmitter {
|
||||
},
|
||||
set: (obj, name, value) => {
|
||||
this._provider[name] = value
|
||||
return value
|
||||
},
|
||||
})
|
||||
this.provider.on('block', this._logBlock.bind(this))
|
||||
|
@ -3,6 +3,9 @@ const NetworkController = require('../../app/scripts/controllers/network')
|
||||
|
||||
describe('# Network Controller', function () {
|
||||
let networkController
|
||||
const networkControllerProviderInit = {
|
||||
getAccounts: () => {},
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
networkController = new NetworkController({
|
||||
@ -10,26 +13,13 @@ describe('# Network Controller', function () {
|
||||
type: 'rinkeby',
|
||||
},
|
||||
})
|
||||
// stub out provider
|
||||
networkController._provider = new Proxy({}, {
|
||||
get: (obj, name) => {
|
||||
return () => {}
|
||||
},
|
||||
})
|
||||
networkController.providerInit = {
|
||||
getAccounts: () => {},
|
||||
}
|
||||
|
||||
networkController.ethQuery = new Proxy({}, {
|
||||
get: (obj, name) => {
|
||||
return () => {}
|
||||
},
|
||||
})
|
||||
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor)
|
||||
})
|
||||
describe('network', function () {
|
||||
describe('#provider', function () {
|
||||
it('provider should be updatable without reassignment', function () {
|
||||
networkController.initializeProvider(networkController.providerInit)
|
||||
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor)
|
||||
const provider = networkController.provider
|
||||
networkController._provider = {test: true}
|
||||
assert.ok(provider.test)
|
||||
@ -75,3 +65,19 @@ describe('# Network Controller', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function dummyProviderConstructor() {
|
||||
return {
|
||||
// provider
|
||||
sendAsync: noop,
|
||||
// block tracker
|
||||
start: noop,
|
||||
stop: noop,
|
||||
on: noop,
|
||||
addListener: noop,
|
||||
once: noop,
|
||||
removeAllListeners: noop,
|
||||
}
|
||||
}
|
||||
|
||||
function noop() {}
|
Loading…
Reference in New Issue
Block a user