6
6
7
7
Test the following RPCs:
8
8
- gettxoutsetinfo
9
+ - getdifficulty
10
+ - getbestblockhash
11
+ - getblockhash
12
+ - getblockheader
9
13
- verifychain
10
14
11
15
Tests correspond to code in rpc/blockchain.cpp.
@@ -40,6 +44,7 @@ def setup_network(self, split=False):
40
44
def run_test (self ):
41
45
self ._test_gettxoutsetinfo ()
42
46
self ._test_getblockheader ()
47
+ self ._test_getdifficulty ()
43
48
self .nodes [0 ].verifychain (4 , 0 )
44
49
45
50
def _test_gettxoutsetinfo (self ):
@@ -57,7 +62,8 @@ def _test_gettxoutsetinfo(self):
57
62
def _test_getblockheader (self ):
58
63
node = self .nodes [0 ]
59
64
60
- assert_raises_jsonrpc (- 5 , "Block not found" , node .getblockheader , "nonsense" )
65
+ assert_raises_jsonrpc (- 5 , "Block not found" ,
66
+ node .getblockheader , "nonsense" )
61
67
62
68
besthash = node .getbestblockhash ()
63
69
secondbesthash = node .getblockhash (199 )
@@ -79,5 +85,11 @@ def _test_getblockheader(self):
79
85
assert isinstance (int (header ['versionHex' ], 16 ), int )
80
86
assert isinstance (header ['difficulty' ], Decimal )
81
87
88
+ def _test_getdifficulty (self ):
89
+ difficulty = self .nodes [0 ].getdifficulty ()
90
+ # 1 hash in 2 should be valid, so difficulty should be 1/2**31
91
+ # binary => decimal => binary math is why we do this check
92
+ assert abs (difficulty * 2 ** 31 - 1 ) < 0.0001
93
+
82
94
if __name__ == '__main__' :
83
95
BlockchainTest ().main ()
0 commit comments