1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

create a provider stub

This commit is contained in:
frankiebee 2017-08-08 18:30:03 -04:00
parent 3a2190ec3c
commit be4011c310

25
test/stub/provider.js Normal file
View File

@ -0,0 +1,25 @@
const JsonRpcEngine = require('json-rpc-engine')
const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold')
module.exports = {
createEngineForTestData,
providerFromEngine,
scaffoldMiddleware,
createStubedProvider
}
function createEngineForTestData () {
return new JsonRpcEngine()
}
function providerFromEngine (engine) {
const provider = { sendAsync: engine.handle.bind(engine) }
return provider
}
function createStubedProvider (resultStub) {
const engine = createEngineForTestData()
engine.push(scaffoldMiddleware(resultStub))
return providerFromEngine(engine)
}