aboutsummaryrefslogtreecommitdiffstats
path: root/test/stub/provider.js
blob: 8a306f6d94b8c5332e738f1ff1f07da95f364a7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)
}