-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-headers-first.js
56 lines (46 loc) · 1.27 KB
/
simple-headers-first.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
'use strict';
const NodeFactory = require('./nodefactory');
const BN = require('bcoin/node_modules/bcrypto/lib/bn.js');
const nodeFactory = new NodeFactory();
(async () => {
const core1 = nodeFactory.createCore();
const bcoin = await nodeFactory.createBcoin();
bcoin.node.network.pow.chainwork = bcoin.node.network.pow.chainwork.mul( new BN(50) )
// Core 1 generates 100 blocks
await new Promise(r => setTimeout(r, 5000));
await core1.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:${core1.ports.port}`, 'add']
);
// Output
await new Promise(r => setTimeout(r, 20000));
const core1info = await core1.rpc(
'getblockchaininfo',
[]
);
const bcoininfo = await bcoin.rpc(
'getblockchaininfo',
[]
);
// Close
await new Promise(r => setTimeout(r, 5000));
await core1.rpc(
'stop',
[]
);
await bcoin.rpc(
'stop',
[]
);
await new Promise(r => setTimeout(r, 5000));
console.log('Core 1: ',
core1info.blocks, core1info.headers, core1info.bestblockhash);
console.log('bcoin: ',
bcoininfo.blocks, bcoininfo.headers, bcoininfo.bestblockhash);
})();