mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 18:20:58 +02:00
test: Extends wait_for_getheaders so a specific block hash can be checked
Previously, `wait_for_getheaders` would check whether a node had received **any** getheaders message. This implied that, if a test needed to check for a specific block hash within a headers message, it had to make sure that it was checking the desired message. This normally involved having to manually clear `last_message`. This method, apart from being too verbose, was error prone, given an undesired `getheaders` would make tests pass. This adds the ability to check for a specific block_hash within the last `getheaders` message.
This commit is contained in:
@ -191,14 +191,13 @@ class TestP2PConn(P2PInterface):
|
||||
def announce_block_and_wait_for_getdata(self, block, use_header, timeout=60):
|
||||
with p2p_lock:
|
||||
self.last_message.pop("getdata", None)
|
||||
self.last_message.pop("getheaders", None)
|
||||
msg = msg_headers()
|
||||
msg.headers = [CBlockHeader(block)]
|
||||
if use_header:
|
||||
self.send_message(msg)
|
||||
else:
|
||||
self.send_message(msg_inv(inv=[CInv(MSG_BLOCK, block.sha256)]))
|
||||
self.wait_for_getheaders(timeout=timeout)
|
||||
self.wait_for_getheaders(block_hash=block.hashPrevBlock, timeout=timeout)
|
||||
self.send_message(msg)
|
||||
self.wait_for_getdata([block.sha256], timeout=timeout)
|
||||
|
||||
|
Reference in New Issue
Block a user