@@ -109,6 +109,9 @@ def test_duplicate_version_msg(self):
109109 self .nodes [0 ].disconnect_p2ps ()
110110
111111 def test_magic_bytes (self ):
112+ # Skip with v2, magic bytes are v1-specific
113+ if self .options .v2transport :
114+ return
112115 self .log .info ("Test message with invalid magic bytes disconnects peer" )
113116 conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
114117 with self .nodes [0 ].assert_debug_log (['Header error: Wrong MessageStart ffffffff received' ]):
@@ -120,6 +123,9 @@ def test_magic_bytes(self):
120123 self .nodes [0 ].disconnect_p2ps ()
121124
122125 def test_checksum (self ):
126+ # Skip with v2, the checksum is v1-specific
127+ if self .options .v2transport :
128+ return
123129 self .log .info ("Test message with invalid checksum logs an error" )
124130 conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
125131 with self .nodes [0 ].assert_debug_log (['Header error: Wrong checksum (badmsg, 2 bytes), expected 78df0a04 was ffffffff' ]):
@@ -137,7 +143,11 @@ def test_checksum(self):
137143 def test_size (self ):
138144 self .log .info ("Test message with oversized payload disconnects peer" )
139145 conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
140- with self .nodes [0 ].assert_debug_log (['Header error: Size too large (badmsg, 4000001 bytes)' ]):
146+ error_msg = (
147+ ['V2 transport error: packet too large (4000014 bytes)' ] if self .options .v2transport
148+ else ['Header error: Size too large (badmsg, 4000001 bytes)' ]
149+ )
150+ with self .nodes [0 ].assert_debug_log (error_msg ):
141151 msg = msg_unrecognized (str_data = "d" * (VALID_DATA_LIMIT + 1 ))
142152 msg = conn .build_message (msg )
143153 conn .send_raw_message (msg )
@@ -147,15 +157,26 @@ def test_size(self):
147157 def test_msgtype (self ):
148158 self .log .info ("Test message with invalid message type logs an error" )
149159 conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
150- with self .nodes [0 ].assert_debug_log (['Header error: Invalid message type' ]):
160+ if self .options .v2transport :
161+ msgtype = 99 # not defined
151162 msg = msg_unrecognized (str_data = "d" )
152- msg = conn .build_message (msg )
153- # Modify msgtype
154- msg = msg [:7 ] + b'\x00 ' + msg [7 + 1 :]
155- conn .send_raw_message (msg )
156- conn .sync_with_ping (timeout = 1 )
157- # Check that traffic is accounted for (24 bytes header + 2 bytes payload)
158- assert_equal (self .nodes [0 ].getpeerinfo ()[0 ]['bytesrecv_per_msg' ]['*other*' ], 26 )
163+ contents = msgtype .to_bytes (1 , 'big' ) + msg .serialize ()
164+ tmsg = conn .v2_state .v2_enc_packet (contents , ignore = False )
165+ with self .nodes [0 ].assert_debug_log (['V2 transport error: invalid message type' ]):
166+ conn .send_raw_message (tmsg )
167+ conn .sync_with_ping (timeout = 1 )
168+ # Check that traffic is accounted for (20 bytes plus 3 bytes contents)
169+ assert_equal (self .nodes [0 ].getpeerinfo ()[0 ]['bytesrecv_per_msg' ]['*other*' ], 23 )
170+ else :
171+ with self .nodes [0 ].assert_debug_log (['Header error: Invalid message type' ]):
172+ msg = msg_unrecognized (str_data = "d" )
173+ msg = conn .build_message (msg )
174+ # Modify msgtype
175+ msg = msg [:7 ] + b'\x00 ' + msg [7 + 1 :]
176+ conn .send_raw_message (msg )
177+ conn .sync_with_ping (timeout = 1 )
178+ # Check that traffic is accounted for (24 bytes header + 2 bytes payload)
179+ assert_equal (self .nodes [0 ].getpeerinfo ()[0 ]['bytesrecv_per_msg' ]['*other*' ], 26 )
159180 self .nodes [0 ].disconnect_p2ps ()
160181
161182 def test_addrv2 (self , label , required_log_messages , raw_addrv2 ):
0 commit comments