-
Notifications
You must be signed in to change notification settings - Fork 0
/
invalidate-block.js
57 lines (48 loc) · 1.2 KB
/
invalidate-block.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
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const NodeFactory = require('./nodefactory');
const nodeFactory = new NodeFactory();
(async () => {
const core = nodeFactory.createCore();
const bcoin = await nodeFactory.createBcoin();
// Core generates 100 blocks
await new Promise(r => setTimeout(r, 2000));
const blocks = await core.rpc(
'generatetoaddress',
[100, 'mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8']
);
// bcoin connects to Core and syncs
await new Promise(r => setTimeout(r, 5000));
await bcoin.rpc(
'addnode',
[`127.0.0.1:${core.ports.port}`, 'add']
);
// What happens when bcoin marks a block as invalid?
await new Promise(r => setTimeout(r, 5000));
await bcoin.rpc(
'invalidateblock',
[blocks[blocks.length - 5]]
);
// Output
await new Promise(r => setTimeout(r, 10000));
const coreinfo = await core.rpc(
'getblockchaininfo',
[]
);
const bcoininfo = await bcoin.rpc(
'getblockchaininfo',
[]
);
console.log('Core: ', coreinfo);
console.log('bcoin: ', bcoininfo);
// Close
await new Promise(r => setTimeout(r, 5000));
await core.rpc(
'stop',
[]
);
await bcoin.rpc(
'stop',
[]
);
await new Promise(r => setTimeout(r, 5000));
})();