diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 12:31:21 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 12:31:21 +0000 |
| commit | 6b78ed707a69e22e5fadd5bd0999c16a0931bbaa (patch) | |
| tree | 4a97b880f89a8a825c6154e19d620c5ed3d82a30 /grasp-audit | |
| parent | 1e267c282d07c68dbee4682c66d3933032ed7fec (diff) | |
refactor(smoke): abstract NIP-34 announcement creation for ngit-relay compatibility
- Add create_announcement_event() helper to create properly formatted
NIP-34 repository announcements that are accepted by GRASP relays
- Update test_send_receive_event to use the helper (removes duplication)
- Update test_create_subscription to use NIP-34 announcements instead
of kind 1 TextNote events
ngit-relay only accepts events that reference the relay in clone/relays
tags. Kind 1 messages don't have these tags, so they're rejected. Using
NIP-34 announcements ensures all smoke tests work against ngit-relay.
Diffstat (limited to 'grasp-audit')
| -rw-r--r-- | grasp-audit/src/specs/nip01_smoke.rs | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/grasp-audit/src/specs/nip01_smoke.rs b/grasp-audit/src/specs/nip01_smoke.rs index bb7c79d..cb256c5 100644 --- a/grasp-audit/src/specs/nip01_smoke.rs +++ b/grasp-audit/src/specs/nip01_smoke.rs | |||
| @@ -10,6 +10,43 @@ use nostr_sdk::prelude::*; | |||
| 10 | pub struct Nip01SmokeTests; | 10 | pub struct Nip01SmokeTests; |
| 11 | 11 | ||
| 12 | impl Nip01SmokeTests { | 12 | impl Nip01SmokeTests { |
| 13 | /// Create a NIP-34 repository announcement event | ||
| 14 | /// | ||
| 15 | /// This helper creates a properly formatted NIP-34 announcement that will be | ||
| 16 | /// accepted by GRASP relays (which require events to list the relay in clone/relays tags). | ||
| 17 | async fn create_announcement_event(client: &AuditClient, test_name: &str) -> Result<Event, String> { | ||
| 18 | // Get relay URL from client | ||
| 19 | let relay_url = client.client().relays().await | ||
| 20 | .keys() | ||
| 21 | .next() | ||
| 22 | .ok_or("No relay URL found")? | ||
| 23 | .to_string(); | ||
| 24 | |||
| 25 | // Convert ws:// to http:// for clone URL | ||
| 26 | let http_url = relay_url | ||
| 27 | .replace("ws://", "http://") | ||
| 28 | .replace("wss://", "https://"); | ||
| 29 | |||
| 30 | // Create unique repository identifier | ||
| 31 | let repo_id = format!("{}-{}", test_name, uuid::Uuid::new_v4()); | ||
| 32 | let npub = client.public_key().to_bech32() | ||
| 33 | .map_err(|e| format!("Failed to encode npub: {}", e))?; | ||
| 34 | |||
| 35 | // Create NIP-34 repository announcement (kind 30617) | ||
| 36 | // This event lists the GRASP server, so it should be accepted | ||
| 37 | let event = client | ||
| 38 | .event_builder(Kind::Custom(30617), format!("NIP-01 smoke test repository: {}", test_name)) | ||
| 39 | .tag(Tag::identifier(&repo_id)) // d tag | ||
| 40 | .tag(Tag::custom(TagKind::Custom("name".into()), vec![format!("{} Test Repo", test_name)])) | ||
| 41 | .tag(Tag::custom(TagKind::Custom("description".into()), vec![format!("Repository for {} smoke testing", test_name)])) | ||
| 42 | .tag(Tag::custom(TagKind::Custom("clone".into()), vec![format!("{}/{}/{}.git", http_url, npub, repo_id)])) | ||
| 43 | .tag(Tag::custom(TagKind::Custom("relays".into()), vec![relay_url.clone()])) | ||
| 44 | .build(client.keys()) | ||
| 45 | .map_err(|e| format!("Failed to build event: {}", e))?; | ||
| 46 | |||
| 47 | Ok(event) | ||
| 48 | } | ||
| 49 | |||
| 13 | /// Run all NIP-01 smoke tests | 50 | /// Run all NIP-01 smoke tests |
| 14 | pub async fn run_all(client: &AuditClient) -> AuditResult { | 51 | pub async fn run_all(client: &AuditClient) -> AuditResult { |
| 15 | let mut results = AuditResult::new("NIP-01 Smoke Tests"); | 52 | let mut results = AuditResult::new("NIP-01 Smoke Tests"); |
| @@ -59,34 +96,8 @@ impl Nip01SmokeTests { | |||
| 59 | "Can send EVENT and receive OK response", | 96 | "Can send EVENT and receive OK response", |
| 60 | ) | 97 | ) |
| 61 | .run(|| async { | 98 | .run(|| async { |
| 62 | // Get relay URL from client | 99 | // Create a NIP-34 announcement event |
| 63 | let relay_url = client.client().relays().await | 100 | let event = Self::create_announcement_event(client, "send_receive_event").await?; |
| 64 | .keys() | ||
| 65 | .next() | ||
| 66 | .ok_or("No relay URL found")? | ||
| 67 | .to_string(); | ||
| 68 | |||
| 69 | // Convert ws:// to http:// for clone URL | ||
| 70 | let http_url = relay_url | ||
| 71 | .replace("ws://", "http://") | ||
| 72 | .replace("wss://", "https://"); | ||
| 73 | |||
| 74 | // Create unique repository identifier | ||
| 75 | let repo_id = format!("smoke-test-{}", uuid::Uuid::new_v4()); | ||
| 76 | let npub = client.public_key().to_bech32() | ||
| 77 | .map_err(|e| format!("Failed to encode npub: {}", e))?; | ||
| 78 | |||
| 79 | // Create NIP-34 repository announcement (kind 30617) | ||
| 80 | // This event lists the GRASP server, so it should be accepted | ||
| 81 | let event = client | ||
| 82 | .event_builder(Kind::Custom(30617), "NIP-01 smoke test repository") | ||
| 83 | .tag(Tag::identifier(&repo_id)) // d tag | ||
| 84 | .tag(Tag::custom(TagKind::Custom("name".into()), vec!["Smoke Test Repo"])) | ||
| 85 | .tag(Tag::custom(TagKind::Custom("description".into()), vec!["Repository for NIP-01 smoke testing"])) | ||
| 86 | .tag(Tag::custom(TagKind::Custom("clone".into()), vec![format!("{}/{}/{}.git", http_url, npub, repo_id)])) | ||
| 87 | .tag(Tag::custom(TagKind::Custom("relays".into()), vec![relay_url.clone()])) | ||
| 88 | .build(client.keys()) | ||
| 89 | .map_err(|e| format!("Failed to build event: {}", e))?; | ||
| 90 | 101 | ||
| 91 | // Send event | 102 | // Send event |
| 92 | let event_id = client | 103 | let event_id = client |
| @@ -149,20 +160,17 @@ impl Nip01SmokeTests { | |||
| 149 | "Can create subscription with REQ and receive EOSE", | 160 | "Can create subscription with REQ and receive EOSE", |
| 150 | ) | 161 | ) |
| 151 | .run(|| async { | 162 | .run(|| async { |
| 152 | // Create a test event first | 163 | // Create a NIP-34 announcement event (accepted by GRASP relays) |
| 153 | let event = client | 164 | let event = Self::create_announcement_event(client, "create_subscription").await?; |
| 154 | .event_builder(Kind::TextNote, "Subscription test event") | ||
| 155 | .build(client.keys()) | ||
| 156 | .map_err(|e| format!("Failed to build event: {}", e))?; | ||
| 157 | 165 | ||
| 158 | client | 166 | let event_id = client |
| 159 | .send_event(event.clone()) | 167 | .send_event(event.clone()) |
| 160 | .await | 168 | .await |
| 161 | .map_err(|e| format!("Failed to send event: {}", e))?; | 169 | .map_err(|e| format!("Failed to send event: {}", e))?; |
| 162 | 170 | ||
| 163 | // Subscribe to events | 171 | // Subscribe to NIP-34 announcements from this author |
| 164 | let filter = Filter::new() | 172 | let filter = Filter::new() |
| 165 | .kind(Kind::TextNote) | 173 | .kind(Kind::Custom(30617)) |
| 166 | .author(client.public_key()); | 174 | .author(client.public_key()); |
| 167 | 175 | ||
| 168 | let events = client | 176 | let events = client |