Skip to content

Commit 757a921

Browse files
committed
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).
1 parent a81c805 commit 757a921

22 files changed

+85
-85
lines changed

contrib/signet/miner

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,15 @@ def do_generate(args):
481481
# report
482482
bstr = "block" if gen.is_mine else "backup block"
483483

484-
next_delta = gen.next_block_delta(block.nBits, block.hash)
484+
next_delta = gen.next_block_delta(block.nBits, block.hash_hex)
485485
next_delta += block.nTime - time.time()
486-
next_is_mine = gen.next_block_is_mine(block.hash)
486+
next_is_mine = gen.next_block_is_mine(block.hash_hex)
487487

488-
logging.debug("Block hash %s payout to %s", block.hash, reward_addr)
488+
logging.debug("Block hash %s payout to %s", block.hash_hex, reward_addr)
489489
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"))
490490
if r != "":
491-
logging.warning("submitblock returned %s for height %d hash %s", r, tmpl["height"], block.hash)
492-
lastheader = block.hash
491+
logging.warning("submitblock returned %s for height %d hash %s", r, tmpl["height"], block.hash_hex)
492+
lastheader = block.hash_hex
493493

494494
def do_calibrate(args):
495495
if args.nbits is not None and args.seconds is not None:

test/functional/feature_assumeutxo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ def check_tx_counts(final: bool) -> None:
544544
"""Check nTx and nChainTx intermediate values right after loading
545545
the snapshot, and final values after the snapshot is validated."""
546546
for height, block in blocks.items():
547-
tx = n1.getblockheader(block.hash)["nTx"]
548-
stats = n1.getchaintxstats(nblocks=1, blockhash=block.hash)
547+
tx = n1.getblockheader(block.hash_hex)["nTx"]
548+
stats = n1.getchaintxstats(nblocks=1, blockhash=block.hash_hex)
549549
chain_tx = stats.get("txcount", None)
550550
window_tx_count = stats.get("window_tx_count", None)
551551
tx_rate = stats.get("txrate", None)

test/functional/feature_assumevalid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ def run_test(self):
138138
height += 1
139139

140140
# Start node1 and node2 with assumevalid so they accept a block with a bad signature.
141-
self.start_node(1, extra_args=["-assumevalid=" + block102.hash])
142-
self.start_node(2, extra_args=["-assumevalid=" + block102.hash])
141+
self.start_node(1, extra_args=["-assumevalid=" + block102.hash_hex])
142+
self.start_node(2, extra_args=["-assumevalid=" + block102.hash_hex])
143143

144144
p2p0 = self.nodes[0].add_p2p_connection(BaseNode())
145145
p2p0.send_header_for_blocks(self.blocks[0:2000])

test/functional/feature_bip68_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def test_bip68_not_consensus(self):
381381
block.solve()
382382

383383
assert_equal(None, self.nodes[0].submitblock(block.serialize().hex()))
384-
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
384+
assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
385385

386386
def activateCSV(self):
387387
# activation should happen at block height 432 (3 periods)

test/functional/feature_block.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def run_test(self):
280280
self.send_blocks([b12, b13, b14], success=False, reject_reason='bad-cb-amount', reconnect=True)
281281

282282
# New tip should be b13.
283-
assert_equal(node.getbestblockhash(), b13.hash)
283+
assert_equal(node.getbestblockhash(), b13.hash_hex)
284284

285285
# Add a block with MAX_BLOCK_SIGOPS and one with one more sigop
286286
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -735,7 +735,7 @@ def run_test(self):
735735
self.block_heights[b48.hash_int] = self.block_heights[b44.hash_int] + 1 # b48 is a parent of b44
736736
b48p = self.next_block("48p")
737737
self.send_blocks([b48, b48p], success=True) # Reorg to the longer chain
738-
node.invalidateblock(b48p.hash) # mark b48p as invalid
738+
node.invalidateblock(b48p.hash_hex) # mark b48p as invalid
739739
node.setmocktime(0)
740740

741741
# Test Merkle tree malleability
@@ -779,7 +779,7 @@ def run_test(self):
779779
self.blocks[56] = b56
780780
assert_equal(len(b56.vtx), 3)
781781
b56 = self.update_block(56, [tx1])
782-
assert_equal(b56.hash, b57.hash)
782+
assert_equal(b56.hash_hex, b57.hash_hex)
783783
self.send_blocks([b56], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
784784

785785
# b57p2 - a good block with 6 tx'es, don't submit until end
@@ -797,7 +797,7 @@ def run_test(self):
797797
self.move_tip(55)
798798
b56p2 = copy.deepcopy(b57p2)
799799
self.blocks["b56p2"] = b56p2
800-
assert_equal(b56p2.hash, b57p2.hash)
800+
assert_equal(b56p2.hash_hex, b57p2.hash_hex)
801801
assert_equal(len(b56p2.vtx), 6)
802802
b56p2 = self.update_block("b56p2", [tx3, tx4])
803803
self.send_blocks([b56p2], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
@@ -955,7 +955,7 @@ def run_test(self):
955955
self.move_tip('dup_2')
956956
b64 = CBlock(b64a)
957957
b64.vtx = copy.deepcopy(b64a.vtx)
958-
assert_equal(b64.hash, b64a.hash)
958+
assert_equal(b64.hash_hex, b64a.hash_hex)
959959
assert_equal(b64.get_weight(), MAX_BLOCK_WEIGHT)
960960
self.blocks[64] = b64
961961
b64 = self.update_block(64, [])

test/functional/feature_cltv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ def run_test(self):
127127
self.test_cltv_info(is_active=False) # Not active as of current tip and next block does not need to obey rules
128128
peer.send_and_ping(msg_block(block))
129129
self.test_cltv_info(is_active=True) # Not active as of current tip, but next block must obey rules
130-
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
130+
assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
131131

132132
self.log.info("Test that blocks must now be at least version 4")
133133
tip = block.hash_int
134134
block_time += 1
135135
block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time, version=3)
136136
block.solve()
137137

138-
with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash}, bad-version(0x00000003)']):
138+
with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash_hex}, bad-version(0x00000003)']):
139139
peer.send_and_ping(msg_block(block))
140140
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
141141
peer.sync_with_ping()

test/functional/feature_dersig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ def run_test(self):
9292
peer.send_and_ping(msg_block(block))
9393
assert_equal(self.nodes[0].getblockcount(), DERSIG_HEIGHT - 1)
9494
self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules
95-
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
95+
assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
9696

9797
self.log.info("Test that blocks must now be at least version 3")
9898
tip = block.hash_int
9999
block_time += 1
100100
block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time, version=2)
101101
block.solve()
102102

103-
with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash}, bad-version(0x00000002)']):
103+
with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash_hex}, bad-version(0x00000002)']):
104104
peer.send_and_ping(msg_block(block))
105105
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
106106
peer.sync_with_ping()

test/functional/feature_taproot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,9 +1337,9 @@ def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_w
13371337
if err_msg is not None:
13381338
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)
13391339
if accept:
1340-
assert node.getbestblockhash() == block.hash, "Failed to accept: %s (response: %s)" % (msg, block_response)
1340+
assert node.getbestblockhash() == block.hash_hex, "Failed to accept: %s (response: %s)" % (msg, block_response)
13411341
self.tip = block.hash_int
1342-
self.lastblockhash = block.hash
1342+
self.lastblockhash = block.hash_hex
13431343
self.lastblocktime += 1
13441344
self.lastblockheight += 1
13451345
else:

test/functional/mining_basic.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,25 +537,25 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
537537
def chain_tip(b_hash, *, status='headers-only', branchlen=1):
538538
return {'hash': b_hash, 'height': 202, 'branchlen': branchlen, 'status': status}
539539

540-
assert chain_tip(block.hash) not in node.getchaintips()
540+
assert chain_tip(block.hash_hex) not in node.getchaintips()
541541
node.submitheader(hexdata=block.serialize().hex())
542-
assert chain_tip(block.hash) in node.getchaintips()
542+
assert chain_tip(block.hash_hex) in node.getchaintips()
543543
node.submitheader(hexdata=CBlockHeader(block).serialize().hex()) # Noop
544-
assert chain_tip(block.hash) in node.getchaintips()
544+
assert chain_tip(block.hash_hex) in node.getchaintips()
545545

546546
bad_block_root = copy.deepcopy(block)
547547
bad_block_root.hashMerkleRoot += 2
548548
bad_block_root.solve()
549-
assert chain_tip(bad_block_root.hash) not in node.getchaintips()
549+
assert chain_tip(bad_block_root.hash_hex) not in node.getchaintips()
550550
node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex())
551-
assert chain_tip(bad_block_root.hash) in node.getchaintips()
551+
assert chain_tip(bad_block_root.hash_hex) in node.getchaintips()
552552
# Should still reject invalid blocks, even if we have the header:
553553
assert_equal(node.submitblock(hexdata=bad_block_root.serialize().hex()), 'bad-txnmrklroot')
554554
assert_equal(node.submitblock(hexdata=bad_block_root.serialize().hex()), 'bad-txnmrklroot')
555-
assert chain_tip(bad_block_root.hash) in node.getchaintips()
555+
assert chain_tip(bad_block_root.hash_hex) in node.getchaintips()
556556
# We know the header for this invalid block, so should just return early without error:
557557
node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex())
558-
assert chain_tip(bad_block_root.hash) in node.getchaintips()
558+
assert chain_tip(bad_block_root.hash_hex) in node.getchaintips()
559559

560560
bad_block_lock = copy.deepcopy(block)
561561
bad_block_lock.vtx[0].nLockTime = 2**32 - 1
@@ -580,7 +580,7 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
580580
peer.wait_for_getheaders(timeout=5, block_hash=block.hashPrevBlock)
581581
peer.send_blocks_and_test(blocks=[block], node=node)
582582
# Must be active now:
583-
assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips()
583+
assert chain_tip(block.hash_hex, status='active', branchlen=0) in node.getchaintips()
584584

585585
# Building a few blocks should give the same results
586586
self.generatetoaddress(node, 10, node.get_deterministic_priv_key().address)

test/functional/mining_mainnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def mine(self, height, prev_hash, blocks, node, fees=0):
7070
self.log.debug(block_hex)
7171
assert_equal(node.submitblock(block_hex), None)
7272
prev_hash = node.getbestblockhash()
73-
assert_equal(prev_hash, block.hash)
73+
assert_equal(prev_hash, block.hash_hex)
7474
return prev_hash
7575

7676

0 commit comments

Comments
 (0)