Skip to content

Commit a5227be

Browse files
committed
test: avoid uneeded block header hash -> integer conversions
1 parent 6a77931 commit a5227be

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

test/functional/feature_cltv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def run_test(self):
196196
self.test_cltv_info(is_active=True) # Not active as of current tip, but next block must obey rules
197197
peer.send_and_ping(msg_block(block))
198198
self.test_cltv_info(is_active=True) # Active as of current tip
199-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.hash_int)
199+
assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
200200

201201

202202
if __name__ == '__main__':

test/functional/feature_dersig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def run_test(self):
146146
self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules
147147
peer.send_and_ping(msg_block(block))
148148
self.test_dersig_info(is_active=True) # Active as of current tip
149-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.hash_int)
149+
assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
150150

151151

152152
if __name__ == '__main__':

test/functional/p2p_compactblocks.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def build_block_on_tip(self, node):
158158
def make_utxos(self):
159159
block = self.build_block_on_tip(self.nodes[0])
160160
self.segwit_node.send_and_ping(msg_no_witness_block(block))
161-
assert int(self.nodes[0].getbestblockhash(), 16) == block.hash_int
161+
assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
162162
self.generate(self.wallet, COINBASE_MATURITY)
163163

164164
total_value = block.vtx[0].vout[0].nValue
@@ -173,7 +173,7 @@ def make_utxos(self):
173173
block2.hashMerkleRoot = block2.calc_merkle_root()
174174
block2.solve()
175175
self.segwit_node.send_and_ping(msg_no_witness_block(block2))
176-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block2.hash_int)
176+
assert_equal(self.nodes[0].getbestblockhash(), block2.hash_hex)
177177
self.utxos.extend([[tx.txid_int, i, out_value] for i in range(10)])
178178

179179

@@ -406,7 +406,7 @@ def test_compactblock_requests(self, test_node):
406406
msg.block_transactions.blockhash = block.hash_int
407407
msg.block_transactions.transactions = [block.vtx[0]]
408408
test_node.send_and_ping(msg)
409-
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
409+
assert_equal(node.getbestblockhash(), block.hash_hex)
410410

411411
# Create a chain of transactions from given utxo, and add to a new block.
412412
def build_block_with_transactions(self, node, utxo, num_transactions):
@@ -555,7 +555,7 @@ def test_incorrect_blocktxn_response(self, test_node):
555555

556556
# Deliver the block
557557
test_node.send_and_ping(msg_block(block))
558-
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
558+
assert_equal(node.getbestblockhash(), block.hash_hex)
559559

560560
def test_getblocktxn_handler(self, test_node):
561561
node = self.nodes[0]
@@ -595,7 +595,7 @@ def test_getblocktxn_handler(self, test_node):
595595
test_node.last_message.pop("blocktxn", None)
596596
test_node.send_and_ping(msg)
597597
with p2p_lock:
598-
assert_equal(test_node.last_message["block"].block.hash_int, int(block_hash, 16))
598+
assert_equal(test_node.last_message["block"].block.hash_hex, block_hash)
599599
assert "blocktxn" not in test_node.last_message
600600

601601
# Request with out-of-bounds tx index results in disconnect
@@ -651,7 +651,7 @@ def test_compactblocks_not_at_tip(self, test_node):
651651
test_node.send_without_ping(msg_getdata([CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))]))
652652
test_node.wait_until(lambda: "block" in test_node.last_message, timeout=30)
653653
with p2p_lock:
654-
assert_equal(test_node.last_message["block"].block.hash_int, int(new_blocks[0], 16))
654+
assert_equal(test_node.last_message["block"].block.hash_hex, new_blocks[0])
655655

656656
# Generate an old compactblock, and verify that it's not accepted.
657657
cur_height = node.getblockcount()
@@ -724,7 +724,7 @@ def test_invalid_tx_in_compactblock(self, test_node):
724724
test_node.send_and_ping(msg)
725725

726726
# Check that the tip didn't advance
727-
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
727+
assert_not_equal(node.getbestblockhash(), block.hash_hex)
728728
test_node.sync_with_ping()
729729

730730
# Helper for enabling cb announcements
@@ -761,7 +761,7 @@ def announce_cmpct_block(node, peer):
761761
assert tx.txid_hex in mempool
762762

763763
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
764-
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
764+
assert_equal(node.getbestblockhash(), block.hash_hex)
765765

766766
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
767767

@@ -777,13 +777,13 @@ def announce_cmpct_block(node, peer):
777777

778778
cmpct_block.use_witness = True
779779
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
780-
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
780+
assert_not_equal(node.getbestblockhash(), block.hash_hex)
781781

782782
msg = msg_no_witness_blocktxn()
783783
msg.block_transactions.blockhash = block.hash_int
784784
msg.block_transactions.transactions = block.vtx[1:]
785785
stalling_peer.send_and_ping(msg)
786-
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
786+
assert_equal(node.getbestblockhash(), block.hash_hex)
787787

788788
def test_highbandwidth_mode_states_via_getpeerinfo(self):
789789
# create new p2p connection for a fresh state w/o any prior sendcmpct messages sent
@@ -839,7 +839,7 @@ def announce_cmpct_block(node, peer, txn_count):
839839
msg.block_transactions.blockhash = block.hash_int
840840
msg.block_transactions.transactions = block.vtx[1:]
841841
peer.send_and_ping(msg)
842-
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
842+
assert_equal(node.getbestblockhash(), block.hash_hex)
843843
peer.clear_getblocktxn()
844844

845845
# Test the simple parallel download case...
@@ -854,26 +854,26 @@ def announce_cmpct_block(node, peer, txn_count):
854854
with p2p_lock:
855855
# The second peer to announce should still get a getblocktxn
856856
assert "getblocktxn" in delivery_peer.last_message
857-
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
857+
assert_not_equal(node.getbestblockhash(), block.hash_hex)
858858

859859
inbound_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
860860
with p2p_lock:
861861
# The third inbound peer to announce should *not* get a getblocktxn
862862
assert "getblocktxn" not in inbound_peer.last_message
863-
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
863+
assert_not_equal(node.getbestblockhash(), block.hash_hex)
864864

865865
outbound_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
866866
with p2p_lock:
867867
# The third peer to announce should get a getblocktxn if outbound
868868
assert "getblocktxn" in outbound_peer.last_message
869-
assert_not_equal(int(node.getbestblockhash(), 16), block.hash_int)
869+
assert_not_equal(node.getbestblockhash(), block.hash_hex)
870870

871871
# Second peer completes the compact block first
872872
msg = msg_blocktxn()
873873
msg.block_transactions.blockhash = block.hash_int
874874
msg.block_transactions.transactions = block.vtx[1:]
875875
delivery_peer.send_and_ping(msg)
876-
assert_equal(int(node.getbestblockhash(), 16), block.hash_int)
876+
assert_equal(node.getbestblockhash(), block.hash_hex)
877877

878878
# Nothing bad should happen if we get a late fill from the first peer...
879879
stalling_peer.send_and_ping(msg)

test/functional/p2p_compactblocks_blocksonly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ def run_test(self):
7272
# A -blocksonly node should not request BIP152 high bandwidth mode upon
7373
# receiving a new valid block at the tip.
7474
p2p_conn_blocksonly.send_and_ping(msg_block(block0))
75-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block0.hash_int)
75+
assert_equal(self.nodes[0].getbestblockhash(), block0.hash_hex)
7676
assert_equal(p2p_conn_blocksonly.message_count['sendcmpct'], 1)
7777
assert_equal(p2p_conn_blocksonly.last_message['sendcmpct'].announce, False)
7878

7979
# A normal node participating in transaction relay should request BIP152
8080
# high bandwidth mode upon receiving a new valid block at the tip.
8181
p2p_conn_high_bw.send_and_ping(msg_block(block0))
82-
assert_equal(int(self.nodes[1].getbestblockhash(), 16), block0.hash_int)
82+
assert_equal(self.nodes[1].getbestblockhash(), block0.hash_hex)
8383
p2p_conn_high_bw.wait_until(lambda: p2p_conn_high_bw.message_count['sendcmpct'] == 2)
8484
assert_equal(p2p_conn_high_bw.last_message['sendcmpct'].announce, True)
8585

test/functional/p2p_invalid_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def run_test(self):
115115
# Update tip info
116116
height += 1
117117
block_time += 1
118-
tip = int(block2_orig.hash_hex, 16)
118+
tip = block2_orig.hash_int
119119

120120
# Complete testing of CVE-2018-17144, by checking for the inflation bug.
121121
# Create a block that spends the output of a tx in a previous block.

test/functional/p2p_sendheaders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ def test_null_locators(self, test_node, inv_node):
247247
block.solve()
248248
test_node.send_header_for_blocks([block])
249249
test_node.clear_block_announcements()
250-
test_node.send_get_headers(locator=[], hashstop=int(block.hash_hex, 16))
250+
test_node.send_get_headers(locator=[], hashstop=block.hash_int)
251251
test_node.sync_with_ping()
252252
assert_equal(test_node.block_announced, False)
253253
inv_node.clear_block_announcements()
254254
test_node.send_without_ping(msg_block(block))
255-
inv_node.check_last_inv_announcement(inv=[int(block.hash_hex, 16)])
255+
inv_node.check_last_inv_announcement(inv=[block.hash_int])
256256

257257
def test_nonnull_locators(self, test_node, inv_node):
258258
tip = int(self.nodes[0].getbestblockhash(), 16)
@@ -538,7 +538,7 @@ def test_nonnull_locators(self, test_node, inv_node):
538538
test_node.wait_for_getdata([x.hash_int for x in blocks])
539539
[test_node.send_without_ping(msg_block(x)) for x in blocks]
540540
test_node.sync_with_ping()
541-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), blocks[1].hash_int)
541+
assert_equal(self.nodes[0].getbestblockhash(), blocks[1].hash_hex)
542542
expected_hash = blocks[1].hash_int
543543

544544
blocks = []

test/functional/test_framework/p2p.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def test_function():
634634
last_headers = self.last_message.get('headers')
635635
if not last_headers:
636636
return False
637-
return last_headers.headers[0].hash_int == int(blockhash, 16)
637+
return last_headers.headers[0].hash_hex == blockhash
638638

639639
self.wait_until(test_function, timeout=timeout)
640640

@@ -643,7 +643,7 @@ def test_function():
643643
last_filtered_block = self.last_message.get('merkleblock')
644644
if not last_filtered_block:
645645
return False
646-
return last_filtered_block.merkleblock.header.hash_int == int(blockhash, 16)
646+
return last_filtered_block.merkleblock.header.hash_hex == blockhash
647647

648648
self.wait_until(test_function, timeout=timeout)
649649

0 commit comments

Comments
 (0)