66
77Test the following RPCs:
88 - gettxoutsetinfo
9+ - getdifficulty
10+ - getbestblockhash
11+ - getblockhash
12+ - getblockheader
913 - verifychain
1014
1115Tests correspond to code in rpc/blockchain.cpp.
@@ -40,6 +44,7 @@ def setup_network(self, split=False):
4044 def run_test (self ):
4145 self ._test_gettxoutsetinfo ()
4246 self ._test_getblockheader ()
47+ self ._test_getdifficulty ()
4348 self .nodes [0 ].verifychain (4 , 0 )
4449
4550 def _test_gettxoutsetinfo (self ):
@@ -57,7 +62,8 @@ def _test_gettxoutsetinfo(self):
5762 def _test_getblockheader (self ):
5863 node = self .nodes [0 ]
5964
60- assert_raises_jsonrpc (- 5 , "Block not found" , node .getblockheader , "nonsense" )
65+ assert_raises_jsonrpc (- 5 , "Block not found" ,
66+ node .getblockheader , "nonsense" )
6167
6268 besthash = node .getbestblockhash ()
6369 secondbesthash = node .getblockhash (199 )
@@ -79,5 +85,11 @@ def _test_getblockheader(self):
7985 assert isinstance (int (header ['versionHex' ], 16 ), int )
8086 assert isinstance (header ['difficulty' ], Decimal )
8187
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+
8294if __name__ == '__main__' :
8395 BlockchainTest ().main ()
0 commit comments