test: enable p2p_invalid_messages.py with v2transport

by disabling some sub-tests that test v1-specific features,
and adapting others to v2.
pull/29358/head
Martin Zumsande 12 months ago
parent 5fc9db504b
commit 87549c8f89

@ -109,6 +109,9 @@ class InvalidMessagesTest(BitcoinTestFramework):
self.nodes[0].disconnect_p2ps()
def test_magic_bytes(self):
# Skip with v2, magic bytes are v1-specific
if self.options.v2transport:
return
self.log.info("Test message with invalid magic bytes disconnects peer")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
with self.nodes[0].assert_debug_log(['Header error: Wrong MessageStart ffffffff received']):
@ -120,6 +123,9 @@ class InvalidMessagesTest(BitcoinTestFramework):
self.nodes[0].disconnect_p2ps()
def test_checksum(self):
# Skip with v2, the checksum is v1-specific
if self.options.v2transport:
return
self.log.info("Test message with invalid checksum logs an error")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
with self.nodes[0].assert_debug_log(['Header error: Wrong checksum (badmsg, 2 bytes), expected 78df0a04 was ffffffff']):
@ -137,7 +143,11 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_size(self):
self.log.info("Test message with oversized payload disconnects peer")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
with self.nodes[0].assert_debug_log(['Header error: Size too large (badmsg, 4000001 bytes)']):
error_msg = (
['V2 transport error: packet too large (4000014 bytes)'] if self.options.v2transport
else ['Header error: Size too large (badmsg, 4000001 bytes)']
)
with self.nodes[0].assert_debug_log(error_msg):
msg = msg_unrecognized(str_data="d" * (VALID_DATA_LIMIT + 1))
msg = conn.build_message(msg)
conn.send_raw_message(msg)
@ -147,15 +157,26 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_msgtype(self):
self.log.info("Test message with invalid message type logs an error")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
with self.nodes[0].assert_debug_log(['Header error: Invalid message type']):
if self.options.v2transport:
msgtype = 99 # not defined
msg = msg_unrecognized(str_data="d")
msg = conn.build_message(msg)
# Modify msgtype
msg = msg[:7] + b'\x00' + msg[7 + 1:]
conn.send_raw_message(msg)
conn.sync_with_ping(timeout=1)
# Check that traffic is accounted for (24 bytes header + 2 bytes payload)
assert_equal(self.nodes[0].getpeerinfo()[0]['bytesrecv_per_msg']['*other*'], 26)
contents = msgtype.to_bytes(1, 'big') + msg.serialize()
tmsg = conn.v2_state.v2_enc_packet(contents, ignore=False)
with self.nodes[0].assert_debug_log(['V2 transport error: invalid message type']):
conn.send_raw_message(tmsg)
conn.sync_with_ping(timeout=1)
# Check that traffic is accounted for (20 bytes plus 3 bytes contents)
assert_equal(self.nodes[0].getpeerinfo()[0]['bytesrecv_per_msg']['*other*'], 23)
else:
with self.nodes[0].assert_debug_log(['Header error: Invalid message type']):
msg = msg_unrecognized(str_data="d")
msg = conn.build_message(msg)
# Modify msgtype
msg = msg[:7] + b'\x00' + msg[7 + 1:]
conn.send_raw_message(msg)
conn.sync_with_ping(timeout=1)
# Check that traffic is accounted for (24 bytes header + 2 bytes payload)
assert_equal(self.nodes[0].getpeerinfo()[0]['bytesrecv_per_msg']['*other*'], 26)
self.nodes[0].disconnect_p2ps()
def test_addrv2(self, label, required_log_messages, raw_addrv2):

Loading…
Cancel
Save