upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/sync
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-08 11:20:35 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-08 11:23:28 +0000
commit5d02ad6b893f9059044914c115d77cf9d8e589c3 (patch)
treeb727f9c44d2f2d4e203dc2344e4c9bd5144a77dd /tests/sync
parent075307804bf66bba10f5bc55cb40e2e6a98a65ee (diff)
refactor: replace hardcoded Kind constants with rust-nostr variants
- Replace KIND_REPOSITORY_ANNOUNCEMENT with Kind::GitRepoAnnouncement - Replace KIND_REPOSITORY_STATE with Kind::RepoState - Replace KIND_PR with Kind::GitPullRequest - Replace KIND_PR_UPDATE with Kind::GitPullRequestUpdate - Replace KIND_USER_GRASP_LIST with Kind::GitUserGraspList - Replace KIND_PATCH with Kind::GitPatch - Replace KIND_ISSUE with Kind::GitIssue - Replace KIND_COMMENT with Kind::Comment - Replace all Kind::Custom(30617|30618|1617|1618|1619|1621|1111|10317) patterns - Remove all hardcoded KIND_* constants from events.rs - Update all match statements to use Kind enum directly - Update all filter builders to use Kind variants - Update all test helpers and assertions Benefits: - Type safety: compiler prevents wrong kind numbers - Readability: Kind::GitRepoAnnouncement is self-documenting - Maintainability: single source of truth (rust-nostr) - IDE support: full autocompletion and refactoring - Standards: aligns with rust-nostr best practices Files modified: 21 Constants removed: 9 Patterns replaced: 100+ Tests passing: 222/222
Diffstat (limited to 'tests/sync')
-rw-r--r--tests/sync/discovery.rs28
-rw-r--r--tests/sync/historic_sync.rs16
-rw-r--r--tests/sync/live_sync.rs14
-rw-r--r--tests/sync/metrics.rs14
-rw-r--r--tests/sync/tag_variations.rs14
5 files changed, 40 insertions, 46 deletions
diff --git a/tests/sync/discovery.rs b/tests/sync/discovery.rs
index 3aa6dda..8ed80b5 100644
--- a/tests/sync/discovery.rs
+++ b/tests/sync/discovery.rs
@@ -14,8 +14,8 @@ use nostr_sdk::prelude::*;
14 14
15use crate::common::{sync_helpers::*, TestRelay}; 15use crate::common::{sync_helpers::*, TestRelay};
16 16
17/// Kind 1617 - Patch event (NIP-34) 17// NOTE: Using rust-nostr Kind variant:
18const KIND_PATCH: u16 = 1617; 18// - Kind::GitPatch.as_u16() -> Kind::GitPatch (1617)
19 19
20/// Create an event referencing a repository coordinate via 'a' tag. 20/// Create an event referencing a repository coordinate via 'a' tag.
21/// 21///
@@ -26,7 +26,7 @@ fn create_event_referencing_repo(keys: &Keys, repo_coord: &str, kind: u16, conte
26 vec![repo_coord.to_string()], 26 vec![repo_coord.to_string()],
27 )]; 27 )];
28 28
29 EventBuilder::new(Kind::Custom(kind), content) 29 EventBuilder::new(Kind::from_u16(kind), content)
30 .tags(tags) 30 .tags(tags)
31 .sign_with_keys(keys) 31 .sign_with_keys(keys)
32 .expect("Failed to sign event") 32 .expect("Failed to sign event")
@@ -82,14 +82,18 @@ async fn test_discovers_layer3_via_layer2() {
82 // 5. Build the repo coordinate for the 'a' tag in the patch 82 // 5. Build the repo coordinate for the 'a' tag in the patch
83 let repo_coord = format!( 83 let repo_coord = format!(
84 "{}:{}:{}", 84 "{}:{}:{}",
85 KIND_REPOSITORY_STATE, 85 Kind::GitRepoAnnouncement.as_u16(),
86 keys.public_key().to_hex(), 86 keys.public_key().to_hex(),
87 "test-repo-discovery" 87 "test-repo-discovery"
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 = 91 let patch = create_event_referencing_repo(
92 create_event_referencing_repo(&keys, &repo_coord, KIND_PATCH, "Test patch proposal"); 92 &keys,
93 &repo_coord,
94 Kind::GitPatch.as_u16(),
95 "Test patch proposal",
96 );
93 let patch_id = patch.id; 97 let patch_id = patch.id;
94 98
95 println!("Created patch {} (kind {})", patch_id, patch.kind.as_u16()); 99 println!("Created patch {} (kind {})", patch_id, patch.kind.as_u16());
@@ -134,9 +138,7 @@ async fn test_discovers_layer3_via_layer2() {
134 tokio::time::sleep(Duration::from_secs(3)).await; 138 tokio::time::sleep(Duration::from_secs(3)).await;
135 139
136 // 10. Verify patch was synced to relay_b 140 // 10. Verify patch was synced to relay_b
137 let filter = Filter::new() 141 let filter = Filter::new().kind(Kind::GitPatch).author(keys.public_key());
138 .kind(Kind::Custom(KIND_PATCH))
139 .author(keys.public_key());
140 142
141 let patch_synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(5)).await; 143 let patch_synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(5)).await;
142 144
@@ -250,9 +252,7 @@ async fn test_relay_discovery_via_announcements_with_historic_sync() {
250 tokio::time::sleep(Duration::from_secs(3)).await; 252 tokio::time::sleep(Duration::from_secs(3)).await;
251 253
252 // 8. Verify Layer 2 event synced to relay_b 254 // 8. Verify Layer 2 event synced to relay_b
253 let issue_filter = Filter::new() 255 let issue_filter = Filter::new().kind(Kind::GitIssue).author(keys.public_key());
254 .kind(Kind::Custom(KIND_ISSUE))
255 .author(keys.public_key());
256 let issue_synced = 256 let issue_synced =
257 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; 257 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
258 258
@@ -389,7 +389,7 @@ async fn test_recursive_relay_discovery_via_announcements_with_historic_sync() {
389 389
390 // 8. Verify announcement_x was synced to relay_a (from bootstrap relay_b) 390 // 8. Verify announcement_x was synced to relay_a (from bootstrap relay_b)
391 let filter_x = Filter::new() 391 let filter_x = Filter::new()
392 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 392 .kind(Kind::GitRepoAnnouncement)
393 .author(keys_x.public_key()); 393 .author(keys_x.public_key());
394 394
395 let announcement_x_synced = 395 let announcement_x_synced =
@@ -402,7 +402,7 @@ async fn test_recursive_relay_discovery_via_announcements_with_historic_sync() {
402 402
403 // 9. Verify announcement_y was synced to relay_a (from discovered relay_c) 403 // 9. Verify announcement_y was synced to relay_a (from discovered relay_c)
404 let filter_y = Filter::new() 404 let filter_y = Filter::new()
405 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 405 .kind(Kind::GitRepoAnnouncement)
406 .author(keys_y.public_key()); 406 .author(keys_y.public_key());
407 407
408 let announcement_y_synced = 408 let announcement_y_synced =
diff --git a/tests/sync/historic_sync.rs b/tests/sync/historic_sync.rs
index c388a7f..aec2819 100644
--- a/tests/sync/historic_sync.rs
+++ b/tests/sync/historic_sync.rs
@@ -29,7 +29,7 @@ async fn test_bootstrap_syncs_existing_layer2_events() {
29 29
30 // Verify announcement synced to syncing relay 30 // Verify announcement synced to syncing relay
31 let filter = Filter::new() 31 let filter = Filter::new()
32 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 32 .kind(Kind::GitRepoAnnouncement)
33 .author(result.maintainer_keys.public_key()); 33 .author(result.maintainer_keys.public_key());
34 34
35 let synced = 35 let synced =
@@ -64,7 +64,7 @@ async fn test_relay_replays_events_after_restart() {
64 64
65 // Verify announcement synced on first run 65 // Verify announcement synced on first run
66 let filter = Filter::new() 66 let filter = Filter::new()
67 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 67 .kind(Kind::GitRepoAnnouncement)
68 .author(result.maintainer_keys.public_key()); 68 .author(result.maintainer_keys.public_key());
69 69
70 let synced_first = wait_for_event_on_relay( 70 let synced_first = wait_for_event_on_relay(
@@ -173,7 +173,7 @@ async fn test_announcement_not_listing_relay_is_not_synced() {
173 173
174 // Verify announcement did NOT sync to syncing relay 174 // Verify announcement did NOT sync to syncing relay
175 let filter = Filter::new() 175 let filter = Filter::new()
176 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 176 .kind(Kind::GitRepoAnnouncement)
177 .author(keys.public_key()); 177 .author(keys.public_key());
178 178
179 let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(2)).await; 179 let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(2)).await;
@@ -274,7 +274,7 @@ async fn test_history_sync_without_negentropy() {
274 274
275 // Verify announcement synced to syncing relay via HISTORY sync 275 // Verify announcement synced to syncing relay via HISTORY sync
276 let filter = Filter::new() 276 let filter = Filter::new()
277 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 277 .kind(Kind::GitRepoAnnouncement)
278 .author(keys.public_key()); 278 .author(keys.public_key());
279 279
280 let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(5)).await; 280 let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(5)).await;
@@ -339,7 +339,7 @@ async fn test_pagination_for_large_historic_sync() {
339 // Create 40 issue events to test pagination (with limit=10, threshold=7) 339 // Create 40 issue events to test pagination (with limit=10, threshold=7)
340 let repo_coord = format!( 340 let repo_coord = format!(
341 "{}:{}:{}", 341 "{}:{}:{}",
342 KIND_REPOSITORY_STATE, 342 Kind::GitRepoAnnouncement.as_u16(),
343 keys.public_key().to_hex(), 343 keys.public_key().to_hex(),
344 repo_id 344 repo_id
345 ); 345 );
@@ -416,16 +416,14 @@ async fn test_pagination_for_large_historic_sync() {
416 416
417 // Verify announcement synced 417 // Verify announcement synced
418 let announcement_filter = Filter::new() 418 let announcement_filter = Filter::new()
419 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 419 .kind(Kind::GitRepoAnnouncement)
420 .author(keys.public_key()); 420 .author(keys.public_key());
421 421
422 let announcement_synced = 422 let announcement_synced =
423 wait_for_event_on_relay(syncing.url(), announcement_filter, Duration::from_secs(3)).await; 423 wait_for_event_on_relay(syncing.url(), announcement_filter, Duration::from_secs(3)).await;
424 424
425 // Verify ALL 40 issues synced 425 // Verify ALL 40 issues synced
426 let issues_filter = Filter::new() 426 let issues_filter = Filter::new().kind(Kind::GitIssue).author(keys.public_key());
427 .kind(Kind::Custom(KIND_ISSUE))
428 .author(keys.public_key());
429 427
430 // Query for all issues 428 // Query for all issues
431 let temp_keys = Keys::generate(); 429 let temp_keys = Keys::generate();
diff --git a/tests/sync/live_sync.rs b/tests/sync/live_sync.rs
index 7fa08a0..8ee3119 100644
--- a/tests/sync/live_sync.rs
+++ b/tests/sync/live_sync.rs
@@ -115,7 +115,7 @@ async fn test_live_sync_layer2_events() {
115 115
116 // 9. Wait and verify event syncs to relay_b 116 // 9. Wait and verify event syncs to relay_b
117 let filter = Filter::new() 117 let filter = Filter::new()
118 .kind(Kind::Custom(KIND_ISSUE)) 118 .kind(Kind::GitIssue)
119 .author(keys.public_key()) 119 .author(keys.public_key())
120 .id(issue_id); 120 .id(issue_id);
121 121
@@ -237,7 +237,7 @@ async fn test_live_sync_layer3_events() {
237 // 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)
238 tokio::time::sleep(Duration::from_secs(2)).await; 238 tokio::time::sleep(Duration::from_secs(2)).await;
239 239
240 let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); 240 let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id);
241 let issue_synced = 241 let issue_synced =
242 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(3)).await; 242 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(3)).await;
243 println!("Issue synced to relay_b: {}", issue_synced); 243 println!("Issue synced to relay_b: {}", issue_synced);
@@ -247,7 +247,7 @@ async fn test_live_sync_layer3_events() {
247 247
248 // 7. Wait and verify comment syncs to relay_b 248 // 7. Wait and verify comment syncs to relay_b
249 let comment_filter = Filter::new() 249 let comment_filter = Filter::new()
250 .kind(Kind::Custom(KIND_COMMENT)) 250 .kind(Kind::Comment)
251 .author(keys.public_key()) 251 .author(keys.public_key())
252 .id(comment_id); 252 .id(comment_id);
253 253
@@ -267,9 +267,7 @@ async fn test_live_sync_layer3_events() {
267 client.connect().await; 267 client.connect().await;
268 tokio::time::sleep(Duration::from_millis(500)).await; 268 tokio::time::sleep(Duration::from_millis(500)).await;
269 269
270 let fetch_filter = Filter::new() 270 let fetch_filter = Filter::new().kind(Kind::Comment).id(comment_id);
271 .kind(Kind::Custom(KIND_COMMENT))
272 .id(comment_id);
273 271
274 if let Ok(events) = client 272 if let Ok(events) = client
275 .fetch_events(fetch_filter, Duration::from_secs(2)) 273 .fetch_events(fetch_filter, Duration::from_secs(2))
@@ -418,9 +416,7 @@ async fn test_live_sync_event_ordering() {
418 client.connect().await; 416 client.connect().await;
419 tokio::time::sleep(Duration::from_millis(500)).await; 417 tokio::time::sleep(Duration::from_millis(500)).await;
420 418
421 let filter = Filter::new() 419 let filter = Filter::new().kind(Kind::GitIssue).author(keys.public_key());
422 .kind(Kind::Custom(KIND_ISSUE))
423 .author(keys.public_key());
424 420
425 match client.fetch_events(filter, Duration::from_secs(3)).await { 421 match client.fetch_events(filter, Duration::from_secs(3)).await {
426 Ok(events) => { 422 Ok(events) => {
diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs
index 987b83a..e8c75c7 100644
--- a/tests/sync/metrics.rs
+++ b/tests/sync/metrics.rs
@@ -17,7 +17,7 @@ use nostr_sdk::prelude::*;
17use crate::common::{ 17use crate::common::{
18 sync_helpers::{ 18 sync_helpers::{
19 create_repo_announcement, fetch_metrics, wait_for_sync_connection, MetricsTestHarness, 19 create_repo_announcement, fetch_metrics, wait_for_sync_connection, MetricsTestHarness,
20 ParsedMetrics, TestClient, KIND_REPOSITORY_STATE, 20 ParsedMetrics, TestClient,
21 }, 21 },
22 TestRelay, 22 TestRelay,
23}; 23};
@@ -175,8 +175,8 @@ async fn test_metric_values_are_numeric() {
175// Phase 2: Real Metrics Tests (Using MetricsTestHarness) 175// Phase 2: Real Metrics Tests (Using MetricsTestHarness)
176// ============================================================================ 176// ============================================================================
177 177
178/// Kind 1617 - Patch event (NIP-34) 178// NOTE: Using rust-nostr Kind variant:
179const KIND_PATCH: u16 = 1617; 179// - Kind::GitPatch.as_u16() -> Kind::GitPatch (1617)
180 180
181/// Create an event referencing a repository coordinate via 'a' tag. 181/// Create an event referencing a repository coordinate via 'a' tag.
182/// 182///
@@ -187,7 +187,7 @@ fn create_event_referencing_repo(keys: &Keys, repo_coord: &str, kind: u16, conte
187 vec![repo_coord.to_string()], 187 vec![repo_coord.to_string()],
188 )]; 188 )];
189 189
190 EventBuilder::new(Kind::Custom(kind), content) 190 EventBuilder::new(Kind::from_u16(kind), content)
191 .tags(tags) 191 .tags(tags)
192 .sign_with_keys(keys) 192 .sign_with_keys(keys)
193 .expect("Failed to sign event") 193 .expect("Failed to sign event")
@@ -239,7 +239,7 @@ async fn test_startup_sync_event_count() {
239 // 5. Build the repo coordinate for the 'a' tag in the patches 239 // 5. Build the repo coordinate for the 'a' tag in the patches
240 let repo_coord = format!( 240 let repo_coord = format!(
241 "{}:{}:{}", 241 "{}:{}:{}",
242 KIND_REPOSITORY_STATE, 242 Kind::GitRepoAnnouncement.as_u16(),
243 keys.public_key().to_hex(), 243 keys.public_key().to_hex(),
244 "test-repo-metrics" 244 "test-repo-metrics"
245 ); 245 );
@@ -250,7 +250,7 @@ async fn test_startup_sync_event_count() {
250 create_event_referencing_repo( 250 create_event_referencing_repo(
251 &keys, 251 &keys,
252 &repo_coord, 252 &repo_coord,
253 KIND_PATCH, 253 Kind::GitPatch.as_u16(),
254 &format!("Test patch {}", i), 254 &format!("Test patch {}", i),
255 ) 255 )
256 }) 256 })
@@ -320,7 +320,7 @@ async fn test_startup_sync_event_count() {
320 320
321 // 12. Verify patches actually synced (functional check) 321 // 12. Verify patches actually synced (functional check)
322 let filter = Filter::new() 322 let filter = Filter::new()
323 .kind(Kind::Custom(KIND_PATCH)) 323 .kind(Kind::Custom(Kind::GitPatch.as_u16()))
324 .author(keys.public_key()); 324 .author(keys.public_key());
325 325
326 let patches_synced = crate::common::sync_helpers::wait_for_event_on_relay( 326 let patches_synced = crate::common::sync_helpers::wait_for_event_on_relay(
diff --git a/tests/sync/tag_variations.rs b/tests/sync/tag_variations.rs
index 7153104..46b1203 100644
--- a/tests/sync/tag_variations.rs
+++ b/tests/sync/tag_variations.rs
@@ -110,7 +110,7 @@ async fn test_layer2_sync_with_lowercase_a_tag() {
110 110
111 // 5. Wait and verify event syncs to relay_b 111 // 5. Wait and verify event syncs to relay_b
112 let filter = Filter::new() 112 let filter = Filter::new()
113 .kind(Kind::Custom(KIND_ISSUE)) 113 .kind(Kind::GitIssue)
114 .author(keys.public_key()) 114 .author(keys.public_key())
115 .id(issue_id); 115 .id(issue_id);
116 116
@@ -212,7 +212,7 @@ async fn test_layer2_sync_with_uppercase_a_tag() {
212 212
213 // 5. Wait and verify event syncs to relay_b 213 // 5. Wait and verify event syncs to relay_b
214 let filter = Filter::new() 214 let filter = Filter::new()
215 .kind(Kind::Custom(KIND_ISSUE)) 215 .kind(Kind::GitIssue)
216 .author(keys.public_key()) 216 .author(keys.public_key())
217 .id(issue_id); 217 .id(issue_id);
218 218
@@ -309,7 +309,7 @@ async fn test_layer2_sync_with_q_tag() {
309 309
310 // 5. Wait and verify event syncs to relay_b 310 // 5. Wait and verify event syncs to relay_b
311 let filter = Filter::new() 311 let filter = Filter::new()
312 .kind(Kind::Custom(KIND_ISSUE)) 312 .kind(Kind::GitIssue)
313 .author(keys.public_key()) 313 .author(keys.public_key())
314 .id(issue_id); 314 .id(issue_id);
315 315
@@ -403,7 +403,7 @@ async fn test_layer3_sync_with_lowercase_e_tag() {
403 println!("Layer 2 issue {} sent to relay_a", issue_id); 403 println!("Layer 2 issue {} sent to relay_a", issue_id);
404 404
405 // 5. Wait for issue to sync to relay_b 405 // 5. Wait for issue to sync to relay_b
406 let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); 406 let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id);
407 let issue_synced = 407 let issue_synced =
408 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; 408 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
409 println!("Issue synced to relay_b: {}", issue_synced); 409 println!("Issue synced to relay_b: {}", issue_synced);
@@ -527,7 +527,7 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
527 println!("Layer 2 issue {} sent to relay_a", issue_id); 527 println!("Layer 2 issue {} sent to relay_a", issue_id);
528 528
529 // 5. Wait for issue to sync to relay_b 529 // 5. Wait for issue to sync to relay_b
530 let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); 530 let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id);
531 let issue_synced = 531 let issue_synced =
532 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; 532 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
533 println!("Issue synced to relay_b: {}", issue_synced); 533 println!("Issue synced to relay_b: {}", issue_synced);
@@ -567,7 +567,7 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
567 567
568 // 7. Wait and verify comment syncs to relay_b 568 // 7. Wait and verify comment syncs to relay_b
569 let comment_filter = Filter::new() 569 let comment_filter = Filter::new()
570 .kind(Kind::Custom(KIND_COMMENT)) // Kind 1111 570 .kind(Kind::Comment) // Kind 1111
571 .author(keys.public_key()) 571 .author(keys.public_key())
572 .id(comment_id); 572 .id(comment_id);
573 573
@@ -655,7 +655,7 @@ async fn test_layer3_sync_with_q_tag() {
655 println!("Layer 2 issue {} sent to relay_a", issue_id); 655 println!("Layer 2 issue {} sent to relay_a", issue_id);
656 656
657 // 5. Wait for issue to sync to relay_b 657 // 5. Wait for issue to sync to relay_b
658 let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); 658 let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id);
659 let issue_synced = 659 let issue_synced =
660 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; 660 wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await;
661 println!("Issue synced to relay_b: {}", issue_synced); 661 println!("Issue synced to relay_b: {}", issue_synced);