mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-22 10:02:34 +02:00
test: Check that non empty version packet is ignored and no disconnection happens
This test type is represented using SEND_NON_EMPTY_VERSION_PACKET.
This commit is contained in:
parent
997cc00b95
commit
c9dacd958d
@ -25,12 +25,14 @@ class TestType(Enum):
|
|||||||
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
|
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
|
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
|
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
|
EARLY_KEY_RESPONSE = 0
|
||||||
EXCESS_GARBAGE = 1
|
EXCESS_GARBAGE = 1
|
||||||
WRONG_GARBAGE_TERMINATOR = 2
|
WRONG_GARBAGE_TERMINATOR = 2
|
||||||
WRONG_GARBAGE = 3
|
WRONG_GARBAGE = 3
|
||||||
SEND_NO_AAD = 4
|
SEND_NO_AAD = 4
|
||||||
|
SEND_NON_EMPTY_VERSION_PACKET = 5
|
||||||
|
|
||||||
|
|
||||||
class EarlyKeyResponseState(EncryptedP2PState):
|
class EarlyKeyResponseState(EncryptedP2PState):
|
||||||
@ -85,6 +87,13 @@ class NoAADState(EncryptedP2PState):
|
|||||||
return super().complete_handshake(response)
|
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):
|
class MisbehavingV2Peer(P2PInterface):
|
||||||
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
|
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
|
||||||
def __init__(self, test_type):
|
def __init__(self, test_type):
|
||||||
@ -102,6 +111,8 @@ class MisbehavingV2Peer(P2PInterface):
|
|||||||
self.v2_state = WrongGarbageState(initiating=True, net='regtest')
|
self.v2_state = WrongGarbageState(initiating=True, net='regtest')
|
||||||
elif self.test_type == TestType.SEND_NO_AAD:
|
elif self.test_type == TestType.SEND_NO_AAD:
|
||||||
self.v2_state = NoAADState(initiating=True, net='regtest')
|
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)
|
super().connection_made(transport)
|
||||||
|
|
||||||
def data_received(self, t):
|
def data_received(self, t):
|
||||||
@ -146,10 +157,15 @@ class EncryptedP2PMisbehaving(BitcoinTestFramework):
|
|||||||
["V2 handshake timeout peer=2"], # WRONG_GARBAGE_TERMINATOR
|
["V2 handshake timeout peer=2"], # WRONG_GARBAGE_TERMINATOR
|
||||||
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
|
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
|
||||||
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
|
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
|
||||||
|
[], # SEND_NON_EMPTY_VERSION_PACKET
|
||||||
]
|
]
|
||||||
for test_type in TestType:
|
for test_type in TestType:
|
||||||
if test_type == TestType.EARLY_KEY_RESPONSE:
|
if test_type == TestType.EARLY_KEY_RESPONSE:
|
||||||
continue
|
continue
|
||||||
|
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):
|
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 = 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()
|
peer.wait_for_disconnect()
|
||||||
|
Loading…
Reference in New Issue
Block a user