upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/nip01_compliance.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-20 21:45:45 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-20 21:45:45 +0000
commitca50f5b98f30d0933a510c05db86b608afee73a0 (patch)
treecdd694a82ba413220d80082056c34de444904f59 /tests/nip01_compliance.rs
parent89c69eae8e75d2b00794087d9ef74fd4856d0f88 (diff)
replace tests to use grasp-audit lib as much as possible
Diffstat (limited to 'tests/nip01_compliance.rs')
-rw-r--r--tests/nip01_compliance.rs80
1 files changed, 28 insertions, 52 deletions
diff --git a/tests/nip01_compliance.rs b/tests/nip01_compliance.rs
index 05957fd..4cb2af4 100644
--- a/tests/nip01_compliance.rs
+++ b/tests/nip01_compliance.rs
@@ -1,14 +1,13 @@
1//! NIP-01 Compliance Integration Tests 1//! NIP-01 Compliance Integration Tests
2//! 2//!
3//! These tests verify that ngit-grasp relay implements NIP-01 correctly 3//! Tests ngit-grasp relay's NIP-01 compliance using grasp-audit library.
4//! by using the grasp-audit library to run compliance tests. 4//! Avoids code duplication by delegating to grasp-audit's test suite.
5//! 5//!
6//! # Test Strategy 6//! # Test Strategy
7//! 7//!
8//! - Uses grasp-audit as a library (not CLI) 8//! - Uses TestRelay fixture for ngit-grasp relay lifecycle management
9//! - Automatically manages relay lifecycle 9//! - Uses grasp-audit's Nip01SmokeTests for actual test logic
10//! - Reuses test specs from grasp-audit (single source of truth) 10//! - Minimal duplication - single source of truth in grasp-audit
11//! - Pure Rust, no shell scripts
12//! 11//!
13//! # Running Tests 12//! # Running Tests
14//! 13//!
@@ -30,17 +29,20 @@ use grasp_audit::*;
30 29
31/// Test NIP-01 smoke tests against ngit-grasp relay 30/// Test NIP-01 smoke tests against ngit-grasp relay
32/// 31///
33/// This test: 32/// This test runs all NIP-01 smoke tests from grasp-audit against
34/// 1. Starts a fresh ngit-grasp relay instance 33/// the ngit-grasp relay implementation.
35/// 2. Runs all NIP-01 smoke tests from grasp-audit 34///
36/// 3. Verifies all tests pass 35/// Tests cover:
37/// 4. Shuts down the relay 36/// - WebSocket connection
37/// - Event send/receive
38/// - Subscriptions (REQ/CLOSE)
39/// - Event validation (signature, ID)
38#[tokio::test] 40#[tokio::test]
39async fn test_nip01_smoke() { 41async fn test_nip01_smoke() {
40 // Start test relay 42 // Start test relay
41 let relay = TestRelay::start().await; 43 let relay = TestRelay::start().await;
42 44
43 // Create audit client in CI mode (isolated, no cleanup needed) 45 // Create audit client in CI mode (isolated testing)
44 let config = AuditConfig::ci(); 46 let config = AuditConfig::ci();
45 let client = AuditClient::new(relay.url(), config) 47 let client = AuditClient::new(relay.url(), config)
46 .await 48 .await
@@ -64,34 +66,12 @@ async fn test_nip01_smoke() {
64 ); 66 );
65} 67}
66 68
67/// Test individual NIP-01 tests can be run separately 69/// Test that relay properly validates events
68///
69/// This demonstrates that we can run individual tests from the specs
70/// for more granular testing or debugging.
71#[tokio::test]
72async fn test_nip01_individual_tests() {
73 use grasp_audit::specs::grasp01::Nip01SmokeTests;
74
75 let relay = TestRelay::start().await;
76 let config = AuditConfig::ci();
77 let client = AuditClient::new(relay.url(), config)
78 .await
79 .expect("Failed to create audit client");
80
81 // We can't call private methods, so we'll run the full suite
82 // This test is mainly to show the pattern
83 let all_results = Nip01SmokeTests::run_all(&client).await;
84
85 relay.stop().await;
86
87 // Verify
88 assert!(all_results.all_passed());
89}
90
91/// Test that relay rejects invalid events
92/// 70///
93/// This is a critical security test - we want to ensure the relay 71/// Critical security test - ensures relay validates:
94/// properly validates events before accepting them. 72/// - Event signatures
73/// - Event IDs
74/// - Other NIP-01 requirements
95#[tokio::test] 75#[tokio::test]
96async fn test_relay_validates_events() { 76async fn test_relay_validates_events() {
97 let relay = TestRelay::start().await; 77 let relay = TestRelay::start().await;
@@ -100,29 +80,29 @@ async fn test_relay_validates_events() {
100 .await 80 .await
101 .expect("Failed to create audit client"); 81 .expect("Failed to create audit client");
102 82
103 // The validation tests are part of the smoke tests 83 // Run smoke tests which include validation tests
104 let results = specs::Nip01SmokeTests::run_all(&client).await; 84 let results = specs::Nip01SmokeTests::run_all(&client).await;
105 85
106 // Check that validation tests exist and pass 86 relay.stop().await;
87
88 // Filter to validation tests
107 let validation_tests: Vec<_> = results 89 let validation_tests: Vec<_> = results
108 .results 90 .results
109 .iter() 91 .iter()
110 .filter(|t| t.spec_ref.contains("validation")) 92 .filter(|t| t.name.contains("reject") || t.name.contains("invalid"))
111 .collect(); 93 .collect();
112 94
113 relay.stop().await;
114
115 // Should have validation tests 95 // Should have validation tests
116 assert!( 96 assert!(
117 !validation_tests.is_empty(), 97 !validation_tests.is_empty(),
118 "No validation tests found in NIP-01 smoke tests" 98 "No validation tests found (these are critical for security)"
119 ); 99 );
120 100
121 // All validation tests should pass 101 // All validation tests should pass
122 for test in validation_tests { 102 for test in validation_tests {
123 assert!( 103 assert!(
124 test.passed, 104 test.passed,
125 "Validation test failed: {} - {}", 105 "Validation test failed: {} - {}\nThis is a security issue!",
126 test.name, 106 test.name,
127 test.error.as_deref().unwrap_or("unknown error") 107 test.error.as_deref().unwrap_or("unknown error")
128 ); 108 );
@@ -131,7 +111,7 @@ async fn test_relay_validates_events() {
131 111
132/// Test relay lifecycle management 112/// Test relay lifecycle management
133/// 113///
134/// Ensures our test fixture properly manages relay lifecycle 114/// Verifies TestRelay fixture properly manages relay lifecycle
135#[tokio::test] 115#[tokio::test]
136async fn test_relay_lifecycle() { 116async fn test_relay_lifecycle() {
137 // Start relay 117 // Start relay
@@ -148,15 +128,11 @@ async fn test_relay_lifecycle() {
148 128
149 // Stop relay 129 // Stop relay
150 relay.stop().await; 130 relay.stop().await;
151
152 // Note: We can't easily verify disconnection without modifying grasp-audit
153 // to expose connection state after relay shutdown. That's okay - the
154 // important part is that the relay starts and stops cleanly.
155} 131}
156 132
157/// Test multiple relays can run in parallel 133/// Test multiple relays can run in parallel
158/// 134///
159/// This ensures our random port selection works correctly 135/// Ensures random port selection avoids conflicts
160#[tokio::test] 136#[tokio::test]
161async fn test_parallel_relays() { 137async fn test_parallel_relays() {
162 // Start two relays simultaneously 138 // Start two relays simultaneously