@@ -109,6 +109,9 @@ def test_duplicate_version_msg(self):
109
109
self .nodes [0 ].disconnect_p2ps ()
110
110
111
111
def test_magic_bytes (self ):
112
+ # Skip with v2, magic bytes are v1-specific
113
+ if self .options .v2transport :
114
+ return
112
115
self .log .info ("Test message with invalid magic bytes disconnects peer" )
113
116
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
114
117
with self .nodes [0 ].assert_debug_log (['Header error: Wrong MessageStart ffffffff received' ]):
@@ -120,6 +123,9 @@ def test_magic_bytes(self):
120
123
self .nodes [0 ].disconnect_p2ps ()
121
124
122
125
def test_checksum (self ):
126
+ # Skip with v2, the checksum is v1-specific
127
+ if self .options .v2transport :
128
+ return
123
129
self .log .info ("Test message with invalid checksum logs an error" )
124
130
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
125
131
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):
137
143
def test_size (self ):
138
144
self .log .info ("Test message with oversized payload disconnects peer" )
139
145
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 ):
141
151
msg = msg_unrecognized (str_data = "d" * (VALID_DATA_LIMIT + 1 ))
142
152
msg = conn .build_message (msg )
143
153
conn .send_raw_message (msg )
@@ -147,15 +157,26 @@ def test_size(self):
147
157
def test_msgtype (self ):
148
158
self .log .info ("Test message with invalid message type logs an error" )
149
159
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
151
162
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 )
159
180
self .nodes [0 ].disconnect_p2ps ()
160
181
161
182
def test_addrv2 (self , label , required_log_messages , raw_addrv2 ):
0 commit comments