diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-19 17:01:36 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-19 17:01:36 +0000 |
| commit | bf7f4d5381203d5c27b2811d62c5b1781533aa2b (patch) | |
| tree | 26903bbf535d83abd7242370d8b6932eb80e3389 /grasp-audit/src/specs/grasp01/nip11_document.rs | |
| parent | fa065ad128882755f2a988d6203b59a2ab5e38ff (diff) | |
fix some clippy fmt warnings
Diffstat (limited to 'grasp-audit/src/specs/grasp01/nip11_document.rs')
| -rw-r--r-- | grasp-audit/src/specs/grasp01/nip11_document.rs | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/grasp-audit/src/specs/grasp01/nip11_document.rs b/grasp-audit/src/specs/grasp01/nip11_document.rs index 3f9c04a..be04777 100644 --- a/grasp-audit/src/specs/grasp01/nip11_document.rs +++ b/grasp-audit/src/specs/grasp01/nip11_document.rs | |||
| @@ -9,7 +9,6 @@ | |||
| 9 | //! - Handles curation field correctly (present if curated, absent otherwise) | 9 | //! - Handles curation field correctly (present if curated, absent otherwise) |
| 10 | 10 | ||
| 11 | use crate::{AuditClient, AuditResult, TestResult}; | 11 | use crate::{AuditClient, AuditResult, TestResult}; |
| 12 | use nostr_sdk::prelude::*; | ||
| 13 | 12 | ||
| 14 | pub struct Nip11DocumentTests; | 13 | pub struct Nip11DocumentTests; |
| 15 | 14 | ||
| @@ -17,25 +16,25 @@ impl Nip11DocumentTests { | |||
| 17 | /// Run all NIP-11 document tests | 16 | /// Run all NIP-11 document tests |
| 18 | pub async fn run_all(client: &AuditClient) -> AuditResult { | 17 | pub async fn run_all(client: &AuditClient) -> AuditResult { |
| 19 | let mut results = AuditResult::new("GRASP-01 NIP-11 Document Tests"); | 18 | let mut results = AuditResult::new("GRASP-01 NIP-11 Document Tests"); |
| 20 | 19 | ||
| 21 | // NIP-11 relay information tests | 20 | // NIP-11 relay information tests |
| 22 | results.add(Self::test_nip11_document_exists(client).await); | 21 | results.add(Self::test_nip11_document_exists(client).await); |
| 23 | results.add(Self::test_nip11_supported_grasps_field(client).await); | 22 | results.add(Self::test_nip11_supported_grasps_field(client).await); |
| 24 | results.add(Self::test_nip11_repo_acceptance_criteria_field(client).await); | 23 | results.add(Self::test_nip11_repo_acceptance_criteria_field(client).await); |
| 25 | results.add(Self::test_nip11_curation_field(client).await); | 24 | results.add(Self::test_nip11_curation_field(client).await); |
| 26 | 25 | ||
| 27 | results | 26 | results |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | // ========================================================================= | 29 | // ========================================================================= |
| 31 | // NIP-11 Relay Information Tests | 30 | // NIP-11 Relay Information Tests |
| 32 | // ========================================================================= | 31 | // ========================================================================= |
| 33 | 32 | ||
| 34 | /// Test: Serve NIP-11 document | 33 | /// Test: Serve NIP-11 document |
| 35 | /// | 34 | /// |
| 36 | /// Spec: Line 11 of ../grasp/01.md | 35 | /// Spec: Line 11 of ../grasp/01.md |
| 37 | /// Requirement: MUST serve NIP-11 document | 36 | /// Requirement: MUST serve NIP-11 document |
| 38 | async fn test_nip11_document_exists(client: &AuditClient) -> TestResult { | 37 | async fn test_nip11_document_exists(_client: &AuditClient) -> TestResult { |
| 39 | TestResult::new( | 38 | TestResult::new( |
| 40 | "nip11_document_exists", | 39 | "nip11_document_exists", |
| 41 | "GRASP-01:nostr-relay:11", | 40 | "GRASP-01:nostr-relay:11", |
| @@ -52,17 +51,17 @@ impl Nip11DocumentTests { | |||
| 52 | // 4. Verify response is valid JSON | 51 | // 4. Verify response is valid JSON |
| 53 | // 5. Parse as NIP-11 document | 52 | // 5. Parse as NIP-11 document |
| 54 | // 6. Verify has required fields (name, description, etc.) | 53 | // 6. Verify has required fields (name, description, etc.) |
| 55 | 54 | ||
| 56 | Err("Not implemented yet".to_string()) | 55 | Err("Not implemented yet".to_string()) |
| 57 | }) | 56 | }) |
| 58 | .await | 57 | .await |
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | /// Test: NIP-11 includes supported_grasps field | 60 | /// Test: NIP-11 includes supported_grasps field |
| 62 | /// | 61 | /// |
| 63 | /// Spec: Line 12 of ../grasp/01.md | 62 | /// Spec: Line 12 of ../grasp/01.md |
| 64 | /// Requirement: MUST list supported GRASPs as string array | 63 | /// Requirement: MUST list supported GRASPs as string array |
| 65 | async fn test_nip11_supported_grasps_field(client: &AuditClient) -> TestResult { | 64 | async fn test_nip11_supported_grasps_field(_client: &AuditClient) -> TestResult { |
| 66 | TestResult::new( | 65 | TestResult::new( |
| 67 | "nip11_supported_grasps_field", | 66 | "nip11_supported_grasps_field", |
| 68 | "GRASP-01:nostr-relay:12", | 67 | "GRASP-01:nostr-relay:12", |
| @@ -76,17 +75,17 @@ impl Nip11DocumentTests { | |||
| 76 | // 4. Verify array includes "GRASP-01" | 75 | // 4. Verify array includes "GRASP-01" |
| 77 | // 5. Verify format: each entry matches pattern "GRASP-\d{2}" | 76 | // 5. Verify format: each entry matches pattern "GRASP-\d{2}" |
| 78 | // 6. Document other GRASPs found (for info) | 77 | // 6. Document other GRASPs found (for info) |
| 79 | 78 | ||
| 80 | Err("Not implemented yet".to_string()) | 79 | Err("Not implemented yet".to_string()) |
| 81 | }) | 80 | }) |
| 82 | .await | 81 | .await |
| 83 | } | 82 | } |
| 84 | 83 | ||
| 85 | /// Test: NIP-11 includes repo_acceptance_criteria field | 84 | /// Test: NIP-11 includes repo_acceptance_criteria field |
| 86 | /// | 85 | /// |
| 87 | /// Spec: Line 13 of ../grasp/01.md | 86 | /// Spec: Line 13 of ../grasp/01.md |
| 88 | /// Requirement: MUST list repository acceptance criteria | 87 | /// Requirement: MUST list repository acceptance criteria |
| 89 | async fn test_nip11_repo_acceptance_criteria_field(client: &AuditClient) -> TestResult { | 88 | async fn test_nip11_repo_acceptance_criteria_field(_client: &AuditClient) -> TestResult { |
| 90 | TestResult::new( | 89 | TestResult::new( |
| 91 | "nip11_repo_acceptance_criteria_field", | 90 | "nip11_repo_acceptance_criteria_field", |
| 92 | "GRASP-01:nostr-relay:13", | 91 | "GRASP-01:nostr-relay:13", |
| @@ -101,17 +100,17 @@ impl Nip11DocumentTests { | |||
| 101 | // 5. Document the criteria (for info) | 100 | // 5. Document the criteria (for info) |
| 102 | // Examples: "Must list this relay in clone and relays tags" | 101 | // Examples: "Must list this relay in clone and relays tags" |
| 103 | // "Pre-payment required via Lightning invoice" | 102 | // "Pre-payment required via Lightning invoice" |
| 104 | 103 | ||
| 105 | Err("Not implemented yet".to_string()) | 104 | Err("Not implemented yet".to_string()) |
| 106 | }) | 105 | }) |
| 107 | .await | 106 | .await |
| 108 | } | 107 | } |
| 109 | 108 | ||
| 110 | /// Test: NIP-11 curation field handling | 109 | /// Test: NIP-11 curation field handling |
| 111 | /// | 110 | /// |
| 112 | /// Spec: Line 14 of ../grasp/01.md | 111 | /// Spec: Line 14 of ../grasp/01.md |
| 113 | /// Requirement: MUST include curation if curated, omit otherwise | 112 | /// Requirement: MUST include curation if curated, omit otherwise |
| 114 | async fn test_nip11_curation_field(client: &AuditClient) -> TestResult { | 113 | async fn test_nip11_curation_field(_client: &AuditClient) -> TestResult { |
| 115 | TestResult::new( | 114 | TestResult::new( |
| 116 | "nip11_curation_field", | 115 | "nip11_curation_field", |
| 117 | "GRASP-01:nostr-relay:14", | 116 | "GRASP-01:nostr-relay:14", |
| @@ -127,39 +126,41 @@ impl Nip11DocumentTests { | |||
| 127 | // 4. If absent: | 126 | // 4. If absent: |
| 128 | // - Document that no curation beyond SPAM prevention | 127 | // - Document that no curation beyond SPAM prevention |
| 129 | // 5. Both cases are valid per spec | 128 | // 5. Both cases are valid per spec |
| 130 | 129 | ||
| 131 | Err("Not implemented yet".to_string()) | 130 | Err("Not implemented yet".to_string()) |
| 132 | }) | 131 | }) |
| 133 | .await | 132 | .await |
| 134 | } | 133 | } |
| 135 | |||
| 136 | } | 134 | } |
| 137 | 135 | ||
| 138 | #[cfg(test)] | 136 | #[cfg(test)] |
| 139 | mod tests { | 137 | mod tests { |
| 140 | use super::*; | 138 | use super::*; |
| 141 | use crate::AuditConfig; | 139 | use crate::AuditConfig; |
| 142 | 140 | ||
| 143 | #[tokio::test] | 141 | #[tokio::test] |
| 144 | #[ignore] // Requires running relay | 142 | #[ignore] // Requires running relay |
| 145 | async fn test_grasp01_nip11_document_against_relay() { | 143 | async fn test_grasp01_nip11_document_against_relay() { |
| 146 | // Read relay URL from environment variable - must be supplied | 144 | // Read relay URL from environment variable - must be supplied |
| 147 | let relay_url = std::env::var("RELAY_URL") | 145 | let relay_url = std::env::var("RELAY_URL").expect( |
| 148 | .expect("RELAY_URL environment variable must be set. Example: RELAY_URL=ws://localhost:18081"); | 146 | "RELAY_URL environment variable must be set. Example: RELAY_URL=ws://localhost:18081", |
| 149 | 147 | ); | |
| 150 | let config = AuditConfig::ci(); | 148 | |
| 151 | let client = AuditClient::new(&relay_url, config) | 149 | let config = AuditConfig::ci(); |
| 152 | .await | 150 | let client = AuditClient::new(&relay_url, config) |
| 153 | .expect(&format!( | 151 | .await |
| 154 | "Failed to connect to relay at {}. Ensure relay is running and accessible. \ | 152 | .unwrap_or_else(|_| { |
| 153 | panic!( | ||
| 154 | "Failed to connect to relay at {}. Ensure relay is running and accessible. \ | ||
| 155 | Try: docker run --rm -p 18081:8081 ghcr.io/danconwaydev/ngit-relay:latest", | 155 | Try: docker run --rm -p 18081:8081 ghcr.io/danconwaydev/ngit-relay:latest", |
| 156 | relay_url | 156 | relay_url |
| 157 | )); | 157 | ) |
| 158 | 158 | }); | |
| 159 | |||
| 159 | let results = Nip11DocumentTests::run_all(&client).await; | 160 | let results = Nip11DocumentTests::run_all(&client).await; |
| 160 | results.print_report(); | 161 | results.print_report(); |
| 161 | 162 | ||
| 162 | // Don't assert all passed yet - tests not implemented | 163 | // Don't assert all passed yet - tests not implemented |
| 163 | // assert!(results.all_passed(), "Some GRASP-01 NIP-11 document tests failed"); | 164 | // assert!(results.all_passed(), "Some GRASP-01 NIP-11 document tests failed"); |
| 164 | } | 165 | } |
| 165 | } \ No newline at end of file | 166 | } |