mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Merge bitcoin/bitcoin#22568: test: add addr-fetch peer connection state and timeout coverage
f8d8eb5fdaa93b6e5b77fd901b94927dc3a0473e test: add addr-fetch timeout connection coverage in p2p_addrfetch.py (Jon Atack)
9321086af7b75be536767d25abef4d7e02ca416a test: add assert_getpeerinfo method and coverage in p2p_addrfetch.py (Jon Atack)
Pull request description:
This patch adds additional addr-fetch peer connection state and timeout coverage as a follow-up to #22096.
ACKs for top commit:
Saviour1001:
Tested ACK <code>[f8d8eb5](f8d8eb5fda
)</code>
mzumsande:
Code review ACK f8d8eb5fdaa93b6e5b77fd901b94927dc3a0473e
Tree-SHA512: 9a13a705d1da6b308d6dcbc6930575205e2e88bfe9f2e7cb4e0c4c40d26538430e6b02c6c772d0cee64e534777348291469a139f99afbf9d4f93f31b9e7b0818
Signed-off-by: Vijay <vijaydas.mp@gmail.com>
This commit is contained in:
parent
8d3f31306e
commit
97fd2b2842
@ -21,18 +21,24 @@ ADDR.port = 18444
|
||||
|
||||
|
||||
class P2PAddrFetch(BitcoinTestFramework):
|
||||
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
def assert_getpeerinfo(self, *, peer_ids):
|
||||
num_peers = len(peer_ids)
|
||||
info = self.nodes[0].getpeerinfo()
|
||||
assert_equal(len(info), num_peers)
|
||||
for n in range(0, num_peers):
|
||||
assert_equal(info[n]['id'], peer_ids[n])
|
||||
assert_equal(info[n]['connection_type'], 'addr-fetch')
|
||||
|
||||
def run_test(self):
|
||||
node = self.nodes[0]
|
||||
self.log.info("Connect to an addr-fetch peer")
|
||||
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, connection_type="addr-fetch")
|
||||
info = node.getpeerinfo()
|
||||
assert_equal(len(info), 1)
|
||||
assert_equal(info[0]['connection_type'], 'addr-fetch')
|
||||
peer_id = 0
|
||||
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=peer_id, connection_type="addr-fetch")
|
||||
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()
|
||||
@ -45,7 +51,7 @@ class P2PAddrFetch(BitcoinTestFramework):
|
||||
msg = msg_addr()
|
||||
msg.addrs = [ADDR]
|
||||
peer.send_and_ping(msg)
|
||||
assert_equal(len(node.getpeerinfo()), 1)
|
||||
self.assert_getpeerinfo(peer_ids=[peer_id])
|
||||
|
||||
self.log.info("Check that answering with larger addr messages leads to disconnect")
|
||||
msg.addrs = [ADDR] * 2
|
||||
@ -53,9 +59,20 @@ class P2PAddrFetch(BitcoinTestFramework):
|
||||
peer.wait_for_disconnect(timeout=5)
|
||||
|
||||
self.log.info("Check timeout for addr-fetch peer that does not send addrs")
|
||||
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, connection_type="addr-fetch")
|
||||
node.setmocktime(int(time.time()) + 301) # Timeout: 5 minutes
|
||||
peer_id = 1
|
||||
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=peer_id, connection_type="addr-fetch")
|
||||
|
||||
time_now = int(time.time())
|
||||
self.assert_getpeerinfo(peer_ids=[peer_id])
|
||||
|
||||
# Expect addr-fetch peer connection to be maintained up to 5 minutes.
|
||||
node.setmocktime(time_now + 295)
|
||||
self.assert_getpeerinfo(peer_ids=[peer_id])
|
||||
|
||||
# Expect addr-fetch peer connection to be disconnected after 5 minutes.
|
||||
node.setmocktime(time_now + 301)
|
||||
peer.wait_for_disconnect(timeout=5)
|
||||
self.assert_getpeerinfo(peer_ids=[])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user