aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_v2_misbehaving.py
diff options
context:
space:
mode:
authorstratospher <44024636+stratospher@users.noreply.github.com>2024-02-13 21:01:21 +0530
committerstratospher <44024636+stratospher@users.noreply.github.com>2024-06-21 19:41:00 +0530
commitc9dacd958d7c1e98b08a7083c299d981e4c11193 (patch)
tree8b30552f92a557a6f5da9cc313b7b9f3af98cc83 /test/functional/p2p_v2_misbehaving.py
parent997cc00b950a7d1b7f2a3971282685f4e81d87d2 (diff)
test: Check that non empty version packet is ignored and no disconnection happens
This test type is represented using SEND_NON_EMPTY_VERSION_PACKET.
Diffstat (limited to 'test/functional/p2p_v2_misbehaving.py')
-rwxr-xr-xtest/functional/p2p_v2_misbehaving.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/test/functional/p2p_v2_misbehaving.py b/test/functional/p2p_v2_misbehaving.py
index 51bf580b9d..e45a63b3b0 100755
--- a/test/functional/p2p_v2_misbehaving.py
+++ b/test/functional/p2p_v2_misbehaving.py
@@ -25,12 +25,14 @@ class TestType(Enum):
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
4. WRONG_GARBAGE - Disconnection happens when garbage bytes that is sent is different from what the peer receives
5. SEND_NO_AAD - Disconnection happens when AAD of first encrypted packet after the garbage terminator is not filled
+ 6. SEND_NON_EMPTY_VERSION_PACKET - non-empty version packet is simply ignored
"""
EARLY_KEY_RESPONSE = 0
EXCESS_GARBAGE = 1
WRONG_GARBAGE_TERMINATOR = 2
WRONG_GARBAGE = 3
SEND_NO_AAD = 4
+ SEND_NON_EMPTY_VERSION_PACKET = 5
class EarlyKeyResponseState(EncryptedP2PState):
@@ -85,6 +87,13 @@ class NoAADState(EncryptedP2PState):
return super().complete_handshake(response)
+class NonEmptyVersionPacketState(EncryptedP2PState):
+ """"Add option for sending non-empty transport version packet."""
+ def complete_handshake(self, response):
+ self.transport_version = random.randbytes(5)
+ return super().complete_handshake(response)
+
+
class MisbehavingV2Peer(P2PInterface):
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
def __init__(self, test_type):
@@ -102,6 +111,8 @@ class MisbehavingV2Peer(P2PInterface):
self.v2_state = WrongGarbageState(initiating=True, net='regtest')
elif self.test_type == TestType.SEND_NO_AAD:
self.v2_state = NoAADState(initiating=True, net='regtest')
+ elif TestType.SEND_NON_EMPTY_VERSION_PACKET:
+ self.v2_state = NonEmptyVersionPacketState(initiating=True, net='regtest')
super().connection_made(transport)
def data_received(self, t):
@@ -146,14 +157,19 @@ class EncryptedP2PMisbehaving(BitcoinTestFramework):
["V2 handshake timeout peer=2"], # WRONG_GARBAGE_TERMINATOR
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
+ [], # SEND_NON_EMPTY_VERSION_PACKET
]
for test_type in TestType:
if test_type == TestType.EARLY_KEY_RESPONSE:
continue
- with node0.assert_debug_log(expected_debug_message[test_type.value], timeout=5):
- peer = node0.add_p2p_connection(MisbehavingV2Peer(test_type), wait_for_verack=False, send_version=False, supports_v2_p2p=True, expect_success=False)
- peer.wait_for_disconnect()
- self.log.info(f"Expected disconnection for {test_type.name}")
+ elif test_type == TestType.SEND_NON_EMPTY_VERSION_PACKET:
+ node0.add_p2p_connection(MisbehavingV2Peer(test_type), wait_for_verack=True, send_version=True, supports_v2_p2p=True)
+ self.log.info(f"No disconnection for {test_type.name}")
+ else:
+ with node0.assert_debug_log(expected_debug_message[test_type.value], timeout=5):
+ peer = node0.add_p2p_connection(MisbehavingV2Peer(test_type), wait_for_verack=False, send_version=False, supports_v2_p2p=True, expect_success=False)
+ peer.wait_for_disconnect()
+ self.log.info(f"Expected disconnection for {test_type.name}")
if __name__ == '__main__':