forked from MetaMask/web3-provider-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.js
45 lines (35 loc) · 1.55 KB
/
basic.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const test = require('tape')
const ProviderEngine = require('../index.js')
const PassthroughProvider = require('./util/passthrough.js')
const FixtureProvider = require('../subproviders/fixture.js')
const TestBlockProvider = require('./util/block.js')
const createPayload = require('../util/create-payload.js')
const injectMetrics = require('./util/inject-metrics')
test('fallthrough test', function(t){
t.plan(8)
// handle nothing
var providerA = injectMetrics(new PassthroughProvider())
// handle "test_rpc"
var providerB = injectMetrics(new FixtureProvider({
test_rpc: true,
}))
// handle block requests
var providerC = injectMetrics(new TestBlockProvider())
var engine = new ProviderEngine()
engine.addProvider(providerA)
engine.addProvider(providerB)
engine.addProvider(providerC)
engine.start()
engine.sendAsync(createPayload({ method: 'test_rpc' }), function(err, response){
t.ifError(err, 'did not error')
t.ok(response, 'has response')
t.equal(providerA.getWitnessed('test_rpc').length, 1, 'providerA did see "test_rpc"')
t.equal(providerA.getHandled('test_rpc').length, 0, 'providerA did NOT handle "test_rpc"')
t.equal(providerB.getWitnessed('test_rpc').length, 1, 'providerB did see "test_rpc"')
t.equal(providerB.getHandled('test_rpc').length, 1, 'providerB did handle "test_rpc"')
t.equal(providerC.getWitnessed('test_rpc').length, 0, 'providerC did NOT see "test_rpc"')
t.equal(providerC.getHandled('test_rpc').length, 0, 'providerC did NOT handle "test_rpc"')
engine.stop()
t.end()
})
})