Skip to content

Commit 8543828

Browse files
committed
refactor: test: improve wait_for{header,merkleblock} interface
The interfaces for the methods wait_for_header() and wait_for_merkleblock() are changed to take a hex string instead of an integer, improving type safety and removing the burden from the caller to always do the transformation via `int(...)`. As suggested by MarcoFalke in bitcoin/bitcoin#18593 (comment)
1 parent 1356a45 commit 8543828

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

test/functional/p2p_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ def run_test(self):
6868
self.log.info('Check that we receive merkleblock and tx if the filter matches a tx in a block')
6969
block_hash = self.nodes[0].generatetoaddress(1, filter_address)[0]
7070
txid = self.nodes[0].getblock(block_hash)['tx'][0]
71-
filter_node.wait_for_merkleblock(int(block_hash, 16))
71+
filter_node.wait_for_merkleblock(block_hash)
7272
filter_node.wait_for_tx(txid)
7373

7474
self.log.info('Check that we only receive a merkleblock if the filter does not match a tx in a block')
7575
filter_node.tx_received = False
7676
block_hash = self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress())[0]
77-
filter_node.wait_for_merkleblock(int(block_hash, 16))
77+
filter_node.wait_for_merkleblock(block_hash)
7878
assert not filter_node.tx_received
7979

8080
self.log.info('Check that we not receive a tx if the filter does not match a mempool tx')

test/functional/p2p_invalid_locator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def run_test(self):
3434
msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)]
3535
node.p2p.send_message(msg)
3636
if type(msg) == msg_getheaders:
37-
node.p2p.wait_for_header(int(node.getbestblockhash(), 16))
37+
node.p2p.wait_for_header(node.getbestblockhash())
3838
else:
3939
node.p2p.wait_for_block(int(node.getbestblockhash(), 16))
4040

test/functional/test_framework/mininode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def test_function():
393393
last_headers = self.last_message.get('headers')
394394
if not last_headers:
395395
return False
396-
return last_headers.headers[0].rehash() == blockhash
396+
return last_headers.headers[0].rehash() == int(blockhash, 16)
397397

398398
wait_until(test_function, timeout=timeout, lock=mininode_lock)
399399

@@ -403,7 +403,7 @@ def test_function():
403403
last_filtered_block = self.last_message.get('merkleblock')
404404
if not last_filtered_block:
405405
return False
406-
return last_filtered_block.merkleblock.header.rehash() == blockhash
406+
return last_filtered_block.merkleblock.header.rehash() == int(blockhash, 16)
407407

408408
wait_until(test_function, timeout=timeout, lock=mininode_lock)
409409

0 commit comments

Comments
 (0)