forked from MetaMask/eth-block-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
47 lines (38 loc) · 1.13 KB
/
basic.js
File metadata and controls
47 lines (38 loc) · 1.13 KB
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
46
47
const test = require('tape')
const RpcBlockTracker = require('../bundle/index')
const JsonRpcEngine = require('json-rpc-engine')
const TestBlockMiddleware = require('./util/testBlockMiddleware')
test('basic tests - constructor', (t) => {
t.plan(1)
const provider = {}
const blockTracker = new RpcBlockTracker({ provider })
t.pass('constructor did not error')
t.end()
})
test('basic tests - walking', (t) => {
t.plan(4)
const engine = new JsonRpcEngine()
const testBlockSource = new TestBlockMiddleware()
testBlockSource.nextBlock()
testBlockSource.nextBlock()
engine.push(testBlockSource.createMiddleware())
const provider = {
sendAsync: engine.handle.bind(engine),
}
const blockTracker = new RpcBlockTracker({ provider })
blockTracker.once('block', () => {
t.pass('saw 1st block')
blockTracker.once('block', () => {
t.pass('saw 2nd block')
blockTracker.once('block', () => {
t.pass('saw 3rd block')
})
})
})
blockTracker.once('latest', () => {
t.pass('saw latest block')
blockTracker.stop()
t.end()
})
blockTracker.start({ fromBlock: '0x01' })
})