aboutsummaryrefslogtreecommitdiff
path: root/test/functional/blockchain.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/blockchain.py')
-rwxr-xr-xtest/functional/blockchain.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/test/functional/blockchain.py b/test/functional/blockchain.py
index 596aed50ec..00ae3d7572 100755
--- a/test/functional/blockchain.py
+++ b/test/functional/blockchain.py
@@ -6,6 +6,10 @@
Test the following RPCs:
- gettxoutsetinfo
+ - getdifficulty
+ - getbestblockhash
+ - getblockhash
+ - getblockheader
- verifychain
Tests correspond to code in rpc/blockchain.cpp.
@@ -31,15 +35,10 @@ class BlockchainTest(BitcoinTestFramework):
self.setup_clean_chain = False
self.num_nodes = 2
- def setup_network(self, split=False):
- self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
- connect_nodes_bi(self.nodes, 0, 1)
- self.is_network_split = False
- self.sync_all()
-
def run_test(self):
self._test_gettxoutsetinfo()
self._test_getblockheader()
+ self._test_getdifficulty()
self.nodes[0].verifychain(4, 0)
def _test_gettxoutsetinfo(self):
@@ -57,7 +56,8 @@ class BlockchainTest(BitcoinTestFramework):
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)
@@ -79,5 +79,11 @@ class BlockchainTest(BitcoinTestFramework):
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()