You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Purpose
This test suite ensures that:
senderRecord(Signed Peer Record).relay/circuit_v2/protocol.pyare covered by tests (as noted in Pacrob’s review).Test Categories
1. HOP Message with Valid SPR
Goal: Verify that a
HOPmessage containing a validsenderRecordis:PeerId.Test Steps:
Create mock peers:
src_peer,relay_peer,dst_peer.Generate a valid
SignedPeerRecordforsrc_peer.Send a simulated
HOPmessage fromsrc_peer→relay_peer, including thesenderRecord.Ensure:
senderRecordfield (HasField("senderRecord") == True).src_peer.get_id().Assertions:
stop_msg.senderRecord.peer_id == src_peer.idrelay.accepted_hop == True2. HOP Message with Invalid SPR
Goal: Verify rejection when the
senderRecordis tampered or invalid.Test Steps:
Same setup as above, but modify the signature or peer id in the SPR.
Send HOP message with corrupted
senderRecord.Verify that:
InvalidPeerRecordorVerificationFailed) is raised or logged.Assertions:
relay.accepted_hop == Falserelay.error_logcontains “peer record verification failed”3. STOP Message Parsing and Validation
Goal: Cover the untested code path Pacrob pointed out:
Test Steps:
Send a simulated
STOPmessage containing a validsenderRecord.Ensure:
stop_msg.HasField("senderRecord")evaluates to True.Assertions:
stop_msg.senderRecord.peer_id == expected_peer_idstop_handler.was_called == True4. Missing SPR Field
Goal: Test fallback behavior when no
senderRecordfield exists.Test Steps:
Send a STOP or HOP message without a
senderRecord.Verify that:
Assertions:
stop_msg.HasField("senderRecord") == Falserelay.logged_warning == "Missing senderRecord"5.
get_remote_peer_idValidationGoal: Validate logic around:
and
Test Steps:
Mock an
INetStreamWithExtrasinstance to simulate both source and destination peers.Ensure that:
get_remote_peer_id()returns consistent and correct PeerIds.Add assertions that the retrieved PeerIds are compared properly to envelope IDs.
Assertions:
src_peer_id == stop_msg.senderRecord.peer_idrelay.error_logcontains “peer id mismatch in envelope”6. End-to-End Relay Flow with Verified SPRs
Goal: Full integration test for a complete HOP–STOP exchange through relay.
Test Steps:
Initialize
src_peer,relay_peer, anddst_peerusing mock host/network.src_peersends aHOPrequest with a valid SPR.relay_peerprocesses and forwards the connection setup.dst_peerresponds with aSTOPmessage containing its SPR.Verify:
Assertions:
relay.connection_established == Truepeerstoreentries updated with each other’s verified records.7. Edge Case — Expired or Replay SPR
Goal: Test temporal validity or replay attack resistance if timestamp or sequence number is present in SPR.
Test Steps:
Assertions:
relay.reject_reason == "stale peer record"Mocks / Helpers Needed
MockStreamsubclass implementingINetStreamWithExtras.get_remote_peer_id().FakePeerstoreto simulate peer records and lookups.generate_signed_peer_record(peer_id, private_key)utility for test data.FakeRelayHostthat logs calls likeaccepted_hop,error_log, andconnection_established.Coverage Goals
Ensure tests hit every new code branch involving:
stop_msg.HasField("senderRecord")get_remote_peer_id()callsAim for >90% coverage for the updated
relay/circuit_v2/protocol.pyfile.Beta Was this translation helpful? Give feedback.
All reactions