Skip to content

Commit

Permalink
Tests: Add test for getdifficulty
Browse files Browse the repository at this point in the history
Test added to blockchain.py as adding a new test to reduce test run time.
  • Loading branch information
jimmysong committed Apr 19, 2017
1 parent c91ca0a commit 821dd5e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/functional/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
Test the following RPCs:
- gettxoutsetinfo
- getdifficulty
- getbestblockhash
- getblockhash
- getblockheader
- verifychain
Tests correspond to code in rpc/blockchain.cpp.
Expand Down Expand Up @@ -40,6 +44,7 @@ def setup_network(self, split=False):
def run_test(self):
self._test_gettxoutsetinfo()
self._test_getblockheader()
self._test_getdifficulty()
self.nodes[0].verifychain(4, 0)

def _test_gettxoutsetinfo(self):
Expand All @@ -57,7 +62,8 @@ def _test_gettxoutsetinfo(self):
def _test_getblockheader(self):
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()
secondbesthash = node.getblockhash(199)
Expand All @@ -79,5 +85,11 @@ def _test_getblockheader(self):
assert isinstance(int(header['versionHex'], 16), int)
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__':
BlockchainTest().main()

0 comments on commit 821dd5e

Please sign in to comment.