1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/test/stub/provider.js

32 lines
910 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')
const TestBlockchain = require('eth-block-tracker/test/util/testBlockMiddleware')
2017-08-09 00:30:03 +02:00
module.exports = {
createEngineForTestData,
providerFromEngine,
scaffoldMiddleware,
createTestProviderTools,
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
}
function createTestProviderTools (opts = {}) {
2017-08-09 00:30:03 +02:00
const engine = createEngineForTestData()
const testBlockchain = new TestBlockchain()
// handle provided hooks
engine.push(scaffoldMiddleware(opts.scaffold || {}))
// handle block tracker methods
engine.push(testBlockchain.createMiddleware())
const provider = providerFromEngine(engine)
return { provider, engine, testBlockchain }
2018-01-18 04:44:11 +01:00
}