diff options
author | Ava Chow <github@achow101.com> | 2024-04-25 13:19:12 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-04-25 13:26:21 -0400 |
commit | 3c88eac28e8984893746caebb313dc3b2fca90db (patch) | |
tree | e6c7e223bdd2da8adbe0b5b8047d9d5cd34d9631 /test/functional/test_framework | |
parent | 16a617461338876a03665cec7f39964602d298bb (diff) | |
parent | c4f857cc301d856f3c60acbe6271d3fe19441c7a (diff) | |
download | bitcoin-3c88eac28e8984893746caebb313dc3b2fca90db.tar.xz |
Merge bitcoin/bitcoin#29736: test: Extends wait_for_getheaders so a specific block hash can be checked
c4f857cc301d856f3c60acbe6271d3fe19441c7a test: 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:
ACK c4f857cc301d856f3c60acbe6271d3fe19441c7a
BrandonOdiwuor:
crACK c4f857cc301d856f3c60acbe6271d3fe19441c7a
cbergqvist:
ACK c4f857cc301d856f3c60acbe6271d3fe19441c7a
stratospher:
tested ACK c4f857c. went through all getheaders messages sent in the tests and checked that it's the one we want.
Tree-SHA512: afc9a31673344dfaaefcf692ec2ab65958c3d4c005f5f3af525e9960f0622d8246d5311e59aba06cfd5c9e0ef9eb90a7fc8e210f030bfbe67b897c061efdeed1
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-x | test/functional/test_framework/p2p.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index ce76008c46..00bd1e4017 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -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) |