mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-11 15:48:05 +00:00
Merge #10229: Tests: Add test for getdifficulty
821dd5e
Tests: Add test for getdifficulty (Jimmy Song)
Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
This commit is contained in:
commit
f3db4c6013
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
Test the following RPCs:
|
Test the following RPCs:
|
||||||
- gettxoutsetinfo
|
- gettxoutsetinfo
|
||||||
|
- getdifficulty
|
||||||
|
- getbestblockhash
|
||||||
|
- getblockhash
|
||||||
|
- getblockheader
|
||||||
- verifychain
|
- verifychain
|
||||||
|
|
||||||
Tests correspond to code in rpc/blockchain.cpp.
|
Tests correspond to code in rpc/blockchain.cpp.
|
||||||
@ -40,6 +44,7 @@ class BlockchainTest(BitcoinTestFramework):
|
|||||||
def run_test(self):
|
def run_test(self):
|
||||||
self._test_gettxoutsetinfo()
|
self._test_gettxoutsetinfo()
|
||||||
self._test_getblockheader()
|
self._test_getblockheader()
|
||||||
|
self._test_getdifficulty()
|
||||||
self.nodes[0].verifychain(4, 0)
|
self.nodes[0].verifychain(4, 0)
|
||||||
|
|
||||||
def _test_gettxoutsetinfo(self):
|
def _test_gettxoutsetinfo(self):
|
||||||
@ -57,7 +62,8 @@ class BlockchainTest(BitcoinTestFramework):
|
|||||||
def _test_getblockheader(self):
|
def _test_getblockheader(self):
|
||||||
node = self.nodes[0]
|
node = self.nodes[0]
|
||||||
|
|
||||||
assert_raises_jsonrpc(-5, "Block not found", node.getblockheader, "nonsense")
|
assert_raises_jsonrpc(-5, "Block not found",
|
||||||
|
node.getblockheader, "nonsense")
|
||||||
|
|
||||||
besthash = node.getbestblockhash()
|
besthash = node.getbestblockhash()
|
||||||
secondbesthash = node.getblockhash(199)
|
secondbesthash = node.getblockhash(199)
|
||||||
@ -79,5 +85,11 @@ class BlockchainTest(BitcoinTestFramework):
|
|||||||
assert isinstance(int(header['versionHex'], 16), int)
|
assert isinstance(int(header['versionHex'], 16), int)
|
||||||
assert isinstance(header['difficulty'], Decimal)
|
assert isinstance(header['difficulty'], Decimal)
|
||||||
|
|
||||||
|
def _test_getdifficulty(self):
|
||||||
|
difficulty = self.nodes[0].getdifficulty()
|
||||||
|
# 1 hash in 2 should be valid, so difficulty should be 1/2**31
|
||||||
|
# binary => decimal => binary math is why we do this check
|
||||||
|
assert abs(difficulty * 2**31 - 1) < 0.0001
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
BlockchainTest().main()
|
BlockchainTest().main()
|
||||||
|
Loading…
Reference in New Issue
Block a user