Skip to content

Commit f3db4c6

Browse files
committed
Merge #10229: Tests: Add test for getdifficulty
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
2 parents 27faa6c + 821dd5e commit f3db4c6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/functional/blockchain.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
77
Test the following RPCs:
88
- gettxoutsetinfo
9+
- getdifficulty
10+
- getbestblockhash
11+
- getblockhash
12+
- getblockheader
913
- verifychain
1014
1115
Tests 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+
8294
if __name__ == '__main__':
8395
BlockchainTest().main()

0 commit comments

Comments
 (0)