From cbed48d5a20b646a5bcc23e907d6163a3a8d36c5 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 10 Dec 2025 16:59:09 +0000 Subject: refactor(tests): extract shared create_repo_announcement helper --- tests/sync/bootstrap.rs | 33 --------------------------------- tests/sync/catchup.rs | 33 --------------------------------- tests/sync/discovery.rs | 23 ----------------------- tests/sync/live_sync.rs | 33 --------------------------------- tests/sync/tag_variations.rs | 33 --------------------------------- 5 files changed, 155 deletions(-) (limited to 'tests/sync') diff --git a/tests/sync/bootstrap.rs b/tests/sync/bootstrap.rs index 4428721..62a8fa5 100644 --- a/tests/sync/bootstrap.rs +++ b/tests/sync/bootstrap.rs @@ -14,39 +14,6 @@ use nostr_sdk::prelude::*; use crate::common::{sync_helpers::*, TestRelay}; -/// Create a valid repository announcement event for testing sync. -/// -/// This creates a kind 30617 event with required clone and relays tags. -/// The event lists all provided domains so it will be accepted by each -/// relay's write policy. -/// -/// # Arguments -/// * `keys` - Keys for signing -/// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") -/// * `identifier` - Repository identifier (d-tag) -fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { - // Build clone URLs for all domains (with .git suffix) - let clone_urls: Vec = domains - .iter() - .map(|d| format!("http://{}/{}.git", d, identifier)) - .collect(); - - // Build relay URLs for all domains - let relay_urls: Vec = domains.iter().map(|d| format!("ws://{}", d)).collect(); - - // Build tags for repository announcement - let tags = vec![ - Tag::identifier(identifier), - Tag::custom(TagKind::custom("clone"), clone_urls), - Tag::custom(TagKind::custom("relays"), relay_urls), - ]; - - EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") - .tags(tags) - .sign_with_keys(keys) - .expect("Failed to sign repo announcement") -} - /// Test 1: Bootstrap sync - relay syncs existing events from bootstrap relay on startup /// /// Scenario: diff --git a/tests/sync/catchup.rs b/tests/sync/catchup.rs index 2d0af16..1ddafd1 100644 --- a/tests/sync/catchup.rs +++ b/tests/sync/catchup.rs @@ -35,39 +35,6 @@ use nostr_sdk::prelude::*; use crate::common::{sync_helpers::*, TestRelay}; -/// Create a valid repository announcement event for testing sync. -/// -/// This creates a kind 30617 event with required clone and relays tags. -/// The event lists all provided domains so it will be accepted by each -/// relay's write policy. -/// -/// # Arguments -/// * `keys` - Keys for signing -/// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") -/// * `identifier` - Repository identifier (d-tag) -fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { - // Build clone URLs for all domains (with .git suffix) - let clone_urls: Vec = domains - .iter() - .map(|d| format!("http://{}/{}.git", d, identifier)) - .collect(); - - // Build relay URLs for all domains - let relay_urls: Vec = domains.iter().map(|d| format!("ws://{}", d)).collect(); - - // Build tags for repository announcement - let tags = vec![ - Tag::identifier(identifier), - Tag::custom(TagKind::custom("clone"), clone_urls), - Tag::custom(TagKind::custom("relays"), relay_urls), - ]; - - EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") - .tags(tags) - .sign_with_keys(keys) - .expect("Failed to sign repo announcement") -} - /// Test that relay performs catchup sync after being offline /// /// # Scenario diff --git a/tests/sync/discovery.rs b/tests/sync/discovery.rs index 5a39a8b..ec40802 100644 --- a/tests/sync/discovery.rs +++ b/tests/sync/discovery.rs @@ -17,29 +17,6 @@ use crate::common::{sync_helpers::*, TestRelay}; /// Kind 1617 - Patch event (NIP-34) const KIND_PATCH: u16 = 1617; -/// Create a valid repository announcement event for testing sync. -/// -/// This creates a kind 30617 event with required clone and relays tags. -fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { - let clone_urls: Vec = domains - .iter() - .map(|d| format!("http://{}/{}.git", d, identifier)) - .collect(); - - let relay_urls: Vec = domains.iter().map(|d| format!("ws://{}", d)).collect(); - - let tags = vec![ - Tag::identifier(identifier), - Tag::custom(TagKind::custom("clone"), clone_urls), - Tag::custom(TagKind::custom("relays"), relay_urls), - ]; - - EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") - .tags(tags) - .sign_with_keys(keys) - .expect("Failed to sign repo announcement") -} - /// Create an event referencing a repository coordinate via 'a' tag. /// /// Used to create Layer 2 events like patches that reference a repository. diff --git a/tests/sync/live_sync.rs b/tests/sync/live_sync.rs index 3432687..9342cde 100644 --- a/tests/sync/live_sync.rs +++ b/tests/sync/live_sync.rs @@ -24,39 +24,6 @@ use nostr_sdk::prelude::*; use crate::common::{sync_helpers::*, TestRelay}; -/// Create a valid repository announcement event for testing sync. -/// -/// This creates a kind 30617 event with required clone and relays tags. -/// The event lists all provided domains so it will be accepted by each -/// relay's write policy. -/// -/// # Arguments -/// * `keys` - Keys for signing -/// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") -/// * `identifier` - Repository identifier (d-tag) -fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { - // Build clone URLs for all domains (with .git suffix) - let clone_urls: Vec = domains - .iter() - .map(|d| format!("http://{}/{}.git", d, identifier)) - .collect(); - - // Build relay URLs for all domains - let relay_urls: Vec = domains.iter().map(|d| format!("ws://{}", d)).collect(); - - // Build tags for repository announcement - let tags = vec![ - Tag::identifier(identifier), - Tag::custom(TagKind::custom("clone"), clone_urls), - Tag::custom(TagKind::custom("relays"), relay_urls), - ]; - - EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") - .tags(tags) - .sign_with_keys(keys) - .expect("Failed to sign repo announcement") -} - /// Test 5: Live sync Layer 2 events /// /// Verifies that Layer 2 events (kind 1618 issues) published to one relay diff --git a/tests/sync/tag_variations.rs b/tests/sync/tag_variations.rs index 3b36e68..a92fdbf 100644 --- a/tests/sync/tag_variations.rs +++ b/tests/sync/tag_variations.rs @@ -25,39 +25,6 @@ use nostr_sdk::prelude::*; use crate::common::{sync_helpers::*, TestRelay}; -/// Create a valid repository announcement event for testing sync. -/// -/// This creates a kind 30617 event with required clone and relays tags. -/// The event lists all provided domains so it will be accepted by each -/// relay's write policy. -/// -/// # Arguments -/// * `keys` - Keys for signing -/// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") -/// * `identifier` - Repository identifier (d-tag) -fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { - // Build clone URLs for all domains (with .git suffix) - let clone_urls: Vec = domains - .iter() - .map(|d| format!("http://{}/{}.git", d, identifier)) - .collect(); - - // Build relay URLs for all domains - let relay_urls: Vec = domains.iter().map(|d| format!("ws://{}", d)).collect(); - - // Build tags for repository announcement - let tags = vec![ - Tag::identifier(identifier), - Tag::custom(TagKind::custom("clone"), clone_urls), - Tag::custom(TagKind::custom("relays"), relay_urls), - ]; - - EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") - .tags(tags) - .sign_with_keys(keys) - .expect("Failed to sign repo announcement") -} - // ============================================================================ // Layer 2 Tag Variation Tests (Tests 8a-c) // ============================================================================ -- cgit v1.2.3