0
0
mirror of https://github.com/namecoin/namecoin-core synced 2025-10-06 00:22:46 +02:00

test: rename CBlockHeader .hash -> .hash_hex for consistency

Note that we unfortunately can't use a scripted diff here, as the
`.hash` symbol is also used for other instances (e.g. CInv).
This commit is contained in:
Sebastian Falbesoner
2025-06-12 15:13:11 +02:00
parent 23be0ec2f0
commit 2118301d77
22 changed files with 84 additions and 84 deletions

View File

@@ -481,15 +481,15 @@ def do_generate(args):
# report # report
bstr = "block" if gen.is_mine else "backup block" bstr = "block" if gen.is_mine else "backup block"
next_delta = gen.next_block_delta(block.nBits, block.hash) next_delta = gen.next_block_delta(block.nBits, block.hash_hex)
next_delta += block.nTime - time.time() next_delta += block.nTime - time.time()
next_is_mine = gen.next_block_is_mine(block.hash) next_is_mine = gen.next_block_is_mine(block.hash_hex)
logging.debug("Block hash %s payout to %s", block.hash, reward_addr) logging.debug("Block hash %s payout to %s", block.hash_hex, reward_addr)
logging.info("Mined %s at height %d; next in %s (%s)", bstr, tmpl["height"], seconds_to_hms(next_delta), ("mine" if next_is_mine else "backup")) logging.info("Mined %s at height %d; next in %s (%s)", bstr, tmpl["height"], seconds_to_hms(next_delta), ("mine" if next_is_mine else "backup"))
if r != "": if r != "":
logging.warning("submitblock returned %s for height %d hash %s", r, tmpl["height"], block.hash) logging.warning("submitblock returned %s for height %d hash %s", r, tmpl["height"], block.hash_hex)
lastheader = block.hash lastheader = block.hash_hex
def do_calibrate(args): def do_calibrate(args):
if args.nbits is not None and args.seconds is not None: if args.nbits is not None and args.seconds is not None:

View File

@@ -138,8 +138,8 @@ class AssumeValidTest(BitcoinTestFramework):
height += 1 height += 1
# Start node1 and node2 with assumevalid so they accept a block with a bad signature. # Start node1 and node2 with assumevalid so they accept a block with a bad signature.
self.start_node(1, extra_args=["-assumevalid=" + block102.hash]) self.start_node(1, extra_args=["-assumevalid=" + block102.hash_hex])
self.start_node(2, extra_args=["-assumevalid=" + block102.hash]) self.start_node(2, extra_args=["-assumevalid=" + block102.hash_hex])
p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) p2p0 = self.nodes[0].add_p2p_connection(BaseNode())
p2p0.send_header_for_blocks(self.blocks[0:2000]) p2p0.send_header_for_blocks(self.blocks[0:2000])

View File

@@ -383,7 +383,7 @@ class BIP68Test(BitcoinTestFramework):
block.solve() block.solve()
assert_equal(None, self.nodes[0].submitblock(block.serialize().hex())) assert_equal(None, self.nodes[0].submitblock(block.serialize().hex()))
assert_equal(self.nodes[0].getbestblockhash(), block.hash) assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
def activateCSV(self): def activateCSV(self):
# activation should happen at block height 432 (3 periods) # activation should happen at block height 432 (3 periods)

View File

@@ -280,7 +280,7 @@ class FullBlockTest(BitcoinTestFramework):
self.send_blocks([b12, b13, b14], success=False, reject_reason='bad-cb-amount', reconnect=True) self.send_blocks([b12, b13, b14], success=False, reject_reason='bad-cb-amount', reconnect=True)
# New tip should be b13. # New tip should be b13.
assert_equal(node.getbestblockhash(), b13.hash) assert_equal(node.getbestblockhash(), b13.hash_hex)
# Add a block with MAX_BLOCK_SIGOPS and one with one more sigop # Add a block with MAX_BLOCK_SIGOPS and one with one more sigop
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -734,7 +734,7 @@ class FullBlockTest(BitcoinTestFramework):
self.block_heights[b48.hash_int] = self.block_heights[b44.hash_int] + 1 # b48 is a parent of b44 self.block_heights[b48.hash_int] = self.block_heights[b44.hash_int] + 1 # b48 is a parent of b44
b48p = self.next_block("48p") b48p = self.next_block("48p")
self.send_blocks([b48, b48p], success=True) # Reorg to the longer chain self.send_blocks([b48, b48p], success=True) # Reorg to the longer chain
node.invalidateblock(b48p.hash) # mark b48p as invalid node.invalidateblock(b48p.hash_hex) # mark b48p as invalid
node.setmocktime(0) node.setmocktime(0)
# Test Merkle tree malleability # Test Merkle tree malleability
@@ -778,7 +778,7 @@ class FullBlockTest(BitcoinTestFramework):
self.blocks[56] = b56 self.blocks[56] = b56
assert_equal(len(b56.vtx), 3) assert_equal(len(b56.vtx), 3)
b56 = self.update_block(56, [tx1]) b56 = self.update_block(56, [tx1])
assert_equal(b56.hash, b57.hash) assert_equal(b56.hash_hex, b57.hash_hex)
self.send_blocks([b56], success=False, reject_reason='bad-txns-duplicate', reconnect=True) self.send_blocks([b56], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
# b57p2 - a good block with 6 tx'es, don't submit until end # b57p2 - a good block with 6 tx'es, don't submit until end
@@ -796,7 +796,7 @@ class FullBlockTest(BitcoinTestFramework):
self.move_tip(55) self.move_tip(55)
b56p2 = copy.deepcopy(b57p2) b56p2 = copy.deepcopy(b57p2)
self.blocks["b56p2"] = b56p2 self.blocks["b56p2"] = b56p2
assert_equal(b56p2.hash, b57p2.hash) assert_equal(b56p2.hash_hex, b57p2.hash_hex)
assert_equal(len(b56p2.vtx), 6) assert_equal(len(b56p2.vtx), 6)
b56p2 = self.update_block("b56p2", [tx3, tx4]) b56p2 = self.update_block("b56p2", [tx3, tx4])
self.send_blocks([b56p2], success=False, reject_reason='bad-txns-duplicate', reconnect=True) self.send_blocks([b56p2], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
@@ -954,7 +954,7 @@ class FullBlockTest(BitcoinTestFramework):
self.move_tip('dup_2') self.move_tip('dup_2')
b64 = CBlock(b64a) b64 = CBlock(b64a)
b64.vtx = copy.deepcopy(b64a.vtx) b64.vtx = copy.deepcopy(b64a.vtx)
assert_equal(b64.hash, b64a.hash) assert_equal(b64.hash_hex, b64a.hash_hex)
assert_equal(b64.get_weight(), MAX_BLOCK_WEIGHT) assert_equal(b64.get_weight(), MAX_BLOCK_WEIGHT)
self.blocks[64] = b64 self.blocks[64] = b64
b64 = self.update_block(64, []) b64 = self.update_block(64, [])

View File

@@ -127,7 +127,7 @@ class BIP65Test(BitcoinTestFramework):
self.test_cltv_info(is_active=False) # Not active as of current tip and next block does not need to obey rules self.test_cltv_info(is_active=False) # Not active as of current tip and next block does not need to obey rules
peer.send_and_ping(msg_block(block)) peer.send_and_ping(msg_block(block))
self.test_cltv_info(is_active=True) # Not active as of current tip, but next block must obey rules self.test_cltv_info(is_active=True) # Not active as of current tip, but next block must obey rules
assert_equal(self.nodes[0].getbestblockhash(), block.hash) assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
self.log.info("Test that blocks must now be at least version 4") self.log.info("Test that blocks must now be at least version 4")
tip = block.hash_int tip = block.hash_int
@@ -135,7 +135,7 @@ class BIP65Test(BitcoinTestFramework):
block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time, version=3) block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time, version=3)
block.solve() block.solve()
with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash}, bad-version(0x00000003)']): with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash_hex}, bad-version(0x00000003)']):
peer.send_and_ping(msg_block(block)) peer.send_and_ping(msg_block(block))
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip) assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
peer.sync_with_ping() peer.sync_with_ping()

View File

@@ -92,7 +92,7 @@ class BIP66Test(BitcoinTestFramework):
peer.send_and_ping(msg_block(block)) peer.send_and_ping(msg_block(block))
assert_equal(self.nodes[0].getblockcount(), DERSIG_HEIGHT - 1) assert_equal(self.nodes[0].getblockcount(), DERSIG_HEIGHT - 1)
self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules
assert_equal(self.nodes[0].getbestblockhash(), block.hash) assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
self.log.info("Test that blocks must now be at least version 3") self.log.info("Test that blocks must now be at least version 3")
tip = block.hash_int tip = block.hash_int
@@ -100,7 +100,7 @@ class BIP66Test(BitcoinTestFramework):
block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time, version=2) block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time, version=2)
block.solve() block.solve()
with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash}, bad-version(0x00000002)']): with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash_hex}, bad-version(0x00000002)']):
peer.send_and_ping(msg_block(block)) peer.send_and_ping(msg_block(block))
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip) assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
peer.sync_with_ping() peer.sync_with_ping()

View File

@@ -143,8 +143,8 @@ class NULLDUMMYTest(BitcoinTestFramework):
block.solve() block.solve()
assert_equal(None if accept else NULLDUMMY_ERROR, node.submitblock(block.serialize().hex())) assert_equal(None if accept else NULLDUMMY_ERROR, node.submitblock(block.serialize().hex()))
if accept: if accept:
assert_equal(node.getbestblockhash(), block.hash) assert_equal(node.getbestblockhash(), block.hash_hex)
self.lastblockhash = block.hash self.lastblockhash = block.hash_hex
self.lastblocktime += 1 self.lastblocktime += 1
self.lastblockheight += 1 self.lastblockheight += 1
else: else:

View File

@@ -1341,9 +1341,9 @@ class TaprootTest(BitcoinTestFramework):
if err_msg is not None: if err_msg is not None:
assert block_response is not None and err_msg in block_response, "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg) assert block_response is not None and err_msg in block_response, "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg)
if accept: if accept:
assert node.getbestblockhash() == block.hash, "Failed to accept: %s (response: %s)" % (msg, block_response) assert node.getbestblockhash() == block.hash_hex, "Failed to accept: %s (response: %s)" % (msg, block_response)
self.tip = block.hash_int self.tip = block.hash_int
self.lastblockhash = block.hash self.lastblockhash = block.hash_hex
self.lastblocktime += 1 self.lastblocktime += 1
self.lastblockheight += 1 self.lastblockheight += 1
else: else:

View File

@@ -445,25 +445,25 @@ class MiningTest(BitcoinTestFramework):
def chain_tip(b_hash, *, status='headers-only', branchlen=1): def chain_tip(b_hash, *, status='headers-only', branchlen=1):
return {'hash': b_hash, 'height': 202, 'branchlen': branchlen, 'status': status} return {'hash': b_hash, 'height': 202, 'branchlen': branchlen, 'status': status}
assert chain_tip(block.hash) not in node.getchaintips() assert chain_tip(block.hash_hex) not in node.getchaintips()
node.submitheader(hexdata=block.serialize().hex()) node.submitheader(hexdata=block.serialize().hex())
assert chain_tip(block.hash) in node.getchaintips() assert chain_tip(block.hash_hex) in node.getchaintips()
node.submitheader(hexdata=CBlockHeader(block).serialize().hex()) # Noop node.submitheader(hexdata=CBlockHeader(block).serialize().hex()) # Noop
assert chain_tip(block.hash) in node.getchaintips() assert chain_tip(block.hash_hex) in node.getchaintips()
bad_block_root = copy.deepcopy(block) bad_block_root = copy.deepcopy(block)
bad_block_root.hashMerkleRoot += 2 bad_block_root.hashMerkleRoot += 2
bad_block_root.solve() bad_block_root.solve()
assert chain_tip(bad_block_root.hash) not in node.getchaintips() assert chain_tip(bad_block_root.hash_hex) not in node.getchaintips()
node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex()) node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex())
assert chain_tip(bad_block_root.hash) in node.getchaintips() assert chain_tip(bad_block_root.hash_hex) in node.getchaintips()
# Should still reject invalid blocks, even if we have the header: # Should still reject invalid blocks, even if we have the header:
assert_equal(node.submitblock(hexdata=bad_block_root.serialize().hex()), 'bad-txnmrklroot') assert_equal(node.submitblock(hexdata=bad_block_root.serialize().hex()), 'bad-txnmrklroot')
assert_equal(node.submitblock(hexdata=bad_block_root.serialize().hex()), 'bad-txnmrklroot') assert_equal(node.submitblock(hexdata=bad_block_root.serialize().hex()), 'bad-txnmrklroot')
assert chain_tip(bad_block_root.hash) in node.getchaintips() assert chain_tip(bad_block_root.hash_hex) in node.getchaintips()
# We know the header for this invalid block, so should just return early without error: # We know the header for this invalid block, so should just return early without error:
node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex()) node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex())
assert chain_tip(bad_block_root.hash) in node.getchaintips() assert chain_tip(bad_block_root.hash_hex) in node.getchaintips()
bad_block_lock = copy.deepcopy(block) bad_block_lock = copy.deepcopy(block)
bad_block_lock.vtx[0].nLockTime = 2**32 - 1 bad_block_lock.vtx[0].nLockTime = 2**32 - 1
@@ -488,7 +488,7 @@ class MiningTest(BitcoinTestFramework):
peer.wait_for_getheaders(timeout=5, block_hash=block.hashPrevBlock) peer.wait_for_getheaders(timeout=5, block_hash=block.hashPrevBlock)
peer.send_blocks_and_test(blocks=[block], node=node) peer.send_blocks_and_test(blocks=[block], node=node)
# Must be active now: # Must be active now:
assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips() assert chain_tip(block.hash_hex, status='active', branchlen=0) in node.getchaintips()
# Building a few blocks should give the same results # Building a few blocks should give the same results
self.generatetoaddress(node, 10, node.get_deterministic_priv_key().address) self.generatetoaddress(node, 10, node.get_deterministic_priv_key().address)

View File

@@ -70,7 +70,7 @@ class MiningMainnetTest(BitcoinTestFramework):
self.log.debug(block_hex) self.log.debug(block_hex)
assert_equal(node.submitblock(block_hex), None) assert_equal(node.submitblock(block_hex), None)
prev_hash = node.getbestblockhash() prev_hash = node.getbestblockhash()
assert_equal(prev_hash, block.hash) assert_equal(prev_hash, block.hash_hex)
return prev_hash return prev_hash

View File

@@ -623,7 +623,7 @@ class CompactBlocksTest(BitcoinTestFramework):
tips = node.getchaintips() tips = node.getchaintips()
found = False found = False
for x in tips: for x in tips:
if x["hash"] == block.hash: if x["hash"] == block.hash_hex:
found = True found = True
break break
assert not found assert not found
@@ -667,7 +667,7 @@ class CompactBlocksTest(BitcoinTestFramework):
tips = node.getchaintips() tips = node.getchaintips()
found = False found = False
for x in tips: for x in tips:
if x["hash"] == block.hash: if x["hash"] == block.hash_hex:
assert_equal(x["status"], "headers-only") assert_equal(x["status"], "headers-only")
found = True found = True
break break

View File

@@ -41,7 +41,7 @@ class P2PFingerprintTest(BitcoinTestFramework):
block.solve() block.solve()
blocks.append(block) blocks.append(block)
prev_hash = block.hash prev_hash = block.hash_hex
prev_height += 1 prev_height += 1
prev_median_time = block_time prev_median_time = block_time
return blocks return blocks

View File

@@ -115,7 +115,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
# Update tip info # Update tip info
height += 1 height += 1
block_time += 1 block_time += 1
tip = int(block2_orig.hash, 16) tip = int(block2_orig.hash_hex, 16)
# Complete testing of CVE-2018-17144, by checking for the inflation bug. # Complete testing of CVE-2018-17144, by checking for the inflation bug.
# Create a block that spends the output of a tx in a previous block. # Create a block that spends the output of a tx in a previous block.

View File

@@ -288,17 +288,17 @@ class InvalidMessagesTest(BitcoinTestFramework):
blockheader.hashPrevBlock = int(blockheader_tip_hash, 16) blockheader.hashPrevBlock = int(blockheader_tip_hash, 16)
blockheader.nTime = int(time.time()) blockheader.nTime = int(time.time())
blockheader.nBits = blockheader_tip.nBits blockheader.nBits = blockheader_tip.nBits
while not blockheader.hash.startswith('0'): while not blockheader.hash_hex.startswith('0'):
blockheader.nNonce += 1 blockheader.nNonce += 1
peer = self.nodes[0].add_p2p_connection(P2PInterface()) peer = self.nodes[0].add_p2p_connection(P2PInterface())
peer.send_and_ping(msg_headers([blockheader])) peer.send_and_ping(msg_headers([blockheader]))
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 1) assert_equal(self.nodes[0].getblockchaininfo()['headers'], 1)
chaintips = self.nodes[0].getchaintips() chaintips = self.nodes[0].getchaintips()
assert_equal(chaintips[0]['status'], 'headers-only') assert_equal(chaintips[0]['status'], 'headers-only')
assert_equal(chaintips[0]['hash'], blockheader.hash) assert_equal(chaintips[0]['hash'], blockheader.hash_hex)
# invalidate PoW # invalidate PoW
while not blockheader.hash.startswith('f'): while not blockheader.hash_hex.startswith('f'):
blockheader.nNonce += 1 blockheader.nNonce += 1
with self.nodes[0].assert_debug_log(['Misbehaving', 'header with invalid proof of work']): with self.nodes[0].assert_debug_log(['Misbehaving', 'header with invalid proof of work']):
peer.send_without_ping(msg_headers([blockheader])) peer.send_without_ping(msg_headers([blockheader]))

View File

@@ -95,7 +95,7 @@ class MutatedBlocksTest(BitcoinTestFramework):
block_txn = msg_blocktxn() block_txn = msg_blocktxn()
block_txn.block_transactions = BlockTransactions(blockhash=block.hash_int, transactions=[tx]) block_txn.block_transactions = BlockTransactions(blockhash=block.hash_int, transactions=[tx])
honest_relayer.send_and_ping(block_txn) honest_relayer.send_and_ping(block_txn)
assert_equal(self.nodes[0].getbestblockhash(), block.hash) assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
# Check that unexpected-witness mutation check doesn't trigger on a header that doesn't connect to anything # Check that unexpected-witness mutation check doesn't trigger on a header that doesn't connect to anything
assert_equal(len(self.nodes[0].getpeerinfo()), 1) assert_equal(len(self.nodes[0].getpeerinfo()), 1)

View File

@@ -143,7 +143,7 @@ def test_witness_block(node, p2p, block, accepted, with_witness=True, reason=Non
reason = [reason] if reason else [] reason = [reason] if reason else []
with node.assert_debug_log(expected_msgs=reason): with node.assert_debug_log(expected_msgs=reason):
p2p.send_and_ping(msg_block(block) if with_witness else msg_no_witness_block(block)) p2p.send_and_ping(msg_block(block) if with_witness else msg_no_witness_block(block))
assert_equal(node.getbestblockhash() == block.hash, accepted) assert_equal(node.getbestblockhash() == block.hash_hex, accepted)
class TestP2PConn(P2PInterface): class TestP2PConn(P2PInterface):
@@ -346,7 +346,7 @@ class SegWitTest(BitcoinTestFramework):
# But it should not be permanently marked bad... # But it should not be permanently marked bad...
# Resend without witness information. # Resend without witness information.
self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed
assert_equal(self.nodes[0].getbestblockhash(), block.hash) assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
# Update our utxo list; we spent the first entry. # Update our utxo list; we spent the first entry.
self.utxo.pop(0) self.utxo.pop(0)
@@ -413,7 +413,7 @@ class SegWitTest(BitcoinTestFramework):
assert len(block.vtx[0].wit.vtxinwit[0].scriptWitness.stack) == 1 assert len(block.vtx[0].wit.vtxinwit[0].scriptWitness.stack) == 1
test_witness_block(self.nodes[0], self.test_node, block, accepted=True) test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Now try to retrieve it... # Now try to retrieve it...
rpc_block = self.nodes[0].getblock(block.hash, False) rpc_block = self.nodes[0].getblock(block.hash_hex, False)
non_wit_block = self.test_node.request_block(block.hash_int, 2) non_wit_block = self.test_node.request_block(block.hash_int, 2)
wit_block = self.test_node.request_block(block.hash_int, 2 | MSG_WITNESS_FLAG) wit_block = self.test_node.request_block(block.hash_int, 2 | MSG_WITNESS_FLAG)
assert_equal(wit_block.serialize(), bytes.fromhex(rpc_block)) assert_equal(wit_block.serialize(), bytes.fromhex(rpc_block))
@@ -421,7 +421,7 @@ class SegWitTest(BitcoinTestFramework):
assert_equal(wit_block.serialize(), block.serialize()) assert_equal(wit_block.serialize(), block.serialize())
# Test size, vsize, weight # Test size, vsize, weight
rpc_details = self.nodes[0].getblock(block.hash, True) rpc_details = self.nodes[0].getblock(block.hash_hex, True)
assert_equal(rpc_details["size"], len(block.serialize())) assert_equal(rpc_details["size"], len(block.serialize()))
assert_equal(rpc_details["strippedsize"], len(block.serialize(False))) assert_equal(rpc_details["strippedsize"], len(block.serialize(False)))
assert_equal(rpc_details["weight"], block.get_weight()) assert_equal(rpc_details["weight"], block.get_weight())
@@ -819,13 +819,13 @@ class SegWitTest(BitcoinTestFramework):
# TODO: repeat this test with a block that can be relayed # TODO: repeat this test with a block that can be relayed
assert_equal('bad-witness-nonce-size', self.nodes[0].submitblock(block.serialize().hex())) assert_equal('bad-witness-nonce-size', self.nodes[0].submitblock(block.serialize().hex()))
assert_not_equal(self.nodes[0].getbestblockhash(), block.hash) assert_not_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.pop() block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.pop()
assert block.get_weight() < MAX_BLOCK_WEIGHT assert block.get_weight() < MAX_BLOCK_WEIGHT
assert_equal(None, self.nodes[0].submitblock(block.serialize().hex())) assert_equal(None, self.nodes[0].submitblock(block.serialize().hex()))
assert self.nodes[0].getbestblockhash() == block.hash assert self.nodes[0].getbestblockhash() == block.hash_hex
# Now make sure that malleating the witness reserved value doesn't # Now make sure that malleating the witness reserved value doesn't
# result in a block permanently marked bad. # result in a block permanently marked bad.
@@ -926,14 +926,14 @@ class SegWitTest(BitcoinTestFramework):
block.vtx[0].wit = CTxWitness() # drop the nonce block.vtx[0].wit = CTxWitness() # drop the nonce
block.solve() block.solve()
assert_equal('bad-witness-merkle-match', self.nodes[0].submitblock(block.serialize().hex())) assert_equal('bad-witness-merkle-match', self.nodes[0].submitblock(block.serialize().hex()))
assert_not_equal(self.nodes[0].getbestblockhash(), block.hash) assert_not_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
# Now redo commitment with the standard nonce, but let bitcoind fill it in. # Now redo commitment with the standard nonce, but let bitcoind fill it in.
add_witness_commitment(block, nonce=0) add_witness_commitment(block, nonce=0)
block.vtx[0].wit = CTxWitness() block.vtx[0].wit = CTxWitness()
block.solve() block.solve()
assert_equal(None, self.nodes[0].submitblock(block.serialize().hex())) assert_equal(None, self.nodes[0].submitblock(block.serialize().hex()))
assert_equal(self.nodes[0].getbestblockhash(), block.hash) assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
# This time, add a tx with non-empty witness, but don't supply # This time, add a tx with non-empty witness, but don't supply
# the commitment. # the commitment.
@@ -949,7 +949,7 @@ class SegWitTest(BitcoinTestFramework):
assert_equal('bad-txnmrklroot', self.nodes[0].submitblock(block_2.serialize().hex())) assert_equal('bad-txnmrklroot', self.nodes[0].submitblock(block_2.serialize().hex()))
# Tip should not advance! # Tip should not advance!
assert_not_equal(self.nodes[0].getbestblockhash(), block_2.hash) assert_not_equal(self.nodes[0].getbestblockhash(), block_2.hash_hex)
@subtest @subtest
def test_extra_witness_data(self): def test_extra_witness_data(self):
@@ -1891,7 +1891,7 @@ class SegWitTest(BitcoinTestFramework):
# Reset the tip back down for the next test # Reset the tip back down for the next test
self.sync_blocks() self.sync_blocks()
for x in self.nodes: for x in self.nodes:
x.invalidateblock(block_4.hash) x.invalidateblock(block_4.hash_hex)
# Try replacing the last input of tx2 to be spending the last # Try replacing the last input of tx2 to be spending the last
# output of tx # output of tx

View File

@@ -247,12 +247,12 @@ class SendHeadersTest(BitcoinTestFramework):
block.solve() block.solve()
test_node.send_header_for_blocks([block]) test_node.send_header_for_blocks([block])
test_node.clear_block_announcements() test_node.clear_block_announcements()
test_node.send_get_headers(locator=[], hashstop=int(block.hash, 16)) test_node.send_get_headers(locator=[], hashstop=int(block.hash_hex, 16))
test_node.sync_with_ping() test_node.sync_with_ping()
assert_equal(test_node.block_announced, False) assert_equal(test_node.block_announced, False)
inv_node.clear_block_announcements() inv_node.clear_block_announcements()
test_node.send_without_ping(msg_block(block)) test_node.send_without_ping(msg_block(block))
inv_node.check_last_inv_announcement(inv=[int(block.hash, 16)]) inv_node.check_last_inv_announcement(inv=[int(block.hash_hex, 16)])
def test_nonnull_locators(self, test_node, inv_node): def test_nonnull_locators(self, test_node, inv_node):
tip = int(self.nodes[0].getbestblockhash(), 16) tip = int(self.nodes[0].getbestblockhash(), 16)

View File

@@ -97,14 +97,14 @@ class AcceptBlockTest(BitcoinTestFramework):
block_time += 1 block_time += 1
test_node.send_and_ping(msg_block(blocks_h2[0])) test_node.send_and_ping(msg_block(blocks_h2[0]))
with self.nodes[1].assert_debug_log(expected_msgs=[f"AcceptBlockHeader: not adding new block header {blocks_h2[1].hash}, missing anti-dos proof-of-work validation"]): with self.nodes[1].assert_debug_log(expected_msgs=[f"AcceptBlockHeader: not adding new block header {blocks_h2[1].hash_hex}, missing anti-dos proof-of-work validation"]):
min_work_node.send_and_ping(msg_block(blocks_h2[1])) min_work_node.send_and_ping(msg_block(blocks_h2[1]))
assert_equal(self.nodes[0].getblockcount(), 2) assert_equal(self.nodes[0].getblockcount(), 2)
assert_equal(self.nodes[1].getblockcount(), 1) assert_equal(self.nodes[1].getblockcount(), 1)
# Ensure that the header of the second block was also not accepted by node1 # Ensure that the header of the second block was also not accepted by node1
assert_equal(self.check_hash_in_chaintips(self.nodes[1], blocks_h2[1].hash), False) assert_equal(self.check_hash_in_chaintips(self.nodes[1], blocks_h2[1].hash_hex), False)
self.log.info("First height 2 block accepted by node0; correctly rejected by node1") self.log.info("First height 2 block accepted by node0; correctly rejected by node1")
# 3. Send another block that builds on genesis. # 3. Send another block that builds on genesis.
@@ -115,11 +115,11 @@ class AcceptBlockTest(BitcoinTestFramework):
tip_entry_found = False tip_entry_found = False
for x in self.nodes[0].getchaintips(): for x in self.nodes[0].getchaintips():
if x['hash'] == block_h1f.hash: if x['hash'] == block_h1f.hash_hex:
assert_equal(x['status'], "headers-only") assert_equal(x['status'], "headers-only")
tip_entry_found = True tip_entry_found = True
assert tip_entry_found assert tip_entry_found
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, block_h1f.hash) assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, block_h1f.hash_hex)
# 4. Send another two block that build on the fork. # 4. Send another two block that build on the fork.
block_h2f = create_block(block_h1f.hash_int, create_coinbase(2), block_time) block_h2f = create_block(block_h1f.hash_int, create_coinbase(2), block_time)
@@ -131,13 +131,13 @@ class AcceptBlockTest(BitcoinTestFramework):
# can't be fully validated. # can't be fully validated.
tip_entry_found = False tip_entry_found = False
for x in self.nodes[0].getchaintips(): for x in self.nodes[0].getchaintips():
if x['hash'] == block_h2f.hash: if x['hash'] == block_h2f.hash_hex:
assert_equal(x['status'], "headers-only") assert_equal(x['status'], "headers-only")
tip_entry_found = True tip_entry_found = True
assert tip_entry_found assert tip_entry_found
# But this block should be accepted by node since it has equal work. # But this block should be accepted by node since it has equal work.
self.nodes[0].getblock(block_h2f.hash) self.nodes[0].getblock(block_h2f.hash_hex)
self.log.info("Second height 2 block accepted, but not reorg'ed to") self.log.info("Second height 2 block accepted, but not reorg'ed to")
# 4b. Now send another block that builds on the forking chain. # 4b. Now send another block that builds on the forking chain.
@@ -149,14 +149,14 @@ class AcceptBlockTest(BitcoinTestFramework):
# can't be fully validated. # can't be fully validated.
tip_entry_found = False tip_entry_found = False
for x in self.nodes[0].getchaintips(): for x in self.nodes[0].getchaintips():
if x['hash'] == block_h3.hash: if x['hash'] == block_h3.hash_hex:
assert_equal(x['status'], "headers-only") assert_equal(x['status'], "headers-only")
tip_entry_found = True tip_entry_found = True
assert tip_entry_found assert tip_entry_found
self.nodes[0].getblock(block_h3.hash) self.nodes[0].getblock(block_h3.hash_hex)
# But this block should be accepted by node since it has more work. # But this block should be accepted by node since it has more work.
self.nodes[0].getblock(block_h3.hash) self.nodes[0].getblock(block_h3.hash_hex)
self.log.info("Unrequested more-work block accepted") self.log.info("Unrequested more-work block accepted")
# 4c. Now mine 288 more blocks and deliver; all should be processed but # 4c. Now mine 288 more blocks and deliver; all should be processed but
@@ -172,8 +172,8 @@ class AcceptBlockTest(BitcoinTestFramework):
# Now send the block at height 5 and check that it wasn't accepted (missing header) # Now send the block at height 5 and check that it wasn't accepted (missing header)
test_node.send_without_ping(msg_block(all_blocks[1])) test_node.send_without_ping(msg_block(all_blocks[1]))
test_node.wait_for_disconnect() test_node.wait_for_disconnect()
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblock, all_blocks[1].hash) assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblock, all_blocks[1].hash_hex)
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblockheader, all_blocks[1].hash) assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblockheader, all_blocks[1].hash_hex)
test_node = self.nodes[0].add_p2p_connection(P2PInterface()) test_node = self.nodes[0].add_p2p_connection(P2PInterface())
# The block at height 5 should be accepted if we provide the missing header, though # The block at height 5 should be accepted if we provide the missing header, though
@@ -181,7 +181,7 @@ class AcceptBlockTest(BitcoinTestFramework):
headers_message.headers.append(CBlockHeader(all_blocks[0])) headers_message.headers.append(CBlockHeader(all_blocks[0]))
test_node.send_without_ping(headers_message) test_node.send_without_ping(headers_message)
test_node.send_and_ping(msg_block(all_blocks[1])) test_node.send_and_ping(msg_block(all_blocks[1]))
self.nodes[0].getblock(all_blocks[1].hash) self.nodes[0].getblock(all_blocks[1].hash_hex)
# Now send the blocks in all_blocks # Now send the blocks in all_blocks
for i in range(288): for i in range(288):
@@ -190,8 +190,8 @@ class AcceptBlockTest(BitcoinTestFramework):
# Blocks 1-287 should be accepted, block 288 should be ignored because it's too far ahead # Blocks 1-287 should be accepted, block 288 should be ignored because it's too far ahead
for x in all_blocks[:-1]: for x in all_blocks[:-1]:
self.nodes[0].getblock(x.hash) self.nodes[0].getblock(x.hash_hex)
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, all_blocks[-1].hash) assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, all_blocks[-1].hash_hex)
# 5. Test handling of unrequested block on the node that didn't process # 5. Test handling of unrequested block on the node that didn't process
# Should still not be processed (even though it has a child that has more # Should still not be processed (even though it has a child that has more
@@ -228,9 +228,9 @@ class AcceptBlockTest(BitcoinTestFramework):
# 7. Send the missing block for the third time (now it is requested) # 7. Send the missing block for the third time (now it is requested)
test_node.send_and_ping(msg_block(block_h1f)) test_node.send_and_ping(msg_block(block_h1f))
assert_equal(self.nodes[0].getblockcount(), 290) assert_equal(self.nodes[0].getblockcount(), 290)
self.nodes[0].getblock(all_blocks[286].hash) self.nodes[0].getblock(all_blocks[286].hash_hex)
assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash) assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash_hex)
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, all_blocks[287].hash) assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, all_blocks[287].hash_hex)
self.log.info("Successfully reorged to longer chain") self.log.info("Successfully reorged to longer chain")
# 8. Create a chain which is invalid at a height longer than the # 8. Create a chain which is invalid at a height longer than the
@@ -256,17 +256,17 @@ class AcceptBlockTest(BitcoinTestFramework):
tip_entry_found = False tip_entry_found = False
for x in self.nodes[0].getchaintips(): for x in self.nodes[0].getchaintips():
if x['hash'] == block_292.hash: if x['hash'] == block_292.hash_hex:
assert_equal(x['status'], "headers-only") assert_equal(x['status'], "headers-only")
tip_entry_found = True tip_entry_found = True
assert tip_entry_found assert tip_entry_found
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, block_292.hash) assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, block_292.hash_hex)
test_node.send_without_ping(msg_block(block_289f)) test_node.send_without_ping(msg_block(block_289f))
test_node.send_and_ping(msg_block(block_290f)) test_node.send_and_ping(msg_block(block_290f))
self.nodes[0].getblock(block_289f.hash) self.nodes[0].getblock(block_289f.hash_hex)
self.nodes[0].getblock(block_290f.hash) self.nodes[0].getblock(block_290f.hash_hex)
test_node.send_without_ping(msg_block(block_291)) test_node.send_without_ping(msg_block(block_291))
@@ -279,8 +279,8 @@ class AcceptBlockTest(BitcoinTestFramework):
# We should have failed reorg and switched back to 290 (but have block 291) # We should have failed reorg and switched back to 290 (but have block 291)
assert_equal(self.nodes[0].getblockcount(), 290) assert_equal(self.nodes[0].getblockcount(), 290)
assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash) assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash_hex)
assert_equal(self.nodes[0].getblock(block_291.hash)["confirmations"], -1) assert_equal(self.nodes[0].getblock(block_291.hash_hex)["confirmations"], -1)
# Now send a new header on the invalid chain, indicating we're forked off, and expect to get disconnected # Now send a new header on the invalid chain, indicating we're forked off, and expect to get disconnected
block_293 = create_block(block_292.hash_int, create_coinbase(293), block_292.nTime+1) block_293 = create_block(block_292.hash_int, create_coinbase(293), block_292.nTime+1)

View File

@@ -480,7 +480,7 @@ class BlockchainTest(BitcoinTestFramework):
assert_is_hex_string(header_hex) assert_is_hex_string(header_hex)
header = from_hex(CBlockHeader(), header_hex) header = from_hex(CBlockHeader(), header_hex)
assert_equal(header.hash, besthash) assert_equal(header.hash_hex, besthash)
assert 'previousblockhash' not in node.getblockheader(node.getblockhash(0)) assert 'previousblockhash' not in node.getblockheader(node.getblockhash(0))
assert 'nextblockhash' not in node.getblockheader(node.getbestblockhash()) assert 'nextblockhash' not in node.getblockheader(node.getbestblockhash())
@@ -623,7 +623,7 @@ class BlockchainTest(BitcoinTestFramework):
b1 = solve_and_send_block(int(fork_hash, 16), fork_height+1, fork_block['time'] + 1) b1 = solve_and_send_block(int(fork_hash, 16), fork_height+1, fork_block['time'] + 1)
b2 = solve_and_send_block(b1.hash_int, fork_height+2, b1.nTime + 1) b2 = solve_and_send_block(b1.hash_int, fork_height+2, b1.nTime + 1)
node.invalidateblock(b2.hash) node.invalidateblock(b2.hash_hex)
def assert_waitforheight(height, timeout=2): def assert_waitforheight(height, timeout=2):
assert_equal( assert_equal(
@@ -729,7 +729,7 @@ class BlockchainTest(BitcoinTestFramework):
block = create_block(int(blockhash, 16), create_coinbase(current_height + 1, nValue=100), block_time) block = create_block(int(blockhash, 16), create_coinbase(current_height + 1, nValue=100), block_time)
block.solve() block.solve()
node.submitheader(block.serialize().hex()) node.submitheader(block.serialize().hex())
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", lambda: node.getblock(block.hash)) assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", lambda: node.getblock(block.hash_hex))
self.log.info("Test getblock when block data is available but undo data isn't") self.log.info("Test getblock when block data is available but undo data isn't")
# Submits a block building on the header-only block, so it can't be connected and has no undo data # Submits a block building on the header-only block, so it can't be connected and has no undo data
@@ -738,10 +738,10 @@ class BlockchainTest(BitcoinTestFramework):
block_noundo.solve() block_noundo.solve()
node.submitblock(block_noundo.serialize().hex()) node.submitblock(block_noundo.serialize().hex())
assert_fee_not_in_block(block_noundo.hash, 2) assert_fee_not_in_block(block_noundo.hash_hex, 2)
assert_fee_not_in_block(block_noundo.hash, 3) assert_fee_not_in_block(block_noundo.hash_hex, 3)
assert_vin_does_not_contain_prevout(block_noundo.hash, 2) assert_vin_does_not_contain_prevout(block_noundo.hash_hex, 2)
assert_vin_does_not_contain_prevout(block_noundo.hash, 3) assert_vin_does_not_contain_prevout(block_noundo.hash_hex, 3)
self.log.info("Test getblock when block is missing") self.log.info("Test getblock when block is missing")
move_block_file('blk00000.dat', 'blk00000.dat.bak') move_block_file('blk00000.dat', 'blk00000.dat.bak')

View File

@@ -103,7 +103,7 @@ class InvalidateTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 3) assert_equal(self.nodes[0].getblockchaininfo()['headers'], 3)
# Reconsider the header # Reconsider the header
self.nodes[0].reconsiderblock(block.hash) self.nodes[0].reconsiderblock(block.hash_hex)
# Since header doesn't have block data, it can't be chain tip # Since header doesn't have block data, it can't be chain tip
# Check if it's possible for an ancestor (with block data) to be the chain tip # Check if it's possible for an ancestor (with block data) to be the chain tip
assert_equal(self.nodes[0].getbestblockhash(), blockhash_6) assert_equal(self.nodes[0].getbestblockhash(), blockhash_6)

View File

@@ -748,7 +748,7 @@ class CBlockHeader:
return r return r
@property @property
def hash(self): def hash_hex(self):
"""Return block header hash as hex string.""" """Return block header hash as hex string."""
return hash256(self._serialize_header())[::-1].hex() return hash256(self._serialize_header())[::-1].hex()

View File

@@ -896,9 +896,9 @@ class P2PDataStore(P2PInterface):
self.sync_with_ping(timeout=timeout) self.sync_with_ping(timeout=timeout)
if success: if success:
self.wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout) self.wait_until(lambda: node.getbestblockhash() == blocks[-1].hash_hex, timeout=timeout)
else: else:
assert_not_equal(node.getbestblockhash(), blocks[-1].hash) assert_not_equal(node.getbestblockhash(), blocks[-1].hash_hex)
def send_txs_and_test(self, txs, node, *, success=True, expect_disconnect=False, reject_reason=None): def send_txs_and_test(self, txs, node, *, success=True, expect_disconnect=False, reject_reason=None):
"""Send txs to test node and test whether they're accepted to the mempool. """Send txs to test node and test whether they're accepted to the mempool.