upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/sync/discovery.rs
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/discovery.rs
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/discovery.rs')
-rw-r--r--tests/sync/discovery.rs28
1 files changed, 14 insertions, 14 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 =