Skip to content

Commit 7ea6499

Browse files
committed
Merge #20028: test: Check that invalid peer traffic is accounted for
faa94cb test: Check that invalid peer traffic is accounted for (MarcoFalke) fae243f test: Remove confusing cast to same type (int to int) (MarcoFalke) Pull request description: Couldn't find a test for this and it seems something we should test, so I wrote one. ACKs for top commit: vasild: ACK faa94cb practicalswift: ACK faa94cb: patch looks correct Tree-SHA512: efcdd35960045cdfbd14480e16e0d1d09e81eb01670ac541ac2b105e1a63818a157c95853270242234a224880873e79957832bf4231374d7fe81de30f35e3abf
2 parents 5db44c7 + faa94cb commit 7ea6499

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
P2PInterface,
2323
)
2424
from test_framework.test_framework import BitcoinTestFramework
25-
from test_framework.util import (
26-
assert_equal,
27-
)
25+
from test_framework.util import assert_equal
2826

2927
VALID_DATA_LIMIT = MAX_PROTOCOL_MESSAGE_LENGTH - 5 # Account for the 5-byte length prefix
3028

29+
3130
class msg_unrecognized:
3231
"""Nonsensical message. Modeled after similar types in test_framework.messages."""
3332

@@ -64,13 +63,13 @@ def test_buffer(self):
6463
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
6564
# Create valid message
6665
msg = conn.build_message(msg_ping(nonce=12345))
67-
cut_pos = 12 # Chosen at an arbitrary position within the header
66+
cut_pos = 12 # Chosen at an arbitrary position within the header
6867
# Send message in two pieces
69-
before = int(self.nodes[0].getnettotals()['totalbytesrecv'])
68+
before = self.nodes[0].getnettotals()['totalbytesrecv']
7069
conn.send_raw_message(msg[:cut_pos])
7170
# Wait until node has processed the first half of the message
72-
self.wait_until(lambda: int(self.nodes[0].getnettotals()['totalbytesrecv']) != before)
73-
middle = int(self.nodes[0].getnettotals()['totalbytesrecv'])
71+
self.wait_until(lambda: self.nodes[0].getnettotals()['totalbytesrecv'] != before)
72+
middle = self.nodes[0].getnettotals()['totalbytesrecv']
7473
# If this assert fails, we've hit an unlikely race
7574
# where the test framework sent a message in between the two halves
7675
assert_equal(middle, before + cut_pos)
@@ -100,6 +99,8 @@ def test_checksum(self):
10099
msg = msg[:cut_len] + b'\xff' * 4 + msg[cut_len + 4:]
101100
conn.send_raw_message(msg)
102101
conn.sync_with_ping(timeout=1)
102+
# Check that traffic is accounted for (24 bytes header + 2 bytes payload)
103+
assert_equal(self.nodes[0].getpeerinfo()[0]['bytesrecv_per_msg']['*other*'], 26)
103104
self.nodes[0].disconnect_p2ps()
104105

105106
def test_size(self):
@@ -123,6 +124,8 @@ def test_msgtype(self):
123124
msg = msg[:7] + b'\x00' + msg[7 + 1:]
124125
conn.send_raw_message(msg)
125126
conn.sync_with_ping(timeout=1)
127+
# Check that traffic is accounted for (24 bytes header + 2 bytes payload)
128+
assert_equal(self.nodes[0].getpeerinfo()[0]['bytesrecv_per_msg']['*other*'], 26)
126129
self.nodes[0].disconnect_p2ps()
127130

128131
def test_oversized_msg(self, msg, size):

0 commit comments

Comments
 (0)