From 2118301d77c20e31e8c280ed3bf3c7d67c07d3ca Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Thu, 12 Jun 2025 15:13:11 +0200 Subject: [PATCH] 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). --- contrib/signet/miner | 10 ++--- test/functional/feature_assumevalid.py | 4 +- test/functional/feature_bip68_sequence.py | 2 +- test/functional/feature_block.py | 10 ++--- test/functional/feature_cltv.py | 4 +- test/functional/feature_dersig.py | 4 +- test/functional/feature_nulldummy.py | 4 +- test/functional/feature_taproot.py | 4 +- test/functional/mining_basic.py | 16 ++++---- test/functional/mining_mainnet.py | 2 +- test/functional/p2p_compactblocks.py | 4 +- test/functional/p2p_fingerprint.py | 2 +- test/functional/p2p_invalid_block.py | 2 +- test/functional/p2p_invalid_messages.py | 6 +-- test/functional/p2p_mutated_blocks.py | 2 +- test/functional/p2p_segwit.py | 20 +++++----- test/functional/p2p_sendheaders.py | 4 +- test/functional/p2p_unrequested_blocks.py | 46 +++++++++++----------- test/functional/rpc_blockchain.py | 14 +++---- test/functional/rpc_invalidateblock.py | 2 +- test/functional/test_framework/messages.py | 2 +- test/functional/test_framework/p2p.py | 4 +- 22 files changed, 84 insertions(+), 84 deletions(-) diff --git a/contrib/signet/miner b/contrib/signet/miner index 4a5058afb29..8c7edc56a32 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -481,15 +481,15 @@ def do_generate(args): # report 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_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")) if r != "": - logging.warning("submitblock returned %s for height %d hash %s", r, tmpl["height"], block.hash) - lastheader = block.hash + logging.warning("submitblock returned %s for height %d hash %s", r, tmpl["height"], block.hash_hex) + lastheader = block.hash_hex def do_calibrate(args): if args.nbits is not None and args.seconds is not None: diff --git a/test/functional/feature_assumevalid.py b/test/functional/feature_assumevalid.py index 0b6998c15b0..7d097b1395b 100755 --- a/test/functional/feature_assumevalid.py +++ b/test/functional/feature_assumevalid.py @@ -138,8 +138,8 @@ class AssumeValidTest(BitcoinTestFramework): height += 1 # 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(2, extra_args=["-assumevalid=" + block102.hash]) + self.start_node(1, extra_args=["-assumevalid=" + block102.hash_hex]) + self.start_node(2, extra_args=["-assumevalid=" + block102.hash_hex]) p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) p2p0.send_header_for_blocks(self.blocks[0:2000]) diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py index eeb98a72604..2f54183fd70 100755 --- a/test/functional/feature_bip68_sequence.py +++ b/test/functional/feature_bip68_sequence.py @@ -383,7 +383,7 @@ class BIP68Test(BitcoinTestFramework): block.solve() 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): # activation should happen at block height 432 (3 periods) diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index 3a477f969b2..63592122be8 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -280,7 +280,7 @@ class FullBlockTest(BitcoinTestFramework): self.send_blocks([b12, b13, b14], success=False, reject_reason='bad-cb-amount', reconnect=True) # 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 # 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 b48p = self.next_block("48p") 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) # Test Merkle tree malleability @@ -778,7 +778,7 @@ class FullBlockTest(BitcoinTestFramework): self.blocks[56] = b56 assert_equal(len(b56.vtx), 3) 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) # b57p2 - a good block with 6 tx'es, don't submit until end @@ -796,7 +796,7 @@ class FullBlockTest(BitcoinTestFramework): self.move_tip(55) b56p2 = copy.deepcopy(b57p2) self.blocks["b56p2"] = b56p2 - assert_equal(b56p2.hash, b57p2.hash) + assert_equal(b56p2.hash_hex, b57p2.hash_hex) assert_equal(len(b56p2.vtx), 6) b56p2 = self.update_block("b56p2", [tx3, tx4]) 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') b64 = CBlock(b64a) 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) self.blocks[64] = b64 b64 = self.update_block(64, []) diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py index 9d2060405da..79ed49f86e4 100755 --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -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 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 - 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") tip = block.hash_int @@ -135,7 +135,7 @@ class BIP65Test(BitcoinTestFramework): block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time, version=3) 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)) assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip) peer.sync_with_ping() diff --git a/test/functional/feature_dersig.py b/test/functional/feature_dersig.py index f20b045cea4..3e159999957 100755 --- a/test/functional/feature_dersig.py +++ b/test/functional/feature_dersig.py @@ -92,7 +92,7 @@ class BIP66Test(BitcoinTestFramework): peer.send_and_ping(msg_block(block)) 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 - 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") tip = block.hash_int @@ -100,7 +100,7 @@ class BIP66Test(BitcoinTestFramework): block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time, version=2) 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)) assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip) peer.sync_with_ping() diff --git a/test/functional/feature_nulldummy.py b/test/functional/feature_nulldummy.py index e04412f3b2d..f301d65a702 100755 --- a/test/functional/feature_nulldummy.py +++ b/test/functional/feature_nulldummy.py @@ -143,8 +143,8 @@ class NULLDUMMYTest(BitcoinTestFramework): block.solve() assert_equal(None if accept else NULLDUMMY_ERROR, node.submitblock(block.serialize().hex())) if accept: - assert_equal(node.getbestblockhash(), block.hash) - self.lastblockhash = block.hash + assert_equal(node.getbestblockhash(), block.hash_hex) + self.lastblockhash = block.hash_hex self.lastblocktime += 1 self.lastblockheight += 1 else: diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py index 2e427ec0d7b..6109fd9b9d8 100755 --- a/test/functional/feature_taproot.py +++ b/test/functional/feature_taproot.py @@ -1341,9 +1341,9 @@ class TaprootTest(BitcoinTestFramework): 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) 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.lastblockhash = block.hash + self.lastblockhash = block.hash_hex self.lastblocktime += 1 self.lastblockheight += 1 else: diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index b60d07b52fa..a4e482f6a01 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -445,25 +445,25 @@ class MiningTest(BitcoinTestFramework): def chain_tip(b_hash, *, status='headers-only', branchlen=1): 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()) - 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 - 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.hashMerkleRoot += 2 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()) - 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: 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: 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.vtx[0].nLockTime = 2**32 - 1 @@ -488,7 +488,7 @@ class MiningTest(BitcoinTestFramework): peer.wait_for_getheaders(timeout=5, block_hash=block.hashPrevBlock) peer.send_blocks_and_test(blocks=[block], node=node) # 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 self.generatetoaddress(node, 10, node.get_deterministic_priv_key().address) diff --git a/test/functional/mining_mainnet.py b/test/functional/mining_mainnet.py index e9aaa36da35..dbe6248fd74 100755 --- a/test/functional/mining_mainnet.py +++ b/test/functional/mining_mainnet.py @@ -70,7 +70,7 @@ class MiningMainnetTest(BitcoinTestFramework): self.log.debug(block_hex) assert_equal(node.submitblock(block_hex), None) prev_hash = node.getbestblockhash() - assert_equal(prev_hash, block.hash) + assert_equal(prev_hash, block.hash_hex) return prev_hash diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index c006910d443..319d8d2beba 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -623,7 +623,7 @@ class CompactBlocksTest(BitcoinTestFramework): tips = node.getchaintips() found = False for x in tips: - if x["hash"] == block.hash: + if x["hash"] == block.hash_hex: found = True break assert not found @@ -667,7 +667,7 @@ class CompactBlocksTest(BitcoinTestFramework): tips = node.getchaintips() found = False for x in tips: - if x["hash"] == block.hash: + if x["hash"] == block.hash_hex: assert_equal(x["status"], "headers-only") found = True break diff --git a/test/functional/p2p_fingerprint.py b/test/functional/p2p_fingerprint.py index 99030141505..738b10c0e40 100755 --- a/test/functional/p2p_fingerprint.py +++ b/test/functional/p2p_fingerprint.py @@ -41,7 +41,7 @@ class P2PFingerprintTest(BitcoinTestFramework): block.solve() blocks.append(block) - prev_hash = block.hash + prev_hash = block.hash_hex prev_height += 1 prev_median_time = block_time return blocks diff --git a/test/functional/p2p_invalid_block.py b/test/functional/p2p_invalid_block.py index 6252d0e6239..8fb20f53dde 100755 --- a/test/functional/p2p_invalid_block.py +++ b/test/functional/p2p_invalid_block.py @@ -115,7 +115,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework): # Update tip info height += 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. # Create a block that spends the output of a tx in a previous block. diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py index 1685eebd4a4..e629a5998d6 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -288,17 +288,17 @@ class InvalidMessagesTest(BitcoinTestFramework): blockheader.hashPrevBlock = int(blockheader_tip_hash, 16) blockheader.nTime = int(time.time()) blockheader.nBits = blockheader_tip.nBits - while not blockheader.hash.startswith('0'): + while not blockheader.hash_hex.startswith('0'): blockheader.nNonce += 1 peer = self.nodes[0].add_p2p_connection(P2PInterface()) peer.send_and_ping(msg_headers([blockheader])) assert_equal(self.nodes[0].getblockchaininfo()['headers'], 1) chaintips = self.nodes[0].getchaintips() assert_equal(chaintips[0]['status'], 'headers-only') - assert_equal(chaintips[0]['hash'], blockheader.hash) + assert_equal(chaintips[0]['hash'], blockheader.hash_hex) # invalidate PoW - while not blockheader.hash.startswith('f'): + while not blockheader.hash_hex.startswith('f'): blockheader.nNonce += 1 with self.nodes[0].assert_debug_log(['Misbehaving', 'header with invalid proof of work']): peer.send_without_ping(msg_headers([blockheader])) diff --git a/test/functional/p2p_mutated_blocks.py b/test/functional/p2p_mutated_blocks.py index 874c264d646..b9ce50bf291 100755 --- a/test/functional/p2p_mutated_blocks.py +++ b/test/functional/p2p_mutated_blocks.py @@ -95,7 +95,7 @@ class MutatedBlocksTest(BitcoinTestFramework): block_txn = msg_blocktxn() block_txn.block_transactions = BlockTransactions(blockhash=block.hash_int, transactions=[tx]) 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 assert_equal(len(self.nodes[0].getpeerinfo()), 1) diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py index 101cccc70e2..7dc904a45f6 100755 --- a/test/functional/p2p_segwit.py +++ b/test/functional/p2p_segwit.py @@ -143,7 +143,7 @@ def test_witness_block(node, p2p, block, accepted, with_witness=True, reason=Non reason = [reason] if reason else [] with node.assert_debug_log(expected_msgs=reason): 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): @@ -346,7 +346,7 @@ class SegWitTest(BitcoinTestFramework): # But it should not be permanently marked bad... # Resend without witness information. 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. self.utxo.pop(0) @@ -413,7 +413,7 @@ class SegWitTest(BitcoinTestFramework): assert len(block.vtx[0].wit.vtxinwit[0].scriptWitness.stack) == 1 test_witness_block(self.nodes[0], self.test_node, block, accepted=True) # 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) wit_block = self.test_node.request_block(block.hash_int, 2 | MSG_WITNESS_FLAG) assert_equal(wit_block.serialize(), bytes.fromhex(rpc_block)) @@ -421,7 +421,7 @@ class SegWitTest(BitcoinTestFramework): assert_equal(wit_block.serialize(), block.serialize()) # 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["strippedsize"], len(block.serialize(False))) 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 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() assert block.get_weight() < MAX_BLOCK_WEIGHT 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 # result in a block permanently marked bad. @@ -926,14 +926,14 @@ class SegWitTest(BitcoinTestFramework): block.vtx[0].wit = CTxWitness() # drop the nonce block.solve() 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. add_witness_commitment(block, nonce=0) block.vtx[0].wit = CTxWitness() block.solve() 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 # the commitment. @@ -949,7 +949,7 @@ class SegWitTest(BitcoinTestFramework): assert_equal('bad-txnmrklroot', self.nodes[0].submitblock(block_2.serialize().hex())) # 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 def test_extra_witness_data(self): @@ -1891,7 +1891,7 @@ class SegWitTest(BitcoinTestFramework): # Reset the tip back down for the next test self.sync_blocks() 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 # output of tx diff --git a/test/functional/p2p_sendheaders.py b/test/functional/p2p_sendheaders.py index 49680e5d626..08722e4d50f 100755 --- a/test/functional/p2p_sendheaders.py +++ b/test/functional/p2p_sendheaders.py @@ -247,12 +247,12 @@ class SendHeadersTest(BitcoinTestFramework): block.solve() test_node.send_header_for_blocks([block]) 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() assert_equal(test_node.block_announced, False) inv_node.clear_block_announcements() 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): tip = int(self.nodes[0].getbestblockhash(), 16) diff --git a/test/functional/p2p_unrequested_blocks.py b/test/functional/p2p_unrequested_blocks.py index c8b99a10266..b165b809d78 100755 --- a/test/functional/p2p_unrequested_blocks.py +++ b/test/functional/p2p_unrequested_blocks.py @@ -97,14 +97,14 @@ class AcceptBlockTest(BitcoinTestFramework): block_time += 1 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])) assert_equal(self.nodes[0].getblockcount(), 2) assert_equal(self.nodes[1].getblockcount(), 1) # 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") # 3. Send another block that builds on genesis. @@ -115,11 +115,11 @@ class AcceptBlockTest(BitcoinTestFramework): tip_entry_found = False 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") tip_entry_found = True 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. 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. tip_entry_found = False 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") tip_entry_found = True assert tip_entry_found # 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") # 4b. Now send another block that builds on the forking chain. @@ -149,14 +149,14 @@ class AcceptBlockTest(BitcoinTestFramework): # can't be fully validated. tip_entry_found = False 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") tip_entry_found = True 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. - self.nodes[0].getblock(block_h3.hash) + self.nodes[0].getblock(block_h3.hash_hex) self.log.info("Unrequested more-work block accepted") # 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) test_node.send_without_ping(msg_block(all_blocks[1])) 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].getblockheader, 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_hex) test_node = self.nodes[0].add_p2p_connection(P2PInterface()) # 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])) test_node.send_without_ping(headers_message) 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 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 for x in all_blocks[:-1]: - self.nodes[0].getblock(x.hash) - assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, all_blocks[-1].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_hex) # 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 @@ -228,9 +228,9 @@ class AcceptBlockTest(BitcoinTestFramework): # 7. Send the missing block for the third time (now it is requested) test_node.send_and_ping(msg_block(block_h1f)) assert_equal(self.nodes[0].getblockcount(), 290) - self.nodes[0].getblock(all_blocks[286].hash) - assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash) - assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, all_blocks[287].hash) + self.nodes[0].getblock(all_blocks[286].hash_hex) + 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_hex) self.log.info("Successfully reorged to longer chain") # 8. Create a chain which is invalid at a height longer than the @@ -256,17 +256,17 @@ class AcceptBlockTest(BitcoinTestFramework): tip_entry_found = False 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") tip_entry_found = True 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_and_ping(msg_block(block_290f)) - self.nodes[0].getblock(block_289f.hash) - self.nodes[0].getblock(block_290f.hash) + self.nodes[0].getblock(block_289f.hash_hex) + self.nodes[0].getblock(block_290f.hash_hex) 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) assert_equal(self.nodes[0].getblockcount(), 290) - assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash) - assert_equal(self.nodes[0].getblock(block_291.hash)["confirmations"], -1) + assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash_hex) + 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 block_293 = create_block(block_292.hash_int, create_coinbase(293), block_292.nTime+1) diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 7f6ad587bf2..d29290fbf6e 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -480,7 +480,7 @@ class BlockchainTest(BitcoinTestFramework): assert_is_hex_string(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 '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) 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): 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.solve() 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") # 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() node.submitblock(block_noundo.serialize().hex()) - assert_fee_not_in_block(block_noundo.hash, 2) - assert_fee_not_in_block(block_noundo.hash, 3) - assert_vin_does_not_contain_prevout(block_noundo.hash, 2) - assert_vin_does_not_contain_prevout(block_noundo.hash, 3) + assert_fee_not_in_block(block_noundo.hash_hex, 2) + assert_fee_not_in_block(block_noundo.hash_hex, 3) + assert_vin_does_not_contain_prevout(block_noundo.hash_hex, 2) + assert_vin_does_not_contain_prevout(block_noundo.hash_hex, 3) self.log.info("Test getblock when block is missing") move_block_file('blk00000.dat', 'blk00000.dat.bak') diff --git a/test/functional/rpc_invalidateblock.py b/test/functional/rpc_invalidateblock.py index 17086a649df..78073bd4420 100755 --- a/test/functional/rpc_invalidateblock.py +++ b/test/functional/rpc_invalidateblock.py @@ -103,7 +103,7 @@ class InvalidateTest(BitcoinTestFramework): assert_equal(self.nodes[0].getblockchaininfo()['headers'], 3) # 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 # Check if it's possible for an ancestor (with block data) to be the chain tip assert_equal(self.nodes[0].getbestblockhash(), blockhash_6) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 104fda94174..2c815ce596e 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -748,7 +748,7 @@ class CBlockHeader: return r @property - def hash(self): + def hash_hex(self): """Return block header hash as hex string.""" return hash256(self._serialize_header())[::-1].hex() diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index fbbf4189cc1..610aa4ccca2 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -896,9 +896,9 @@ class P2PDataStore(P2PInterface): self.sync_with_ping(timeout=timeout) 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: - 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): """Send txs to test node and test whether they're accepted to the mempool.