diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 07:03:04 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 07:03:04 +0000 |
| commit | 74c7b090a6ec7f749a3a79dcb0c9a0a6bc198702 (patch) | |
| tree | cfb3a0b6ac170ff54a7f82cfd0472ecbfe1206cf /grasp-audit/README.md | |
| parent | 5cd47079ee762125817612d2bf82a0bca07da3ad (diff) | |
test: add ngit-relay integration testing instructions
- Add RELAY_URL environment variable support to tests
- Document expected behavior when testing against ngit-relay
- Add test-ngit-relay.sh script for automated testing
- Clarify that ngit-relay only accepts Git events (NIP-34)
- Note that 4/6 NIP-01 smoke tests passing is expected
- Key validation tests (invalid signature/ID) pass correctly
- Add instructions for testing against general-purpose relays
The validation tests passing confirms ngit-relay implements NIP-01
correctly, even though it has restrictive acceptance policies.
Diffstat (limited to 'grasp-audit/README.md')
| -rw-r--r-- | grasp-audit/README.md | 149 |
1 files changed, 147 insertions, 2 deletions
diff --git a/grasp-audit/README.md b/grasp-audit/README.md index b49ad11..a2b0024 100644 --- a/grasp-audit/README.md +++ b/grasp-audit/README.md | |||
| @@ -123,15 +123,160 @@ cargo run --example simple_audit | |||
| 123 | 123 | ||
| 124 | ## Testing | 124 | ## Testing |
| 125 | 125 | ||
| 126 | ### Unit Tests | ||
| 127 | |||
| 126 | ```bash | 128 | ```bash |
| 127 | # Enter dev environment (NixOS) | 129 | # Enter dev environment (NixOS) |
| 128 | nix develop | 130 | nix develop |
| 129 | 131 | ||
| 130 | # Run unit tests | 132 | # Run unit tests (no relay required) |
| 131 | cargo test | 133 | cargo test |
| 134 | ``` | ||
| 135 | |||
| 136 | ### Integration Tests Against ngit-relay | ||
| 137 | |||
| 138 | Test against the reference GRASP implementation to ensure compatibility. | ||
| 139 | |||
| 140 | **Note:** ngit-relay is a specialized GRASP relay that only accepts Git-related events (NIP-34). | ||
| 141 | Some NIP-01 smoke tests (like `send_receive_event`) will fail because ngit-relay rejects | ||
| 142 | non-Git events. This is expected behavior - the validation tests should still pass. | ||
| 143 | |||
| 144 | ```bash | ||
| 145 | # 1. Create temporary directories for clean state | ||
| 146 | mkdir -p /tmp/ngit-test/{repos,blossom,relay-db,logs} | ||
| 147 | |||
| 148 | # 2. Start ngit-relay with fresh data (using port 8082 to avoid conflicts) | ||
| 149 | docker run --rm -d \ | ||
| 150 | --name ngit-relay-test \ | ||
| 151 | -p 8082:8081 \ | ||
| 152 | -e NGIT_DOMAIN=localhost \ | ||
| 153 | -e NGIT_RELAY_NAME="ngit-relay test instance" \ | ||
| 154 | -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ | ||
| 155 | -e NGIT_OWNER_NPUB="npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr" \ | ||
| 156 | -e NGIT_PROACTIVE_SYNC_GIT=false \ | ||
| 157 | -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ | ||
| 158 | -e NGIT_PROACTIVE_SYNC_NOSTR=false \ | ||
| 159 | -e NGIT_LOG_LEVEL=INFO \ | ||
| 160 | -v /tmp/ngit-test/repos:/srv/ngit-relay/repos \ | ||
| 161 | -v /tmp/ngit-test/blossom:/srv/ngit-relay/blossom \ | ||
| 162 | -v /tmp/ngit-test/relay-db:/srv/ngit-relay/relay-db \ | ||
| 163 | -v /tmp/ngit-test/logs:/var/log/ngit-relay \ | ||
| 164 | ghcr.io/danconwaydev/ngit-relay:latest | ||
| 165 | |||
| 166 | # 3. Wait for relay to start | ||
| 167 | sleep 3 | ||
| 168 | |||
| 169 | # 4. Run tests against ngit-relay on port 8082 | ||
| 170 | RELAY_URL=ws://localhost:8082 cargo test --ignored | ||
| 171 | |||
| 172 | # Expected results when testing against ngit-relay: | ||
| 173 | # - ✓ websocket_connection (basic connectivity) | ||
| 174 | # - ✗ send_receive_event (ngit-relay rejects non-Git events - EXPECTED FAILURE) | ||
| 175 | # - ✗ create_subscription (depends on send_receive_event - EXPECTED FAILURE) | ||
| 176 | # - ✓ close_subscription (basic protocol) | ||
| 177 | # - ✓ reject_invalid_signature (validation works! - KEY TEST) | ||
| 178 | # - ✓ reject_invalid_event_id (validation works! - KEY TEST) | ||
| 179 | # | ||
| 180 | # Result: 4/6 passed (66.7%) | ||
| 181 | # | ||
| 182 | # This is CORRECT behavior! It shows ngit-relay: | ||
| 183 | # 1. Implements NIP-01 validation correctly (rejects invalid events) | ||
| 184 | # 2. Has restrictive acceptance policies (only accepts Git events) | ||
| 185 | # 3. Is a properly functioning GRASP relay | ||
| 186 | # | ||
| 187 | # The test will exit with an error, but the validation tests passing | ||
| 188 | # is what matters for GRASP compliance. | ||
| 189 | |||
| 190 | # 5. Stop and cleanup | ||
| 191 | docker stop ngit-relay-test | ||
| 192 | rm -rf /tmp/ngit-test | ||
| 193 | ``` | ||
| 194 | |||
| 195 | **Why fresh directories?** | ||
| 196 | - Ensures clean state for each test run | ||
| 197 | - Prevents test pollution from previous runs | ||
| 198 | - Matches CI environment behavior | ||
| 199 | |||
| 200 | **Environment variables explained:** | ||
| 201 | - `NGIT_DOMAIN`: Domain name (localhost for testing) | ||
| 202 | - `NGIT_RELAY_NAME`: Relay name for NIP-11 | ||
| 203 | - `NGIT_RELAY_DESCRIPTION`: Relay description for NIP-11 | ||
| 204 | - `NGIT_OWNER_NPUB`: Relay owner's npub (uses reference impl owner) | ||
| 205 | - `NGIT_PROACTIVE_SYNC_*`: Disable proactive sync for testing | ||
| 206 | - `NGIT_LOG_LEVEL`: Set to INFO for debugging | ||
| 207 | |||
| 208 | **Port mapping:** | ||
| 209 | - ngit-relay serves both WebSocket (relay) and HTTP (git) on port 8081 | ||
| 210 | - WebSocket endpoint: `ws://localhost:8081/` | ||
| 211 | - Git HTTP endpoint: `http://localhost:8081/<npub>/<identifier>.git` | ||
| 212 | |||
| 213 | ### Testing Against General-Purpose Relays | ||
| 214 | |||
| 215 | For full NIP-01 smoke test coverage (all 6 tests passing), test against a general-purpose relay: | ||
| 216 | |||
| 217 | ```bash | ||
| 218 | # Start nostr-rs-relay (accepts all event kinds) | ||
| 219 | docker run --rm -d --name nostr-test-relay -p 7000:8080 scsibug/nostr-rs-relay | ||
| 132 | 220 | ||
| 133 | # Run integration tests (requires running relay) | 221 | # Run tests (all should pass) |
| 222 | cargo test --lib -- --ignored --nocapture | ||
| 223 | |||
| 224 | # Cleanup | ||
| 225 | docker stop nostr-test-relay | ||
| 226 | ``` | ||
| 227 | |||
| 228 | Expected: 6/6 tests passed (100%) | ||
| 229 | |||
| 230 | ### Quick Test Script | ||
| 231 | |||
| 232 | Save this as `test-ngit-relay.sh`: | ||
| 233 | |||
| 234 | ```bash | ||
| 235 | #!/bin/bash | ||
| 236 | set -e | ||
| 237 | |||
| 238 | echo "🧹 Cleaning up old test data..." | ||
| 239 | rm -rf /tmp/ngit-test | ||
| 240 | mkdir -p /tmp/ngit-test/{repos,blossom,relay-db,logs} | ||
| 241 | |||
| 242 | echo "🚀 Starting ngit-relay..." | ||
| 243 | docker run --rm -d \ | ||
| 244 | --name ngit-relay-test \ | ||
| 245 | -p 8081:8081 \ | ||
| 246 | -e NGIT_DOMAIN=localhost \ | ||
| 247 | -e NGIT_RELAY_NAME="ngit-relay test instance" \ | ||
| 248 | -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ | ||
| 249 | -e NGIT_OWNER_NPUB="npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr" \ | ||
| 250 | -e NGIT_PROACTIVE_SYNC_GIT=false \ | ||
| 251 | -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ | ||
| 252 | -e NGIT_PROACTIVE_SYNC_NOSTR=false \ | ||
| 253 | -e NGIT_LOG_LEVEL=INFO \ | ||
| 254 | -v /tmp/ngit-test/repos:/srv/ngit-relay/repos \ | ||
| 255 | -v /tmp/ngit-test/blossom:/srv/ngit-relay/blossom \ | ||
| 256 | -v /tmp/ngit-test/relay-db:/srv/ngit-relay/relay-db \ | ||
| 257 | -v /tmp/ngit-test/logs:/var/log/ngit-relay \ | ||
| 258 | ghcr.io/danconwaydev/ngit-relay:latest | ||
| 259 | |||
| 260 | echo "⏳ Waiting for relay to start..." | ||
| 261 | sleep 3 | ||
| 262 | |||
| 263 | echo "🧪 Running tests..." | ||
| 134 | cargo test --ignored | 264 | cargo test --ignored |
| 265 | |||
| 266 | echo "🛑 Stopping relay..." | ||
| 267 | docker stop ngit-relay-test | ||
| 268 | |||
| 269 | echo "🧹 Cleaning up..." | ||
| 270 | rm -rf /tmp/ngit-test | ||
| 271 | |||
| 272 | echo "✅ Done!" | ||
| 273 | ``` | ||
| 274 | |||
| 275 | Then run: | ||
| 276 | |||
| 277 | ```bash | ||
| 278 | chmod +x test-ngit-relay.sh | ||
| 279 | ./test-ngit-relay.sh | ||
| 135 | ``` | 280 | ``` |
| 136 | 281 | ||
| 137 | ## Architecture | 282 | ## Architecture |