|
| 1 | +# Freenet Ping App Test Suite |
| 2 | + |
| 3 | +This directory contains integration tests for the Freenet Ping application, focusing on contract state propagation in various network topologies and connectivity scenarios. |
| 4 | + |
| 5 | +## Test Organization |
| 6 | + |
| 7 | +| Test File | Scenario | |
| 8 | +| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | |
| 9 | +| `run_app.rs` | **Multi-node and client functionality tests.** Contains tests for basic multi-node functionality and client application. | |
| 10 | +| `run_app_blocked_peers.rs` | **Parameterized blocked peers tests.** A unified implementation of blocked peers tests with different functional behaviors. | |
| 11 | +| `run_app_partially_connected_network.rs` | **Partial connectivity test.** Large-scale network test with controlled connectivity between nodes. | |
| 12 | + |
| 13 | +## Parameterized "Blocked Peers" Tests |
| 14 | + |
| 15 | +The `run_app_blocked_peers.rs` file contains a parameterized implementation that consolidates blocked peers testing into a single file. The file provides the following test variants: |
| 16 | + |
| 17 | +| Test Function | Description | |
| 18 | +| ---------------------------------- | -------------------------------------------------------------------------------- | |
| 19 | +| `test_ping_blocked_peers` | **Baseline implementation.** Standard test for indirect propagation via gateway. | |
| 20 | +| `test_ping_blocked_peers_simple` | **Minimal variant.** One round of updates, simplified verification. | |
| 21 | +| `test_ping_blocked_peers_solution` | **Reference implementation.** Best practices for indirect propagation. | |
| 22 | + |
| 23 | +## Test Structure |
| 24 | + |
| 25 | +### In `run_app.rs` |
| 26 | + |
| 27 | +| Test Function | Description | |
| 28 | +| ---------------------------- | -------------------------------------------------------------- | |
| 29 | +| `test_ping_multi_node` | Tests basic contract propagation in a fully-connected network. | |
| 30 | +| `test_ping_application_loop` | Tests the complete client application running over time. | |
| 31 | + |
| 32 | +### In `run_app_partially_connected_network.rs` |
| 33 | + |
| 34 | +| Test Function | Description | |
| 35 | +| --------------------------------------- | ---------------------------------------------------------------- | |
| 36 | +| `test_ping_partially_connected_network` | Tests propagation in a larger network with partial connectivity. | |
| 37 | + |
| 38 | +### Multi-node vs. Partially Connected Tests |
| 39 | + |
| 40 | +- **Multi-node test**: Uses a fully connected network where all nodes can directly communicate with each other |
| 41 | +- **Partially connected test**: Creates a larger network with controlled connectivity ratio (50%) between nodes, testing how updates propagate in a more realistic, constrained network topology |
| 42 | + |
| 43 | +## The "Blocked Peers" Test Scenario |
| 44 | + |
| 45 | +The "blocked peers" tests verify that contract state updates can propagate correctly even when direct peer-to-peer connections are blocked: |
| 46 | + |
| 47 | +1. Two regular nodes (Node1 and Node2) are configured to block each other's network addresses |
| 48 | +2. A gateway node is connected to both regular nodes |
| 49 | +3. All nodes subscribe to the ping contract |
| 50 | +4. Each node sends state updates with its own unique identifier |
| 51 | +5. Updates must route through the gateway to reach nodes with blocked direct connections |
| 52 | +6. The test verifies that all nodes eventually have the same consistent state |
| 53 | + |
| 54 | +This tests Freenet's ability to maintain contract state consistency even when the network topology prevents direct communication between some peers. |
| 55 | + |
| 56 | +## Common Test Infrastructure |
| 57 | + |
| 58 | +The `common/mod.rs` module provides shared infrastructure for tests, including: |
| 59 | + |
| 60 | +- Node and gateway configuration |
| 61 | +- Contract deployment helpers |
| 62 | +- State comparison utilities |
| 63 | +- WebSocket connection management |
| 64 | +- State update and verification functions |
| 65 | + |
| 66 | +## Parameterized Testing Approach |
| 67 | + |
| 68 | +The unified approach in `run_app_blocked_peers.rs` offers several advantages: |
| 69 | + |
| 70 | +- **Reduced duplication**: Core test logic is defined once and reused |
| 71 | +- **Consistent methodology**: All variants follow the same testing pattern |
| 72 | +- **Functional variants**: Tests focus on different functional behaviors (baseline, simple, solution) |
| 73 | +- **Easier maintenance**: Changes to the core test logic only need to be made in one place |
| 74 | +- **Focused test coverage**: Each variant tests a specific functional aspect of the system |
| 75 | + |
| 76 | +## Running the Tests |
| 77 | + |
| 78 | +Run all tests with: |
| 79 | + |
| 80 | +```bash |
| 81 | +cd apps/freenet-ping |
| 82 | +cargo test |
| 83 | +``` |
| 84 | + |
| 85 | +Run a specific blocked peers test variant: |
| 86 | + |
| 87 | +```bash |
| 88 | +cargo test test_ping_blocked_peers_simple |
| 89 | +``` |
| 90 | + |
| 91 | +Run the large-scale partial connectivity network test: |
| 92 | + |
| 93 | +```bash |
| 94 | +cargo test -p freenet-ping-app --test run_app_partially_connected_network |
| 95 | +``` |
| 96 | + |
| 97 | +--- |
0 commit comments