Skip to content

Commit

Permalink
refactor: test: use wait_for_getdata() in p2p_compactblocks.py
Browse files Browse the repository at this point in the history
  • Loading branch information
theStack committed Apr 24, 2020
1 parent d8ca51d commit c4027e7
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions test/functional/p2p_compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,15 @@ def test_compactblock_requests(self, test_node, segwit=True):
# request
for announce in ["inv", "header"]:
block = self.build_block_on_tip(node, segwit=segwit)
with mininode_lock:
test_node.last_message.pop("getdata", None)

if announce == "inv":
test_node.send_message(msg_inv([CInv(2, block.sha256)]))
wait_until(lambda: "getheaders" in test_node.last_message, timeout=30, lock=mininode_lock)
test_node.send_header_for_blocks([block])
else:
test_node.send_header_for_blocks([block])
wait_until(lambda: "getdata" in test_node.last_message, timeout=30, lock=mininode_lock)
assert_equal(len(test_node.last_message["getdata"].inv), 1)
test_node.wait_for_getdata([block.sha256], timeout=30)
assert_equal(test_node.last_message["getdata"].inv[0].type, 4)
assert_equal(test_node.last_message["getdata"].inv[0].hash, block.sha256)

# Send back a compactblock message that omits the coinbase
comp_block = HeaderAndShortIDs()
Expand Down Expand Up @@ -567,10 +563,8 @@ def test_incorrect_blocktxn_response(self, test_node):
assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock)

# We should receive a getdata request
wait_until(lambda: "getdata" in test_node.last_message, timeout=10, lock=mininode_lock)
assert_equal(len(test_node.last_message["getdata"].inv), 1)
test_node.wait_for_getdata([block.sha256], timeout=10)
assert test_node.last_message["getdata"].inv[0].type == 2 or test_node.last_message["getdata"].inv[0].type == 2 | MSG_WITNESS_FLAG
assert_equal(test_node.last_message["getdata"].inv[0].hash, block.sha256)

# Deliver the block
if version == 2:
Expand Down

0 comments on commit c4027e7

Please sign in to comment.