Skip to content

test(router): add unit tests and relay routing integration test - #80

Open
Sendi0011 wants to merge 1 commit into
StellarConduit:mainfrom
Sendi0011:test/router-relay-integration-tests
Open

test(router): add unit tests and relay routing integration test#80
Sendi0011 wants to merge 1 commit into
StellarConduit:mainfrom
Sendi0011:test/router-relay-integration-tests

Conversation

@Sendi0011

@Sendi0011 Sendi0011 commented Mar 10, 2026

Copy link
Copy Markdown

Title: test(router): add unit tests and relay routing integration test

Closes: #47

Summary

Adds external test coverage for PathFinder and RelayRouter, and an end-to-end relay routing integration test as specified in Issue #47. Also exposes the router module publicly in src/lib.rs, which was the only missing wiring preventing external tests from compiling.

Changes

src/lib.rs — added pub mod router;

tests/router_test.rs — 9 unit tests:

  • test_pathfinder_ranks_relay_adjacent_peer_first — 1-hop peer sorts before 5-hop peer regardless of input order
  • test_pathfinder_handles_empty_connections — empty input returns empty, no panic
  • test_pathfinder_unknown_peers_ranked_last — peers with no HopCounter entry sort to the end
  • test_pathfinder_follows_graph_edges_to_relay — PathFinder traverses MeshGraph edges to find relay proximity
  • test_relay_router_respects_target_fanout — 10 peers, fanout=3 → exactly 3 returned
  • test_relay_router_falls_back_to_random_when_no_relay_path — all peers at 255 hops → still returns target_fanout peers
  • test_relay_router_returns_all_when_fanout_exceeds_peer_count
  • test_relay_router_empty_input_returns_empty
  • test_relay_router_zero_fanout_returns_empty

tests/integration/relay_routing_test.rs — 3 integration tests:

  • test_message_routes_to_relay_node — 4-node chain (Node0–Node1–Node2–Node3/Relay), message injected at Node0 reaches the relay ✓
  • test_message_injected_at_relay_is_received
  • test_isolated_node_message_stays_at_origin

Note on MeshSimulator (#20): Since Issue #20 is not yet merged, a minimal MeshBuilder harness is implemented inline in the integration test using the same PathFinder + RelayRouter + MeshGraph + HopCounter stack. When #20 lands, the harness can be swapped for the canonical MeshSimulator with no changes to the test assertions.

Test results

router_test:        9 passed, 0 failed
relay_routing_test: 3 passed, 0 failed

## Proof

<img width="1136" height="880" alt="Screenshot 2026-03-10 at 06 18 50" src="https://github.com/user-attachments/assets/daedca04-34dc-4464-b0bf-9595b16aa8c3" />

<img width="1136" height="880" alt="Screenshot 2026-03-10 at 06 19 01" src="https://github.com/user-attachments/assets/a26d26c7-adf6-44b4-839c-15b94f062386" />

Closes #47 

@Sendi0011

Copy link
Copy Markdown
Author

GM @Mrwicks00 this trust you are doing great? this pr is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant