Skip to content

Commit 75447f0

Browse files
committed
test: improve msg sends and p2p disconnections in p2p_invalid_messages
- call disconnect_p2ps() outside of the assert_debug_log scopes - send messages directly from the p2p conn rather than via nodes[0].p2p - add an assertion
1 parent 5796019 commit 75447f0

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_magic_bytes(self):
8686
msg = b'\xff' * 4 + msg[4:]
8787
conn.send_raw_message(msg)
8888
conn.wait_for_disconnect(timeout=1)
89-
self.nodes[0].disconnect_p2ps()
89+
self.nodes[0].disconnect_p2ps()
9090

9191
def test_checksum(self):
9292
self.log.info("Test message with invalid checksum logs an error")
@@ -97,19 +97,19 @@ def test_checksum(self):
9797
cut_len = 4 + 12 + 4
9898
# modify checksum
9999
msg = msg[:cut_len] + b'\xff' * 4 + msg[cut_len + 4:]
100-
self.nodes[0].p2p.send_raw_message(msg)
100+
conn.send_raw_message(msg)
101101
conn.sync_with_ping(timeout=1)
102-
self.nodes[0].disconnect_p2ps()
102+
self.nodes[0].disconnect_p2ps()
103103

104104
def test_size(self):
105105
self.log.info("Test message with oversized payload disconnects peer")
106106
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
107107
with self.nodes[0].assert_debug_log(['']):
108108
msg = msg_unrecognized(str_data="d" * (VALID_DATA_LIMIT + 1))
109109
msg = conn.build_message(msg)
110-
self.nodes[0].p2p.send_raw_message(msg)
110+
conn.send_raw_message(msg)
111111
conn.wait_for_disconnect(timeout=1)
112-
self.nodes[0].disconnect_p2ps()
112+
self.nodes[0].disconnect_p2ps()
113113

114114
def test_msgtype(self):
115115
self.log.info("Test message with invalid message type logs an error")
@@ -120,9 +120,9 @@ def test_msgtype(self):
120120
msg = conn.build_message(msg)
121121
# Modify msgtype
122122
msg = msg[:7] + b'\x00' + msg[7 + 1:]
123-
self.nodes[0].p2p.send_raw_message(msg)
123+
conn.send_raw_message(msg)
124124
conn.sync_with_ping(timeout=1)
125-
self.nodes[0].disconnect_p2ps()
125+
self.nodes[0].disconnect_p2ps()
126126

127127
def test_oversized_msg(self, msg, size):
128128
msg_type = msg.msgtype.decode('ascii')
@@ -160,8 +160,9 @@ def test_resource_exhaustion(self):
160160
self.log.info("(c) Wait for node to drop junk messages, while remaining connected")
161161
conn.sync_with_ping(timeout=400)
162162

163-
# Peer 1, despite being served up a bunch of nonsense, should still be connected.
163+
# Despite being served up a bunch of nonsense, the peers should still be connected.
164164
assert conn.is_connected
165+
assert conn2.is_connected
165166
self.nodes[0].disconnect_p2ps()
166167

167168

0 commit comments

Comments
 (0)