2017-08-09 00:30:03 +02:00
|
|
|
const JsonRpcEngine = require('json-rpc-engine')
|
|
|
|
const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold')
|
2018-01-18 06:43:34 +01:00
|
|
|
const TestBlockchain = require('eth-block-tracker/test/util/testBlockMiddleware')
|
2017-08-09 00:30:03 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
createEngineForTestData,
|
|
|
|
providerFromEngine,
|
|
|
|
scaffoldMiddleware,
|
2018-01-18 06:43:34 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-01-18 06:43:34 +01:00
|
|
|
function createTestProviderTools (opts = {}) {
|
2017-08-09 00:30:03 +02:00
|
|
|
const engine = createEngineForTestData()
|
2018-01-18 06:43:34 +01:00
|
|
|
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
|
|
|
}
|