test: Combine sync_send_with_ping and sync_with_ping

This commit is contained in:
MarcoFalke 2023-09-05 12:11:54 +02:00
parent 260445bee8
commit fae0b21e6c
No known key found for this signature in database
8 changed files with 12 additions and 16 deletions

View File

@ -133,7 +133,7 @@ class AddrTest(BitcoinTestFramework):
self.mocktime += 10 * 60
self.nodes[0].setmocktime(self.mocktime)
for peer in receivers:
peer.sync_send_with_ping()
peer.sync_with_ping()
def oversized_addr_test(self):
self.log.info('Send an addr message that is too large')

View File

@ -48,7 +48,7 @@ class P2PAddrFetch(BitcoinTestFramework):
self.assert_getpeerinfo(peer_ids=[peer_id])
self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer")
peer.sync_send_with_ping()
peer.sync_with_ping()
with p2p_lock:
assert peer.message_count['getaddr'] == 1
assert peer.message_count['getheaders'] == 0

View File

@ -101,7 +101,7 @@ class P2PBlocksOnly(BitcoinTestFramework):
# Bump time forward to ensure m_next_inv_send_time timer pops
self.nodes[0].setmocktime(int(time.time()) + 60)
conn.sync_send_with_ping()
conn.sync_with_ping()
assert int(txid, 16) not in conn.get_invs()
def check_p2p_inv_violation(self, peer):

View File

@ -94,11 +94,11 @@ class P2PCompactBlocksBlocksOnly(BitcoinTestFramework):
block1 = self.build_block_on_tip()
p2p_conn_blocksonly.send_message(msg_headers(headers=[CBlockHeader(block1)]))
p2p_conn_blocksonly.sync_send_with_ping()
p2p_conn_blocksonly.sync_with_ping()
assert_equal(p2p_conn_blocksonly.last_message['getdata'].inv, [CInv(MSG_BLOCK | MSG_WITNESS_FLAG, block1.sha256)])
p2p_conn_high_bw.send_message(msg_headers(headers=[CBlockHeader(block1)]))
p2p_conn_high_bw.sync_send_with_ping()
p2p_conn_high_bw.sync_with_ping()
assert_equal(p2p_conn_high_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)])
self.log.info("Test that getdata(CMPCT) is still sent on BIP152 low bandwidth connections"

View File

@ -177,7 +177,7 @@ class FilterTest(BitcoinTestFramework):
filter_peer.merkleblock_received = False
filter_peer.tx_received = False
self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)
filter_peer.sync_send_with_ping()
filter_peer.sync_with_ping()
assert not filter_peer.merkleblock_received
assert not filter_peer.tx_received

View File

@ -151,7 +151,7 @@ class P2PIBDStallingTest(BitcoinTestFramework):
def all_sync_send_with_ping(self, peers):
for p in peers:
if p.is_connected:
p.sync_send_with_ping()
p.sync_with_ping()
def is_block_requested(self, peers, hash):
for p in peers:

View File

@ -53,7 +53,7 @@ class P2PIBDTxRelayTest(BitcoinTestFramework):
peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=txid)]))
# The node should not send a getdata, but if it did, it would first delay 2 seconds
self.nodes[0].setmocktime(int(time.time() + NONPREF_PEER_TX_DELAY))
peer_inver.sync_send_with_ping()
peer_inver.sync_with_ping()
with p2p_lock:
assert txid not in peer_inver.getdata_requests
self.nodes[0].disconnect_p2ps()

View File

@ -558,16 +558,12 @@ class P2PInterface(P2PConnection):
self.send_message(message)
self.sync_with_ping(timeout=timeout)
def sync_send_with_ping(self, timeout=60):
"""Ensure SendMessages is called on this connection"""
# Calling sync_with_ping twice requires that the node calls
def sync_with_ping(self, timeout=60):
"""Ensure ProcessMessages and SendMessages is called on this connection"""
# Sending two pings back-to-back, requires that the node calls
# `ProcessMessage` twice, and thus ensures `SendMessages` must have
# been called at least once
self.sync_with_ping()
self.sync_with_ping()
def sync_with_ping(self, timeout=60):
"""Ensure ProcessMessages is called on this connection"""
self.send_message(msg_ping(nonce=0))
self.send_message(msg_ping(nonce=self.ping_counter))
def test_function():