1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/test/stub/provider.js

38 lines
946 B
JavaScript
Raw Normal View History

2017-08-09 00:30:03 +02:00
const JsonRpcEngine = require('json-rpc-engine')
const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold')
module.exports = {
createEngineForTestData,
providerFromEngine,
scaffoldMiddleware,
2018-01-14 23:00:59 +01:00
createEthJsQueryStub,
createStubedProvider,
2017-08-09 00:30:03 +02:00
}
function createEngineForTestData () {
return new JsonRpcEngine()
}
function providerFromEngine (engine) {
const provider = { sendAsync: engine.handle.bind(engine) }
return provider
}
2018-01-14 23:00:59 +01:00
function createEthJsQueryStub (stubProvider) {
return new Proxy({}, {
get: (obj, method) => {
return (...params) => {
return new Promise((resolve, reject) => {
stubProvider.sendAsync({ method: `eth_${method}`, params }, (err, ress) => resolve(ress.result))
})
}
},
})
}
2017-08-09 00:30:03 +02:00
function createStubedProvider (resultStub) {
const engine = createEngineForTestData()
engine.push(scaffoldMiddleware(resultStub))
return providerFromEngine(engine)
}