Skip to content

Commit 9f5608c

Browse files
committed
test: check for matching object hashes in wait_for_getdata
1 parent a7a6f1f commit 9f5608c

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

test/functional/p2p_fingerprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run_test(self):
9090

9191
# Force reorg to a longer chain
9292
node0.send_message(msg_headers(new_blocks))
93-
node0.wait_for_getdata()
93+
node0.wait_for_getdata([x.sha256 for x in new_blocks])
9494
for block in new_blocks:
9595
node0.send_and_ping(msg_block(block))
9696

test/functional/p2p_segwit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def announce_tx_and_wait_for_getdata(self, tx, timeout=60, success=True):
159159
self.last_message.pop("getdata", None)
160160
self.send_message(msg_inv(inv=[CInv(1, tx.sha256)]))
161161
if success:
162-
self.wait_for_getdata(timeout)
162+
self.wait_for_getdata([tx.sha256], timeout)
163163
else:
164164
time.sleep(timeout)
165165
assert not self.last_message.get("getdata")
@@ -176,7 +176,7 @@ def announce_block_and_wait_for_getdata(self, block, use_header, timeout=60):
176176
self.send_message(msg_inv(inv=[CInv(2, block.sha256)]))
177177
self.wait_for_getheaders()
178178
self.send_message(msg)
179-
self.wait_for_getdata()
179+
self.wait_for_getdata([block.sha256])
180180

181181
def request_block(self, blockhash, inv_type, timeout=60):
182182
with mininode_lock:

test/functional/p2p_sendheaders.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,6 @@ def send_getblocks(self, locator):
144144
getblocks_message.locator.vHave = locator
145145
self.send_message(getblocks_message)
146146

147-
def wait_for_getdata(self, hash_list, timeout=60):
148-
if hash_list == []:
149-
return
150-
151-
test_function = lambda: "getdata" in self.last_message and [x.hash for x in self.last_message["getdata"].inv] == hash_list
152-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
153-
154147
def wait_for_block_announcement(self, block_hash, timeout=60):
155148
test_function = lambda: self.last_blockhash_announced == block_hash
156149
wait_until(test_function, timeout=timeout, lock=mininode_lock)

test/functional/test_framework/mininode.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,17 +406,17 @@ def test_function():
406406

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

409-
def wait_for_getdata(self, timeout=60):
409+
def wait_for_getdata(self, hash_list, timeout=60):
410410
"""Waits for a getdata message.
411411
412-
Receiving any getdata message will satisfy the predicate. the last_message["getdata"]
413-
value must be explicitly cleared before calling this method, or this will return
414-
immediately with success. TODO: change this method to take a hash value and only
415-
return true if the correct block/tx has been requested."""
412+
The object hashes in the inventory vector must match the provided hash_list."""
416413

417414
def test_function():
418415
assert self.is_connected
419-
return self.last_message.get("getdata")
416+
last_data = self.last_message.get("getdata")
417+
if not last_data:
418+
return False
419+
return [x.hash for x in last_data.inv] == hash_list
420420

421421
wait_until(test_function, timeout=timeout, lock=mininode_lock)
422422

0 commit comments

Comments
 (0)