forked from ElementsProject/elements
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeature_progress.py
executable file
·61 lines (46 loc) · 1.73 KB
/
feature_progress.py
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
58
59
60
61
#!/usr/bin/env python3
# Copyright (c) 2015-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Test progress code
#
import time
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
Decimal,
)
def assert_close(f1, f2):
assert abs(Decimal(f1)-f2) < 0.1
class ProgressTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
self.extra_args = [["-debug", "-con_npowtargetspacing=1", "-maxtimeadjustment=0"]] * self.num_nodes
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self):
self.setup_nodes()
self.starttime = int(time.time())
def setmocktime(self, ntime):
for node in self.nodes:
node.setmocktime(self.starttime + ntime)
def run_test(self):
node1 = self.nodes[0]
node2 = self.nodes[1]
self.setmocktime(0)
blocks = []
for i in range(10):
self.setmocktime(i)
blocks.extend(self.generate(node1, 1, sync_fun=self.no_op))
self.setmocktime(19)
assert_close(0.5, node1.getblockchaininfo()["verificationprogress"])
assert node2.getblockchaininfo()["initialblockdownload"]
self.setmocktime(10)
for i in range(10):
node2.submitblock(node1.getblock(blocks[i], False))
progress = node2.getblockchaininfo()["verificationprogress"]
assert_close(i/10.0, progress)
assert not node2.getblockchaininfo()["initialblockdownload"]
if __name__ == '__main__':
ProgressTest().main()