test: set P2PConnection.p2p_connected_to_node in peer_connect_helper()

Set `P2PConnection.p2p_connected_to_node` in
`P2PConnection.peer_connect_helper()` instead of
`TestNode.add_p2p_connection()` and
`TestNode.add_outbound_p2p_connection()`.

This way tests can create an instance of `P2PConnection` and use
`P2PConnection.peer_connect_helper()` directly.
pull/29420/head
Vasil Dimov 9 months ago
parent 22cd0e888c
commit 57529ac4db
No known key found for this signature in database
GPG Key ID: 54DF06F64B55CBBF

@ -188,6 +188,7 @@ class P2PConnection(asyncio.Protocol):
self.on_connection_send_msg = None self.on_connection_send_msg = None
self.recvbuf = b"" self.recvbuf = b""
self.magic_bytes = MAGIC_BYTES[net] self.magic_bytes = MAGIC_BYTES[net]
self.p2p_connected_to_node = dstport != 0
def peer_connect(self, dstaddr, dstport, *, net, timeout_factor, supports_v2_p2p): def peer_connect(self, dstaddr, dstport, *, net, timeout_factor, supports_v2_p2p):
self.peer_connect_helper(dstaddr, dstport, net, timeout_factor) self.peer_connect_helper(dstaddr, dstport, net, timeout_factor)

@ -714,7 +714,6 @@ class TestNode():
if supports_v2_p2p is None: if supports_v2_p2p is None:
supports_v2_p2p = self.use_v2transport supports_v2_p2p = self.use_v2transport
p2p_conn.p2p_connected_to_node = True
if self.use_v2transport: if self.use_v2transport:
kwargs['services'] = kwargs.get('services', P2P_SERVICES) | NODE_P2P_V2 kwargs['services'] = kwargs.get('services', P2P_SERVICES) | NODE_P2P_V2
supports_v2_p2p = self.use_v2transport and supports_v2_p2p supports_v2_p2p = self.use_v2transport and supports_v2_p2p
@ -781,7 +780,6 @@ class TestNode():
self.log.debug("Connecting to %s:%d %s" % (address, port, connection_type)) self.log.debug("Connecting to %s:%d %s" % (address, port, connection_type))
self.addconnection('%s:%d' % (address, port), connection_type, advertise_v2_p2p) self.addconnection('%s:%d' % (address, port), connection_type, advertise_v2_p2p)
p2p_conn.p2p_connected_to_node = False
if supports_v2_p2p is None: if supports_v2_p2p is None:
supports_v2_p2p = self.use_v2transport supports_v2_p2p = self.use_v2transport
if advertise_v2_p2p is None: if advertise_v2_p2p is None:

Loading…
Cancel
Save