mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 05:57:59 +01:00
Merge bitcoin/bitcoin#29736: test: Extends wait_for_getheaders so a specific block hash can be checked
c4f857cc30test: Extends wait_for_getheaders so a specific block hash can be checked (Sergi Delgado Segura) Pull request description: Fixes https://github.com/bitcoin/bitcoin/issues/18614 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. ACKs for top commit: achow101: ACKc4f857cc30BrandonOdiwuor: crACKc4f857cc30cbergqvist: ACKc4f857cc30stratospher: tested ACKc4f857c. went through all getheaders messages sent in the tests and checked that it's the one we want. Tree-SHA512: afc9a31673344dfaaefcf692ec2ab65958c3d4c005f5f3af525e9960f0622d8246d5311e59aba06cfd5c9e0ef9eb90a7fc8e210f030bfbe67b897c061efdeed1
This commit is contained in:
@@ -644,15 +644,17 @@ class P2PInterface(P2PConnection):
|
||||
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
def wait_for_getheaders(self, *, timeout=60):
|
||||
"""Waits for a getheaders message.
|
||||
def wait_for_getheaders(self, block_hash=None, *, timeout=60):
|
||||
"""Waits for a getheaders message containing a specific block hash.
|
||||
|
||||
Receiving any getheaders message will satisfy the predicate. the last_message["getheaders"]
|
||||
value must be explicitly cleared before calling this method, or this will return
|
||||
immediately with success. TODO: change this method to take a hash value and only
|
||||
return true if the correct block header has been requested."""
|
||||
If no block hash is provided, checks whether any getheaders message has been received by the node."""
|
||||
def test_function():
|
||||
return self.last_message.get("getheaders")
|
||||
last_getheaders = self.last_message.pop("getheaders", None)
|
||||
if block_hash is None:
|
||||
return last_getheaders
|
||||
if last_getheaders is None:
|
||||
return False
|
||||
return block_hash == last_getheaders.locator.vHave[0]
|
||||
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user