upleb.uk

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

summaryrefslogtreecommitdiff
path: root/grasp-audit
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-27 16:02:47 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-27 16:02:47 +0000
commitf6b0f92e6f06d2c44c4d668bb8fa918b84b6d04d (patch)
tree6bdd0154440a0cbf0564b087c888ebb58b5c51a0 /grasp-audit
parentc4a35fe8421bc0a0e6608f1b153cb6043230e8b5 (diff)
Task 5: Standardize nip01_smoke.rs tests to fixture-first pattern
- test_send_receive_event uses TestContext + FixtureKind::ValidRepo - test_create_subscription uses TestContext + FixtureKind::ValidRepo - Tests remain functionally equivalent (same verification logic) - Pure connectivity tests like test_websocket_connection unchanged - Tests pass: cargo test --lib nip01_smoke - Added fixture-first pattern documentation to test docstrings
Diffstat (limited to 'grasp-audit')
-rw-r--r--grasp-audit/src/specs/grasp01/nip01_smoke.rs55
1 files changed, 26 insertions, 29 deletions
diff --git a/grasp-audit/src/specs/grasp01/nip01_smoke.rs b/grasp-audit/src/specs/grasp01/nip01_smoke.rs
index 79220e5..182e362 100644
--- a/grasp-audit/src/specs/grasp01/nip01_smoke.rs
+++ b/grasp-audit/src/specs/grasp01/nip01_smoke.rs
@@ -4,7 +4,7 @@
4//! We don't comprehensively test NIP-01 because rust-nostr already has 1000+ tests. 4//! We don't comprehensively test NIP-01 because rust-nostr already has 1000+ tests.
5//! These are just smoke tests to ensure the relay is working at all. 5//! These are just smoke tests to ensure the relay is working at all.
6 6
7use crate::{AuditClient, AuditResult, TestResult}; 7use crate::{AuditClient, AuditResult, FixtureKind, TestContext, TestResult};
8use nostr_sdk::prelude::*; 8use nostr_sdk::prelude::*;
9 9
10pub struct Nip01SmokeTests; 10pub struct Nip01SmokeTests;
@@ -52,6 +52,12 @@ impl Nip01SmokeTests {
52 /// 52 ///
53 /// For GRASP servers, we send a NIP-34 repository announcement that lists 53 /// For GRASP servers, we send a NIP-34 repository announcement that lists
54 /// the GRASP server in clone and relays tags (required for acceptance). 54 /// the GRASP server in clone and relays tags (required for acceptance).
55 ///
56 /// ## Fixture-First Pattern
57 ///
58 /// 1. **Generate**: Create TestContext and get ValidRepo fixture
59 /// 2. **Send**: Fixture already sends the event to relay
60 /// 3. **Verify**: Query event back and verify it was stored correctly
55 pub async fn test_send_receive_event(client: &AuditClient) -> TestResult { 61 pub async fn test_send_receive_event(client: &AuditClient) -> TestResult {
56 TestResult::new( 62 TestResult::new(
57 "send_receive_event", 63 "send_receive_event",
@@ -59,30 +65,19 @@ impl Nip01SmokeTests {
59 "Can send EVENT and receive OK response", 65 "Can send EVENT and receive OK response",
60 ) 66 )
61 .run(|| async { 67 .run(|| async {
62 // Create a NIP-34 announcement event 68 // Step 1: GENERATE - Create TestContext and get ValidRepo fixture
63 let event = client 69 let ctx = TestContext::new(client);
64 .create_repo_announcement("send_receive_event") 70 let event = ctx
71 .get_fixture(FixtureKind::ValidRepo)
65 .await 72 .await
66 .map_err(|e| format!("Failed to create announcement: {}", e))?; 73 .map_err(|e| format!("Failed to create ValidRepo fixture: {}", e))?;
67 74
68 // Send event 75 let event_id = event.id;
69 let event_id = client
70 .send_event(event.clone())
71 .await
72 .map_err(|e| format!("Failed to send event: {}", e))?;
73
74 // Verify we got an event ID back
75 if event_id != event.id {
76 return Err(format!(
77 "Event ID mismatch: sent {}, got {}",
78 event.id, event_id
79 ));
80 }
81 76
82 // Wait a bit for event to be indexed 77 // Wait a bit for event to be indexed
83 tokio::time::sleep(std::time::Duration::from_millis(100)).await; 78 tokio::time::sleep(std::time::Duration::from_millis(100)).await;
84 79
85 // Try to query it back 80 // Step 2: VERIFY - Query event back
86 let filter = Filter::new().kind(Kind::Custom(30617)).id(event_id); 81 let filter = Filter::new().kind(Kind::Custom(30617)).id(event_id);
87 82
88 let events = client 83 let events = client
@@ -123,6 +118,12 @@ impl Nip01SmokeTests {
123 /// 118 ///
124 /// Spec: NIP-01 REQ message 119 /// Spec: NIP-01 REQ message
125 /// Requirement: Relay MUST support REQ subscriptions 120 /// Requirement: Relay MUST support REQ subscriptions
121 ///
122 /// ## Fixture-First Pattern
123 ///
124 /// 1. **Generate**: Create TestContext and get ValidRepo fixture
125 /// 2. **Send**: Fixture already sends the event to relay
126 /// 3. **Verify**: Subscribe and verify we receive the event
126 pub async fn test_create_subscription(client: &AuditClient) -> TestResult { 127 pub async fn test_create_subscription(client: &AuditClient) -> TestResult {
127 TestResult::new( 128 TestResult::new(
128 "create_subscription", 129 "create_subscription",
@@ -130,18 +131,14 @@ impl Nip01SmokeTests {
130 "Can create subscription with REQ and receive EOSE", 131 "Can create subscription with REQ and receive EOSE",
131 ) 132 )
132 .run(|| async { 133 .run(|| async {
133 // Create a NIP-34 announcement event (accepted by GRASP relays) 134 // Step 1: GENERATE - Create TestContext and get ValidRepo fixture
134 let event = client 135 let ctx = TestContext::new(client);
135 .create_repo_announcement("create_subscription") 136 let _event = ctx
136 .await 137 .get_fixture(FixtureKind::ValidRepo)
137 .map_err(|e| format!("Failed to create announcement: {}", e))?;
138
139 let _event_id = client
140 .send_event(event.clone())
141 .await 138 .await
142 .map_err(|e| format!("Failed to send event: {}", e))?; 139 .map_err(|e| format!("Failed to create ValidRepo fixture: {}", e))?;
143 140
144 // Subscribe to NIP-34 announcements from this author 141 // Step 2: VERIFY - Subscribe to NIP-34 announcements from this author
145 let filter = Filter::new() 142 let filter = Filter::new()
146 .kind(Kind::Custom(30617)) 143 .kind(Kind::Custom(30617))
147 .author(client.public_key()); 144 .author(client.public_key());