upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-11 16:53:03 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-11 16:53:03 +0000
commit2a9160836bb87fdea3ae891563b0169c68d1c2ab (patch)
tree583c890687beaf7f380fc0be131bdf17485f06fa /tests
parent52489d3b1a7d79e164b4cc901b53fd06c05ce1b1 (diff)
fix: resolve all fmt and clippy warnings
Main lib (src/): - Add #[allow(dead_code)] for build_info field (stored to prevent Prometheus unregistration) - Add #[allow(dead_code)] for first_seen field (reserved for future rate limiting) - Replace .or_insert_with(RelaySyncNeeds::default) with .or_default() - Replace manual div_ceil implementations with .div_ceil(100) Test code (tests/): - Replace .expect(&format!(...)) with .unwrap_or_else(|_| panic!(...)) - Remove needless borrows in fetch_metrics() calls - Add #[allow(dead_code)] and #[allow(unused_imports)] to test helpers module grasp-audit: - Apply cargo fmt to fix formatting
Diffstat (limited to 'tests')
-rw-r--r--tests/common/mod.rs2
-rw-r--r--tests/common/relay.rs6
-rw-r--r--tests/common/sync_helpers.rs54
-rw-r--r--tests/nip77_negentropy.rs27
-rw-r--r--tests/sync.rs2
-rw-r--r--tests/sync/bootstrap.rs9
-rw-r--r--tests/sync/discovery.rs15
-rw-r--r--tests/sync/live_sync.rs7
-rw-r--r--tests/sync/metrics.rs6
-rw-r--r--tests/sync/tag_variations.rs139
10 files changed, 150 insertions, 117 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 9bbfb40..37ac3bb 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,4 +1,6 @@
1//! Common test utilities 1//! Common test utilities
2#![allow(dead_code)] // Test helpers may not be used in all test configurations
3#![allow(unused_imports)] // Re-exports may not be used in all test configurations
2 4
3pub mod relay; 5pub mod relay;
4pub mod sync_helpers; 6pub mod sync_helpers;
diff --git a/tests/common/relay.rs b/tests/common/relay.rs
index 2dd526b..55cc18e 100644
--- a/tests/common/relay.rs
+++ b/tests/common/relay.rs
@@ -104,7 +104,11 @@ impl TestRelay {
104 } 104 }
105 105
106 /// Start relay with full options 106 /// Start relay with full options
107 async fn start_with_full_options(port: u16, bootstrap_relay_url: Option<String>, disable_negentropy: bool) -> Self { 107 async fn start_with_full_options(
108 port: u16,
109 bootstrap_relay_url: Option<String>,
110 disable_negentropy: bool,
111 ) -> Self {
108 let bind_address = format!("127.0.0.1:{}", port); 112 let bind_address = format!("127.0.0.1:{}", port);
109 let url = format!("ws://127.0.0.1:{}", port); 113 let url = format!("ws://127.0.0.1:{}", port);
110 114
diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs
index 531ebe1..7fa0393 100644
--- a/tests/common/sync_helpers.rs
+++ b/tests/common/sync_helpers.rs
@@ -173,7 +173,11 @@ impl TestClient {
173/// # Returns 173/// # Returns
174/// * `Ok(Event)` - Signed event ready to send 174/// * `Ok(Event)` - Signed event ready to send
175/// * `Err(String)` - If signing fails 175/// * `Err(String)` - If signing fails
176pub fn build_layer2_issue_event(keys: &Keys, repo_coord: &str, title: &str) -> Result<Event, String> { 176pub fn build_layer2_issue_event(
177 keys: &Keys,
178 repo_coord: &str,
179 title: &str,
180) -> Result<Event, String> {
177 build_layer2_issue_with_tag(keys, repo_coord, title, TagVariant::LowercaseA) 181 build_layer2_issue_with_tag(keys, repo_coord, title, TagVariant::LowercaseA)
178} 182}
179 183
@@ -256,10 +260,7 @@ pub fn build_layer3_comment_event(
256 // Choose tag based on kind (NIP-22 uses E, NIP-10 style uses e) 260 // Choose tag based on kind (NIP-22 uses E, NIP-10 style uses e)
257 let tag = if kind_num == KIND_COMMENT { 261 let tag = if kind_num == KIND_COMMENT {
258 // NIP-22 comment: uppercase 'E' tag 262 // NIP-22 comment: uppercase 'E' tag
259 Tag::custom( 263 Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()])
260 TagKind::custom("E"),
261 vec![parent_event_id.to_hex()],
262 )
263 } else { 264 } else {
264 // Kind 1 reply: lowercase 'e' tag with root marker (NIP-10) 265 // Kind 1 reply: lowercase 'e' tag with root marker (NIP-10)
265 Tag::custom( 266 Tag::custom(
@@ -299,10 +300,7 @@ pub fn build_layer3_comment_with_uppercase_e_tag(
299 parent_event_id: &EventId, 300 parent_event_id: &EventId,
300 content: &str, 301 content: &str,
301) -> Result<Event, String> { 302) -> Result<Event, String> {
302 let tag = Tag::custom( 303 let tag = Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()]);
303 TagKind::custom("E"),
304 vec![parent_event_id.to_hex()],
305 );
306 304
307 EventBuilder::new(Kind::Custom(KIND_COMMENT), content) 305 EventBuilder::new(Kind::Custom(KIND_COMMENT), content)
308 .tags(vec![tag]) 306 .tags(vec![tag])
@@ -316,10 +314,7 @@ pub fn build_layer3_quote_with_q_tag(
316 parent_event_id: &EventId, 314 parent_event_id: &EventId,
317 content: &str, 315 content: &str,
318) -> Result<Event, String> { 316) -> Result<Event, String> {
319 let tag = Tag::custom( 317 let tag = Tag::custom(TagKind::custom("q"), vec![parent_event_id.to_hex()]);
320 TagKind::custom("q"),
321 vec![parent_event_id.to_hex()],
322 );
323 318
324 EventBuilder::new(Kind::Custom(1), content) 319 EventBuilder::new(Kind::Custom(1), content)
325 .tags(vec![tag]) 320 .tags(vec![tag])
@@ -587,10 +582,7 @@ pub fn repo_coord(keys: &Keys, identifier: &str) -> String {
587/// ``` 582/// ```
588pub async fn fetch_metrics(relay_url: &str) -> Result<String, reqwest::Error> { 583pub async fn fetch_metrics(relay_url: &str) -> Result<String, reqwest::Error> {
589 // Convert ws:// URL to http:// for metrics endpoint 584 // Convert ws:// URL to http:// for metrics endpoint
590 let http_url = relay_url 585 let http_url = relay_url.replace("ws://", "http://").replace("/", "") + "/metrics";
591 .replace("ws://", "http://")
592 .replace("/", "")
593 + "/metrics";
594 586
595 reqwest::get(&http_url).await?.text().await 587 reqwest::get(&http_url).await?.text().await
596} 588}
@@ -888,8 +880,8 @@ mod tests {
888 let keys = Keys::generate(); 880 let keys = Keys::generate();
889 let coord = repo_coord(&keys, "my-repo"); 881 let coord = repo_coord(&keys, "my-repo");
890 882
891 let event = build_layer2_issue_event(&keys, &coord, "Test Issue") 883 let event =
892 .expect("Should create event"); 884 build_layer2_issue_event(&keys, &coord, "Test Issue").expect("Should create event");
893 885
894 // nostr-sdk 0.43: use field access 886 // nostr-sdk 0.43: use field access
895 assert_eq!(event.kind.as_u16(), KIND_ISSUE); 887 assert_eq!(event.kind.as_u16(), KIND_ISSUE);
@@ -937,8 +929,13 @@ mod tests {
937 let keys = Keys::generate(); 929 let keys = Keys::generate();
938 let parent_id = EventId::all_zeros(); 930 let parent_id = EventId::all_zeros();
939 931
940 let event = build_layer3_comment_event(&keys, &parent_id, "Test comment", Kind::Custom(KIND_COMMENT)) 932 let event = build_layer3_comment_event(
941 .expect("Should create event"); 933 &keys,
934 &parent_id,
935 "Test comment",
936 Kind::Custom(KIND_COMMENT),
937 )
938 .expect("Should create event");
942 939
943 assert_eq!(event.kind.as_u16(), KIND_COMMENT); 940 assert_eq!(event.kind.as_u16(), KIND_COMMENT);
944 941
@@ -980,8 +977,7 @@ mod tests {
980 977
981 let has_e_tag = event.tags.iter().any(|tag| { 978 let has_e_tag = event.tags.iter().any(|tag| {
982 let slice = tag.as_slice(); 979 let slice = tag.as_slice();
983 slice.first().is_some_and(|t| t == "e") && 980 slice.first().is_some_and(|t| t == "e") && slice.get(3).is_some_and(|m| m == "root")
984 slice.get(3).is_some_and(|m| m == "root")
985 }); 981 });
986 assert!(has_e_tag, "Should have 'e' tag with root marker"); 982 assert!(has_e_tag, "Should have 'e' tag with root marker");
987 } 983 }
@@ -1038,7 +1034,10 @@ mod tests {
1038 fn test_parse_gauge_without_labels() { 1034 fn test_parse_gauge_without_labels() {
1039 let text = r#"ngit_sync_relays_tracked_total 3"#; 1035 let text = r#"ngit_sync_relays_tracked_total 3"#;
1040 let metrics = ParsedMetrics::parse(text); 1036 let metrics = ParsedMetrics::parse(text);
1041 assert_eq!(metrics.gauge("ngit_sync_relays_tracked_total", &[]), Some(3)); 1037 assert_eq!(
1038 metrics.gauge("ngit_sync_relays_tracked_total", &[]),
1039 Some(3)
1040 );
1042 } 1041 }
1043 1042
1044 #[test] 1043 #[test]
@@ -1051,9 +1050,6 @@ mod tests {
1051 fn test_parse_metric_with_relay_url_label() { 1050 fn test_parse_metric_with_relay_url_label() {
1052 let text = r#"ngit_sync_relay_connected{relay="ws://127.0.0.1:12345"} 1"#; 1051 let text = r#"ngit_sync_relay_connected{relay="ws://127.0.0.1:12345"} 1"#;
1053 let metrics = ParsedMetrics::parse(text); 1052 let metrics = ParsedMetrics::parse(text);
1054 assert_eq!( 1053 assert_eq!(metrics.relay_connected("ws://127.0.0.1:12345"), Some(true));
1055 metrics.relay_connected("ws://127.0.0.1:12345"),
1056 Some(true)
1057 );
1058 } 1054 }
1059} \ No newline at end of file 1055}
diff --git a/tests/nip77_negentropy.rs b/tests/nip77_negentropy.rs
index c8e0b50..5293754 100644
--- a/tests/nip77_negentropy.rs
+++ b/tests/nip77_negentropy.rs
@@ -45,13 +45,13 @@ async fn test_nip77_negentropy_sync_finds_events() {
45 let keys = Keys::generate(); 45 let keys = Keys::generate();
46 46
47 // Create a repository announcement that will be accepted by the relay 47 // Create a repository announcement that will be accepted by the relay
48 let announcement = create_repo_announcement( 48 let announcement = create_repo_announcement(&keys, &[&relay.domain()], "test-repo-nip77");
49 &keys,
50 &[&relay.domain()],
51 "test-repo-nip77",
52 );
53 let event1_id = announcement.id; 49 let event1_id = announcement.id;
54 println!("Created event 1: {} (kind {})", event1_id, announcement.kind.as_u16()); 50 println!(
51 "Created event 1: {} (kind {})",
52 event1_id,
53 announcement.kind.as_u16()
54 );
55 55
56 // Create a second event (issue referencing the repo) 56 // Create a second event (issue referencing the repo)
57 let repo_coord = format!( 57 let repo_coord = format!(
@@ -63,7 +63,11 @@ async fn test_nip77_negentropy_sync_finds_events() {
63 let issue = build_layer2_issue_event(&keys, &repo_coord, "Test issue for NIP-77") 63 let issue = build_layer2_issue_event(&keys, &repo_coord, "Test issue for NIP-77")
64 .expect("Failed to build issue event"); 64 .expect("Failed to build issue event");
65 let event2_id = issue.id; 65 let event2_id = issue.id;
66 println!("Created event 2: {} (kind {})", event2_id, issue.kind.as_u16()); 66 println!(
67 "Created event 2: {} (kind {})",
68 event2_id,
69 issue.kind.as_u16()
70 );
67 71
68 // 3. Send events to relay using TestClient 72 // 3. Send events to relay using TestClient
69 let publish_client = TestClient::new(relay.url(), keys.clone()) 73 let publish_client = TestClient::new(relay.url(), keys.clone())
@@ -99,9 +103,10 @@ async fn test_nip77_negentropy_sync_finds_events() {
99 tokio::time::sleep(Duration::from_millis(500)).await; 103 tokio::time::sleep(Duration::from_millis(500)).await;
100 104
101 // 6. Perform negentropy sync with filter matching our events 105 // 6. Perform negentropy sync with filter matching our events
102 let filter = Filter::new() 106 let filter = Filter::new().author(keys.public_key()).kinds(vec![
103 .author(keys.public_key()) 107 Kind::Custom(KIND_REPOSITORY_STATE),
104 .kinds(vec![Kind::Custom(KIND_REPOSITORY_STATE), Kind::Custom(KIND_ISSUE)]); 108 Kind::Custom(KIND_ISSUE),
109 ]);
105 110
106 println!("Starting negentropy sync with filter: {:?}", filter); 111 println!("Starting negentropy sync with filter: {:?}", filter);
107 112
@@ -177,7 +182,7 @@ async fn test_nip77_negentropy_sync_empty_result() {
177 182
178 // 3. Sync with filter that won't match anything 183 // 3. Sync with filter that won't match anything
179 let filter = Filter::new() 184 let filter = Filter::new()
180 .author(keys.public_key()) // Random new key, no events exist 185 .author(keys.public_key()) // Random new key, no events exist
181 .kind(Kind::Custom(KIND_REPOSITORY_STATE)); 186 .kind(Kind::Custom(KIND_REPOSITORY_STATE));
182 187
183 println!("Starting negentropy sync with empty filter"); 188 println!("Starting negentropy sync with empty filter");
diff --git a/tests/sync.rs b/tests/sync.rs
index 5b6b752..2e09fb8 100644
--- a/tests/sync.rs
+++ b/tests/sync.rs
@@ -37,4 +37,4 @@ mod sync {
37 pub mod live_sync; 37 pub mod live_sync;
38 pub mod metrics; 38 pub mod metrics;
39 pub mod tag_variations; 39 pub mod tag_variations;
40} \ No newline at end of file 40}
diff --git a/tests/sync/bootstrap.rs b/tests/sync/bootstrap.rs
index 8a181c9..174fe28 100644
--- a/tests/sync/bootstrap.rs
+++ b/tests/sync/bootstrap.rs
@@ -167,7 +167,8 @@ async fn test_relay_replays_events_after_restart() {
167 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 167 .kind(Kind::Custom(KIND_REPOSITORY_STATE))
168 .author(keys.public_key()); 168 .author(keys.public_key());
169 169
170 let synced_first = wait_for_event_on_relay(relay_b.url(), filter.clone(), Duration::from_secs(5)).await; 170 let synced_first =
171 wait_for_event_on_relay(relay_b.url(), filter.clone(), Duration::from_secs(5)).await;
171 println!("First sync check: {}", synced_first); 172 println!("First sync check: {}", synced_first);
172 173
173 // 8. Stop relay_b 174 // 8. Stop relay_b
@@ -193,7 +194,8 @@ async fn test_relay_replays_events_after_restart() {
193 // 12. Verify announcement is available on new relay_b 194 // 12. Verify announcement is available on new relay_b
194 // The announcement listed the OLD relay_b domain, but since relay_a still 195 // The announcement listed the OLD relay_b domain, but since relay_a still
195 // has the event, new relay_b should be able to sync it via bootstrap 196 // has the event, new relay_b should be able to sync it via bootstrap
196 let synced_after_restart = wait_for_event_on_relay(relay_b_new.url(), filter, Duration::from_secs(5)).await; 197 let synced_after_restart =
198 wait_for_event_on_relay(relay_b_new.url(), filter, Duration::from_secs(5)).await;
197 199
198 // 13. Cleanup 200 // 13. Cleanup
199 relay_b_new.stop().await; 201 relay_b_new.stop().await;
@@ -384,7 +386,8 @@ async fn test_history_sync_without_negentropy() {
384 relay_b_port, 386 relay_b_port,
385 Some(relay_a.url().into()), 387 Some(relay_a.url().into()),
386 true, // disable_negentropy = true 388 true, // disable_negentropy = true
387 ).await; 389 )
390 .await;
388 println!( 391 println!(
389 "relay_b started at {} (domain: {}) - negentropy DISABLED, will do HISTORY sync", 392 "relay_b started at {} (domain: {}) - negentropy DISABLED, will do HISTORY sync",
390 relay_b.url(), 393 relay_b.url(),
diff --git a/tests/sync/discovery.rs b/tests/sync/discovery.rs
index 9e27f9e..ed3e9bb 100644
--- a/tests/sync/discovery.rs
+++ b/tests/sync/discovery.rs
@@ -88,7 +88,8 @@ async fn test_discovers_layer3_via_layer2() {
88 ); 88 );
89 89
90 // 6. Create a patch event (Layer 2) that references the announcement 90 // 6. Create a patch event (Layer 2) that references the announcement
91 let patch = create_event_referencing_repo(&keys, &repo_coord, KIND_PATCH, "Test patch proposal"); 91 let patch =
92 create_event_referencing_repo(&keys, &repo_coord, KIND_PATCH, "Test patch proposal");
92 let patch_id = patch.id; 93 let patch_id = patch.id;
93 94
94 println!("Created patch {} (kind {})", patch_id, patch.kind.as_u16()); 95 println!("Created patch {} (kind {})", patch_id, patch.kind.as_u16());
@@ -252,7 +253,8 @@ async fn test_layer2_discovery_with_chain() {
252 let issue_filter = Filter::new() 253 let issue_filter = Filter::new()
253 .kind(Kind::Custom(KIND_ISSUE)) 254 .kind(Kind::Custom(KIND_ISSUE))
254 .author(keys.public_key()); 255 .author(keys.public_key());
255 let issue_synced = wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; 256 let issue_synced =
257 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
256 258
257 println!("Sync result:"); 259 println!("Sync result:");
258 println!(" Issue {} synced: {}", issue_id, issue_synced); 260 println!(" Issue {} synced: {}", issue_id, issue_synced);
@@ -296,7 +298,7 @@ async fn test_layer2_discovery_with_chain() {
296#[tokio::test] 298#[tokio::test]
297async fn test_recursive_relay_discovery_syncs_announcement() { 299async fn test_recursive_relay_discovery_syncs_announcement() {
298 // 1. Start all three relays 300 // 1. Start all three relays
299 301
300 // relay_b - will be the bootstrap relay, has announcement_x 302 // relay_b - will be the bootstrap relay, has announcement_x
301 let relay_b = TestRelay::start().await; 303 let relay_b = TestRelay::start().await;
302 println!( 304 println!(
@@ -344,7 +346,10 @@ async fn test_recursive_relay_discovery_syncs_announcement() {
344 "repo-y-ac-only", 346 "repo-y-ac-only",
345 ); 347 );
346 let announcement_y_id = announcement_y.id; 348 let announcement_y_id = announcement_y.id;
347 println!("Created announcement_y {} listing A+C only", announcement_y_id); 349 println!(
350 "Created announcement_y {} listing A+C only",
351 announcement_y_id
352 );
348 for tag in announcement_y.tags.iter() { 353 for tag in announcement_y.tags.iter() {
349 println!(" Tag: {:?}", tag.as_slice()); 354 println!(" Tag: {:?}", tag.as_slice());
350 } 355 }
@@ -425,4 +430,4 @@ async fn test_recursive_relay_discovery_syncs_announcement() {
425 "announcement_y {} should have synced from discovered relay_c to relay_a (recursive discovery)", 430 "announcement_y {} should have synced from discovered relay_c to relay_a (recursive discovery)",
426 announcement_y_id 431 announcement_y_id
427 ); 432 );
428} \ No newline at end of file 433}
diff --git a/tests/sync/live_sync.rs b/tests/sync/live_sync.rs
index ebe1c0b..7fa08a0 100644
--- a/tests/sync/live_sync.rs
+++ b/tests/sync/live_sync.rs
@@ -229,7 +229,10 @@ async fn test_live_sync_layer3_events() {
229 .send_event(&comment) 229 .send_event(&comment)
230 .await 230 .await
231 .expect("Failed to send comment"); 231 .expect("Failed to send comment");
232 println!("Layer 3 comment {} sent to relay_a BEFORE Layer 3 subscription established", comment_id); 232 println!(
233 "Layer 3 comment {} sent to relay_a BEFORE Layer 3 subscription established",
234 comment_id
235 );
233 236
234 // 6. Now wait for issue to sync to relay_b (this triggers Layer 3 filter creation) 237 // 6. Now wait for issue to sync to relay_b (this triggers Layer 3 filter creation)
235 tokio::time::sleep(Duration::from_secs(2)).await; 238 tokio::time::sleep(Duration::from_secs(2)).await;
@@ -394,7 +397,7 @@ async fn test_live_sync_event_ordering() {
394 client_a 397 client_a
395 .send_event(&issue) 398 .send_event(&issue)
396 .await 399 .await
397 .expect(&format!("Failed to send issue {}", i)); 400 .unwrap_or_else(|_| panic!("Failed to send issue {}", i));
398 401
399 // Delay between events to ensure different timestamps 402 // Delay between events to ensure different timestamps
400 tokio::time::sleep(Duration::from_millis(150)).await; 403 tokio::time::sleep(Duration::from_millis(150)).await;
diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs
index 26d379d..14e1dfd 100644
--- a/tests/sync/metrics.rs
+++ b/tests/sync/metrics.rs
@@ -32,7 +32,7 @@ async fn test_prometheus_format_valid() {
32 let relay = TestRelay::start().await; 32 let relay = TestRelay::start().await;
33 tokio::time::sleep(Duration::from_millis(500)).await; 33 tokio::time::sleep(Duration::from_millis(500)).await;
34 34
35 let metrics = fetch_metrics(&relay.url()) 35 let metrics = fetch_metrics(relay.url())
36 .await 36 .await
37 .expect("Failed to fetch metrics"); 37 .expect("Failed to fetch metrics");
38 38
@@ -67,7 +67,7 @@ async fn test_metrics_availability_during_sync() {
67 67
68 // Make multiple metrics requests while sync is active 68 // Make multiple metrics requests while sync is active
69 for i in 0..3 { 69 for i in 0..3 {
70 let metrics = fetch_metrics(&sync_relay.url()).await; 70 let metrics = fetch_metrics(sync_relay.url()).await;
71 assert!( 71 assert!(
72 metrics.is_ok(), 72 metrics.is_ok(),
73 "Metrics request {} should succeed during sync", 73 "Metrics request {} should succeed during sync",
@@ -135,7 +135,7 @@ async fn test_metric_values_are_numeric() {
135 let relay = TestRelay::start().await; 135 let relay = TestRelay::start().await;
136 tokio::time::sleep(Duration::from_millis(500)).await; 136 tokio::time::sleep(Duration::from_millis(500)).await;
137 137
138 let metrics = fetch_metrics(&relay.url()) 138 let metrics = fetch_metrics(relay.url())
139 .await 139 .await
140 .expect("Should fetch metrics"); 140 .expect("Should fetch metrics");
141 141
diff --git a/tests/sync/tag_variations.rs b/tests/sync/tag_variations.rs
index 273a573..41a6611 100644
--- a/tests/sync/tag_variations.rs
+++ b/tests/sync/tag_variations.rs
@@ -57,11 +57,8 @@ async fn test_layer2_sync_with_lowercase_a_tag() {
57 57
58 // 2. Create and send repository announcement to both relays 58 // 2. Create and send repository announcement to both relays
59 let repo_id = "test-repo-tag-8a"; 59 let repo_id = "test-repo-tag-8a";
60 let announcement = create_repo_announcement( 60 let announcement =
61 &keys, 61 create_repo_announcement(&keys, &[&relay_a.domain(), &relay_b.domain()], repo_id);
62 &[&relay_a.domain(), &relay_b.domain()],
63 repo_id,
64 );
65 62
66 let client_a = TestClient::new(relay_a.url(), keys.clone()) 63 let client_a = TestClient::new(relay_a.url(), keys.clone())
67 .await 64 .await
@@ -88,11 +85,16 @@ async fn test_layer2_sync_with_lowercase_a_tag() {
88 85
89 // 4. Create and send Layer 2 issue with lowercase 'a' tag 86 // 4. Create and send Layer 2 issue with lowercase 'a' tag
90 let repo_coordinate = repo_coord(&keys, repo_id); 87 let repo_coordinate = repo_coord(&keys, repo_id);
91 let issue = build_layer2_issue_event(&keys, &repo_coordinate, "Test Issue with lowercase a tag") 88 let issue =
92 .expect("Failed to create issue event"); 89 build_layer2_issue_event(&keys, &repo_coordinate, "Test Issue with lowercase a tag")
90 .expect("Failed to create issue event");
93 let issue_id = issue.id; 91 let issue_id = issue.id;
94 92
95 println!("Created issue {} (kind {}) with lowercase 'a' tag", issue_id, issue.kind.as_u16()); 93 println!(
94 "Created issue {} (kind {}) with lowercase 'a' tag",
95 issue_id,
96 issue.kind.as_u16()
97 );
96 for tag in issue.tags.iter() { 98 for tag in issue.tags.iter() {
97 println!(" Tag: {:?}", tag.as_slice()); 99 println!(" Tag: {:?}", tag.as_slice());
98 } 100 }
@@ -154,11 +156,8 @@ async fn test_layer2_sync_with_uppercase_a_tag() {
154 156
155 // 2. Create and send repository announcement to both relays 157 // 2. Create and send repository announcement to both relays
156 let repo_id = "test-repo-tag-8b"; 158 let repo_id = "test-repo-tag-8b";
157 let announcement = create_repo_announcement( 159 let announcement =
158 &keys, 160 create_repo_announcement(&keys, &[&relay_a.domain(), &relay_b.domain()], repo_id);
159 &[&relay_a.domain(), &relay_b.domain()],
160 repo_id,
161 );
162 161
163 let client_a = TestClient::new(relay_a.url(), keys.clone()) 162 let client_a = TestClient::new(relay_a.url(), keys.clone())
164 .await 163 .await
@@ -185,11 +184,19 @@ async fn test_layer2_sync_with_uppercase_a_tag() {
185 184
186 // 4. Create and send Layer 2 issue with uppercase 'A' tag 185 // 4. Create and send Layer 2 issue with uppercase 'A' tag
187 let repo_coordinate = repo_coord(&keys, repo_id); 186 let repo_coordinate = repo_coord(&keys, repo_id);
188 let issue = build_layer2_issue_with_uppercase_a_tag(&keys, &repo_coordinate, "Test Issue with uppercase A tag") 187 let issue = build_layer2_issue_with_uppercase_a_tag(
189 .expect("Failed to create issue event"); 188 &keys,
189 &repo_coordinate,
190 "Test Issue with uppercase A tag",
191 )
192 .expect("Failed to create issue event");
190 let issue_id = issue.id; 193 let issue_id = issue.id;
191 194
192 println!("Created issue {} (kind {}) with uppercase 'A' tag", issue_id, issue.kind.as_u16()); 195 println!(
196 "Created issue {} (kind {}) with uppercase 'A' tag",
197 issue_id,
198 issue.kind.as_u16()
199 );
193 for tag in issue.tags.iter() { 200 for tag in issue.tags.iter() {
194 println!(" Tag: {:?}", tag.as_slice()); 201 println!(" Tag: {:?}", tag.as_slice());
195 } 202 }
@@ -250,11 +257,8 @@ async fn test_layer2_sync_with_q_tag() {
250 257
251 // 2. Create and send repository announcement to both relays 258 // 2. Create and send repository announcement to both relays
252 let repo_id = "test-repo-tag-8c"; 259 let repo_id = "test-repo-tag-8c";
253 let announcement = create_repo_announcement( 260 let announcement =
254 &keys, 261 create_repo_announcement(&keys, &[&relay_a.domain(), &relay_b.domain()], repo_id);
255 &[&relay_a.domain(), &relay_b.domain()],
256 repo_id,
257 );
258 262
259 let client_a = TestClient::new(relay_a.url(), keys.clone()) 263 let client_a = TestClient::new(relay_a.url(), keys.clone())
260 .await 264 .await
@@ -285,7 +289,11 @@ async fn test_layer2_sync_with_q_tag() {
285 .expect("Failed to create issue event"); 289 .expect("Failed to create issue event");
286 let issue_id = issue.id; 290 let issue_id = issue.id;
287 291
288 println!("Created issue {} (kind {}) with 'q' tag", issue_id, issue.kind.as_u16()); 292 println!(
293 "Created issue {} (kind {}) with 'q' tag",
294 issue_id,
295 issue.kind.as_u16()
296 );
289 for tag in issue.tags.iter() { 297 for tag in issue.tags.iter() {
290 println!(" Tag: {:?}", tag.as_slice()); 298 println!(" Tag: {:?}", tag.as_slice());
291 } 299 }
@@ -350,11 +358,8 @@ async fn test_layer3_sync_with_lowercase_e_tag() {
350 358
351 // 2. Create and send repository announcement to both relays 359 // 2. Create and send repository announcement to both relays
352 let repo_id = "test-repo-tag-9a"; 360 let repo_id = "test-repo-tag-9a";
353 let announcement = create_repo_announcement( 361 let announcement =
354 &keys, 362 create_repo_announcement(&keys, &[&relay_a.domain(), &relay_b.domain()], repo_id);
355 &[&relay_a.domain(), &relay_b.domain()],
356 repo_id,
357 );
358 363
359 let client_a = TestClient::new(relay_a.url(), keys.clone()) 364 let client_a = TestClient::new(relay_a.url(), keys.clone())
360 .await 365 .await
@@ -392,10 +397,9 @@ async fn test_layer3_sync_with_lowercase_e_tag() {
392 println!("Layer 2 issue {} sent to relay_a", issue_id); 397 println!("Layer 2 issue {} sent to relay_a", issue_id);
393 398
394 // 5. Wait for issue to sync to relay_b 399 // 5. Wait for issue to sync to relay_b
395 let issue_filter = Filter::new() 400 let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id);
396 .kind(Kind::Custom(KIND_ISSUE)) 401 let issue_synced =
397 .id(issue_id); 402 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
398 let issue_synced = wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
399 println!("Issue synced to relay_b: {}", issue_synced); 403 println!("Issue synced to relay_b: {}", issue_synced);
400 assert!(issue_synced, "Layer 2 issue should sync first"); 404 assert!(issue_synced, "Layer 2 issue should sync first");
401 405
@@ -412,7 +416,11 @@ async fn test_layer3_sync_with_lowercase_e_tag() {
412 .expect("Failed to create reply"); 416 .expect("Failed to create reply");
413 let reply_id = reply.id; 417 let reply_id = reply.id;
414 418
415 println!("Created reply {} (kind {}) with lowercase 'e' tag", reply_id, reply.kind.as_u16()); 419 println!(
420 "Created reply {} (kind {}) with lowercase 'e' tag",
421 reply_id,
422 reply.kind.as_u16()
423 );
416 for tag in reply.tags.iter() { 424 for tag in reply.tags.iter() {
417 println!(" Tag: {:?}", tag.as_slice()); 425 println!(" Tag: {:?}", tag.as_slice());
418 } 426 }
@@ -428,11 +436,12 @@ async fn test_layer3_sync_with_lowercase_e_tag() {
428 436
429 // 7. Wait and verify reply syncs to relay_b 437 // 7. Wait and verify reply syncs to relay_b
430 let reply_filter = Filter::new() 438 let reply_filter = Filter::new()
431 .kind(Kind::TextNote) // Kind 1 439 .kind(Kind::TextNote) // Kind 1
432 .author(keys.public_key()) 440 .author(keys.public_key())
433 .id(reply_id); 441 .id(reply_id);
434 442
435 let reply_synced = wait_for_event_on_relay(relay_b.url(), reply_filter, Duration::from_secs(5)).await; 443 let reply_synced =
444 wait_for_event_on_relay(relay_b.url(), reply_filter, Duration::from_secs(5)).await;
436 445
437 println!("Reply {} synced to relay_b: {}", reply_id, reply_synced); 446 println!("Reply {} synced to relay_b: {}", reply_id, reply_synced);
438 447
@@ -473,11 +482,8 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
473 482
474 // 2. Create and send repository announcement to both relays 483 // 2. Create and send repository announcement to both relays
475 let repo_id = "test-repo-tag-9b"; 484 let repo_id = "test-repo-tag-9b";
476 let announcement = create_repo_announcement( 485 let announcement =
477 &keys, 486 create_repo_announcement(&keys, &[&relay_a.domain(), &relay_b.domain()], repo_id);
478 &[&relay_a.domain(), &relay_b.domain()],
479 repo_id,
480 );
481 487
482 let client_a = TestClient::new(relay_a.url(), keys.clone()) 488 let client_a = TestClient::new(relay_a.url(), keys.clone())
483 .await 489 .await
@@ -515,10 +521,9 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
515 println!("Layer 2 issue {} sent to relay_a", issue_id); 521 println!("Layer 2 issue {} sent to relay_a", issue_id);
516 522
517 // 5. Wait for issue to sync to relay_b 523 // 5. Wait for issue to sync to relay_b
518 let issue_filter = Filter::new() 524 let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id);
519 .kind(Kind::Custom(KIND_ISSUE)) 525 let issue_synced =
520 .id(issue_id); 526 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
521 let issue_synced = wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
522 println!("Issue synced to relay_b: {}", issue_synced); 527 println!("Issue synced to relay_b: {}", issue_synced);
523 assert!(issue_synced, "Layer 2 issue should sync first"); 528 assert!(issue_synced, "Layer 2 issue should sync first");
524 529
@@ -531,11 +536,16 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
531 tokio::time::sleep(Duration::from_millis(500)).await; 536 tokio::time::sleep(Duration::from_millis(500)).await;
532 537
533 // 6. Create and send Layer 3 comment with uppercase 'E' tag (kind 1111) 538 // 6. Create and send Layer 3 comment with uppercase 'E' tag (kind 1111)
534 let comment = build_layer3_comment_with_uppercase_e_tag(&keys, &issue_id, "Comment with uppercase E tag") 539 let comment =
535 .expect("Failed to create comment"); 540 build_layer3_comment_with_uppercase_e_tag(&keys, &issue_id, "Comment with uppercase E tag")
541 .expect("Failed to create comment");
536 let comment_id = comment.id; 542 let comment_id = comment.id;
537 543
538 println!("Created comment {} (kind {}) with uppercase 'E' tag", comment_id, comment.kind.as_u16()); 544 println!(
545 "Created comment {} (kind {}) with uppercase 'E' tag",
546 comment_id,
547 comment.kind.as_u16()
548 );
539 for tag in comment.tags.iter() { 549 for tag in comment.tags.iter() {
540 println!(" Tag: {:?}", tag.as_slice()); 550 println!(" Tag: {:?}", tag.as_slice());
541 } 551 }
@@ -551,13 +561,17 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
551 561
552 // 7. Wait and verify comment syncs to relay_b 562 // 7. Wait and verify comment syncs to relay_b
553 let comment_filter = Filter::new() 563 let comment_filter = Filter::new()
554 .kind(Kind::Custom(KIND_COMMENT)) // Kind 1111 564 .kind(Kind::Custom(KIND_COMMENT)) // Kind 1111
555 .author(keys.public_key()) 565 .author(keys.public_key())
556 .id(comment_id); 566 .id(comment_id);
557 567
558 let comment_synced = wait_for_event_on_relay(relay_b.url(), comment_filter, Duration::from_secs(5)).await; 568 let comment_synced =
569 wait_for_event_on_relay(relay_b.url(), comment_filter, Duration::from_secs(5)).await;
559 570
560 println!("Comment {} synced to relay_b: {}", comment_id, comment_synced); 571 println!(
572 "Comment {} synced to relay_b: {}",
573 comment_id, comment_synced
574 );
561 575
562 // 8. Cleanup 576 // 8. Cleanup
563 relay_b.stop().await; 577 relay_b.stop().await;
@@ -596,11 +610,8 @@ async fn test_layer3_sync_with_q_tag() {
596 610
597 // 2. Create and send repository announcement to both relays 611 // 2. Create and send repository announcement to both relays
598 let repo_id = "test-repo-tag-9c"; 612 let repo_id = "test-repo-tag-9c";
599 let announcement = create_repo_announcement( 613 let announcement =
600 &keys, 614 create_repo_announcement(&keys, &[&relay_a.domain(), &relay_b.domain()], repo_id);
601 &[&relay_a.domain(), &relay_b.domain()],
602 repo_id,
603 );
604 615
605 let client_a = TestClient::new(relay_a.url(), keys.clone()) 616 let client_a = TestClient::new(relay_a.url(), keys.clone())
606 .await 617 .await
@@ -638,10 +649,9 @@ async fn test_layer3_sync_with_q_tag() {
638 println!("Layer 2 issue {} sent to relay_a", issue_id); 649 println!("Layer 2 issue {} sent to relay_a", issue_id);
639 650
640 // 5. Wait for issue to sync to relay_b 651 // 5. Wait for issue to sync to relay_b
641 let issue_filter = Filter::new() 652 let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id);
642 .kind(Kind::Custom(KIND_ISSUE)) 653 let issue_synced =
643 .id(issue_id); 654 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
644 let issue_synced = wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
645 println!("Issue synced to relay_b: {}", issue_synced); 655 println!("Issue synced to relay_b: {}", issue_synced);
646 assert!(issue_synced, "Layer 2 issue should sync first"); 656 assert!(issue_synced, "Layer 2 issue should sync first");
647 657
@@ -658,7 +668,11 @@ async fn test_layer3_sync_with_q_tag() {
658 .expect("Failed to create quote"); 668 .expect("Failed to create quote");
659 let quote_id = quote.id; 669 let quote_id = quote.id;
660 670
661 println!("Created quote {} (kind {}) with 'q' tag", quote_id, quote.kind.as_u16()); 671 println!(
672 "Created quote {} (kind {}) with 'q' tag",
673 quote_id,
674 quote.kind.as_u16()
675 );
662 for tag in quote.tags.iter() { 676 for tag in quote.tags.iter() {
663 println!(" Tag: {:?}", tag.as_slice()); 677 println!(" Tag: {:?}", tag.as_slice());
664 } 678 }
@@ -674,11 +688,12 @@ async fn test_layer3_sync_with_q_tag() {
674 688
675 // 7. Wait and verify quote syncs to relay_b 689 // 7. Wait and verify quote syncs to relay_b
676 let quote_filter = Filter::new() 690 let quote_filter = Filter::new()
677 .kind(Kind::TextNote) // Kind 1 691 .kind(Kind::TextNote) // Kind 1
678 .author(keys.public_key()) 692 .author(keys.public_key())
679 .id(quote_id); 693 .id(quote_id);
680 694
681 let quote_synced = wait_for_event_on_relay(relay_b.url(), quote_filter, Duration::from_secs(5)).await; 695 let quote_synced =
696 wait_for_event_on_relay(relay_b.url(), quote_filter, Duration::from_secs(5)).await;
682 697
683 println!("Quote {} synced to relay_b: {}", quote_id, quote_synced); 698 println!("Quote {} synced to relay_b: {}", quote_id, quote_synced);
684 699
@@ -690,4 +705,4 @@ async fn test_layer3_sync_with_q_tag() {
690 quote_synced, 705 quote_synced,
691 "Layer 3 quote with 'q' tag should have synced to relay_b" 706 "Layer 3 quote with 'q' tag should have synced to relay_b"
692 ); 707 );
693} \ No newline at end of file 708}