Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_blockchain.py
Show All 23 Lines | |||||
import subprocess | import subprocess | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
TIME_GENESIS_BLOCK, | TIME_GENESIS_BLOCK, | ||||
) | ) | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CBlockHeader, | |||||
FromHex, | |||||
msg_block, | msg_block, | ||||
) | ) | ||||
from test_framework.p2p import P2PInterface | from test_framework.p2p import P2PInterface | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_greater_than, | assert_greater_than, | ||||
assert_greater_than_or_equal, | assert_greater_than_or_equal, | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | def _test_getblockheader(self): | ||||
assert_is_hash_string(header['bits'], length=None) | assert_is_hash_string(header['bits'], length=None) | ||||
assert isinstance(header['time'], int) | assert isinstance(header['time'], int) | ||||
assert isinstance(header['mediantime'], int) | assert isinstance(header['mediantime'], int) | ||||
assert isinstance(header['nonce'], int) | assert isinstance(header['nonce'], int) | ||||
assert isinstance(header['version'], int) | assert isinstance(header['version'], int) | ||||
assert isinstance(int(header['versionHex'], 16), int) | assert isinstance(int(header['versionHex'], 16), int) | ||||
assert isinstance(header['difficulty'], Decimal) | assert isinstance(header['difficulty'], Decimal) | ||||
# Test with verbose=False, which should return the header as hex. | |||||
header_hex = node.getblockheader(blockhash=besthash, verbose=False) | |||||
assert_is_hex_string(header_hex) | |||||
header = FromHex(CBlockHeader(), header_hex) | |||||
header.calc_sha256() | |||||
assert_equal(header.hash, besthash) | |||||
def _test_getdifficulty(self): | def _test_getdifficulty(self): | ||||
difficulty = self.nodes[0].getdifficulty() | difficulty = self.nodes[0].getdifficulty() | ||||
# 1 hash in 2 should be valid, so difficulty should be 1/2**31 | # 1 hash in 2 should be valid, so difficulty should be 1/2**31 | ||||
# binary => decimal => binary math is why we do this check | # binary => decimal => binary math is why we do this check | ||||
assert abs(difficulty * 2**31 - 1) < 0.0001 | assert abs(difficulty * 2**31 - 1) < 0.0001 | ||||
def _test_getnetworkhashps(self): | def _test_getnetworkhashps(self): | ||||
hashes_per_second = self.nodes[0].getnetworkhashps() | hashes_per_second = self.nodes[0].getnetworkhashps() | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |