diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 16:59:09 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 16:59:09 +0000 |
| commit | cbed48d5a20b646a5bcc23e907d6163a3a8d36c5 (patch) | |
| tree | d01b4e49e5ffadc8f12f00f44e015531fa2deadb /tests | |
| parent | a958a55196537598492c3935ab46e3b6e23ee44b (diff) | |
refactor(tests): extract shared create_repo_announcement helper
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/common/sync_helpers.rs | 40 | ||||
| -rw-r--r-- | tests/sync/bootstrap.rs | 33 | ||||
| -rw-r--r-- | tests/sync/catchup.rs | 33 | ||||
| -rw-r--r-- | tests/sync/discovery.rs | 23 | ||||
| -rw-r--r-- | tests/sync/live_sync.rs | 33 | ||||
| -rw-r--r-- | tests/sync/tag_variations.rs | 33 |
6 files changed, 40 insertions, 155 deletions
diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index d9be332..be8f421 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs | |||
| @@ -325,6 +325,46 @@ pub fn build_layer3_quote_with_q_tag( | |||
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | // ============================================================================ | 327 | // ============================================================================ |
| 328 | // Repository Announcement Helper | ||
| 329 | // ============================================================================ | ||
| 330 | |||
| 331 | /// Create a valid repository announcement event for testing sync. | ||
| 332 | /// | ||
| 333 | /// This creates a kind 30617 event with required clone and relays tags. | ||
| 334 | /// The event lists all provided domains so it will be accepted by each | ||
| 335 | /// relay's write policy. | ||
| 336 | /// | ||
| 337 | /// # Arguments | ||
| 338 | /// * `keys` - Keys for signing | ||
| 339 | /// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") | ||
| 340 | /// * `identifier` - Repository identifier (d-tag) | ||
| 341 | /// | ||
| 342 | /// # Returns | ||
| 343 | /// A signed repository announcement event ready to send. | ||
| 344 | pub fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { | ||
| 345 | // Build clone URLs for all domains (with .git suffix) | ||
| 346 | let clone_urls: Vec<String> = domains | ||
| 347 | .iter() | ||
| 348 | .map(|d| format!("http://{}/{}.git", d, identifier)) | ||
| 349 | .collect(); | ||
| 350 | |||
| 351 | // Build relay URLs for all domains | ||
| 352 | let relay_urls: Vec<String> = domains.iter().map(|d| format!("ws://{}", d)).collect(); | ||
| 353 | |||
| 354 | // Build tags for repository announcement | ||
| 355 | let tags = vec![ | ||
| 356 | Tag::identifier(identifier), | ||
| 357 | Tag::custom(TagKind::custom("clone"), clone_urls), | ||
| 358 | Tag::custom(TagKind::custom("relays"), relay_urls), | ||
| 359 | ]; | ||
| 360 | |||
| 361 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | ||
| 362 | .tags(tags) | ||
| 363 | .sign_with_keys(keys) | ||
| 364 | .expect("Failed to sign repo announcement") | ||
| 365 | } | ||
| 366 | |||
| 367 | // ============================================================================ | ||
| 328 | // Assertion Helpers | 368 | // Assertion Helpers |
| 329 | // ============================================================================ | 369 | // ============================================================================ |
| 330 | 370 | ||
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::*; | |||
| 14 | 14 | ||
| 15 | use crate::common::{sync_helpers::*, TestRelay}; | 15 | use crate::common::{sync_helpers::*, TestRelay}; |
| 16 | 16 | ||
| 17 | /// Create a valid repository announcement event for testing sync. | ||
| 18 | /// | ||
| 19 | /// This creates a kind 30617 event with required clone and relays tags. | ||
| 20 | /// The event lists all provided domains so it will be accepted by each | ||
| 21 | /// relay's write policy. | ||
| 22 | /// | ||
| 23 | /// # Arguments | ||
| 24 | /// * `keys` - Keys for signing | ||
| 25 | /// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") | ||
| 26 | /// * `identifier` - Repository identifier (d-tag) | ||
| 27 | fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { | ||
| 28 | // Build clone URLs for all domains (with .git suffix) | ||
| 29 | let clone_urls: Vec<String> = domains | ||
| 30 | .iter() | ||
| 31 | .map(|d| format!("http://{}/{}.git", d, identifier)) | ||
| 32 | .collect(); | ||
| 33 | |||
| 34 | // Build relay URLs for all domains | ||
| 35 | let relay_urls: Vec<String> = domains.iter().map(|d| format!("ws://{}", d)).collect(); | ||
| 36 | |||
| 37 | // Build tags for repository announcement | ||
| 38 | let tags = vec![ | ||
| 39 | Tag::identifier(identifier), | ||
| 40 | Tag::custom(TagKind::custom("clone"), clone_urls), | ||
| 41 | Tag::custom(TagKind::custom("relays"), relay_urls), | ||
| 42 | ]; | ||
| 43 | |||
| 44 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | ||
| 45 | .tags(tags) | ||
| 46 | .sign_with_keys(keys) | ||
| 47 | .expect("Failed to sign repo announcement") | ||
| 48 | } | ||
| 49 | |||
| 50 | /// Test 1: Bootstrap sync - relay syncs existing events from bootstrap relay on startup | 17 | /// Test 1: Bootstrap sync - relay syncs existing events from bootstrap relay on startup |
| 51 | /// | 18 | /// |
| 52 | /// Scenario: | 19 | /// 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::*; | |||
| 35 | 35 | ||
| 36 | use crate::common::{sync_helpers::*, TestRelay}; | 36 | use crate::common::{sync_helpers::*, TestRelay}; |
| 37 | 37 | ||
| 38 | /// Create a valid repository announcement event for testing sync. | ||
| 39 | /// | ||
| 40 | /// This creates a kind 30617 event with required clone and relays tags. | ||
| 41 | /// The event lists all provided domains so it will be accepted by each | ||
| 42 | /// relay's write policy. | ||
| 43 | /// | ||
| 44 | /// # Arguments | ||
| 45 | /// * `keys` - Keys for signing | ||
| 46 | /// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") | ||
| 47 | /// * `identifier` - Repository identifier (d-tag) | ||
| 48 | fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { | ||
| 49 | // Build clone URLs for all domains (with .git suffix) | ||
| 50 | let clone_urls: Vec<String> = domains | ||
| 51 | .iter() | ||
| 52 | .map(|d| format!("http://{}/{}.git", d, identifier)) | ||
| 53 | .collect(); | ||
| 54 | |||
| 55 | // Build relay URLs for all domains | ||
| 56 | let relay_urls: Vec<String> = domains.iter().map(|d| format!("ws://{}", d)).collect(); | ||
| 57 | |||
| 58 | // Build tags for repository announcement | ||
| 59 | let tags = vec![ | ||
| 60 | Tag::identifier(identifier), | ||
| 61 | Tag::custom(TagKind::custom("clone"), clone_urls), | ||
| 62 | Tag::custom(TagKind::custom("relays"), relay_urls), | ||
| 63 | ]; | ||
| 64 | |||
| 65 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | ||
| 66 | .tags(tags) | ||
| 67 | .sign_with_keys(keys) | ||
| 68 | .expect("Failed to sign repo announcement") | ||
| 69 | } | ||
| 70 | |||
| 71 | /// Test that relay performs catchup sync after being offline | 38 | /// Test that relay performs catchup sync after being offline |
| 72 | /// | 39 | /// |
| 73 | /// # Scenario | 40 | /// # 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}; | |||
| 17 | /// Kind 1617 - Patch event (NIP-34) | 17 | /// Kind 1617 - Patch event (NIP-34) |
| 18 | const KIND_PATCH: u16 = 1617; | 18 | const KIND_PATCH: u16 = 1617; |
| 19 | 19 | ||
| 20 | /// Create a valid repository announcement event for testing sync. | ||
| 21 | /// | ||
| 22 | /// This creates a kind 30617 event with required clone and relays tags. | ||
| 23 | fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { | ||
| 24 | let clone_urls: Vec<String> = domains | ||
| 25 | .iter() | ||
| 26 | .map(|d| format!("http://{}/{}.git", d, identifier)) | ||
| 27 | .collect(); | ||
| 28 | |||
| 29 | let relay_urls: Vec<String> = domains.iter().map(|d| format!("ws://{}", d)).collect(); | ||
| 30 | |||
| 31 | let tags = vec![ | ||
| 32 | Tag::identifier(identifier), | ||
| 33 | Tag::custom(TagKind::custom("clone"), clone_urls), | ||
| 34 | Tag::custom(TagKind::custom("relays"), relay_urls), | ||
| 35 | ]; | ||
| 36 | |||
| 37 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | ||
| 38 | .tags(tags) | ||
| 39 | .sign_with_keys(keys) | ||
| 40 | .expect("Failed to sign repo announcement") | ||
| 41 | } | ||
| 42 | |||
| 43 | /// Create an event referencing a repository coordinate via 'a' tag. | 20 | /// Create an event referencing a repository coordinate via 'a' tag. |
| 44 | /// | 21 | /// |
| 45 | /// Used to create Layer 2 events like patches that reference a repository. | 22 | /// 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::*; | |||
| 24 | 24 | ||
| 25 | use crate::common::{sync_helpers::*, TestRelay}; | 25 | use crate::common::{sync_helpers::*, TestRelay}; |
| 26 | 26 | ||
| 27 | /// Create a valid repository announcement event for testing sync. | ||
| 28 | /// | ||
| 29 | /// This creates a kind 30617 event with required clone and relays tags. | ||
| 30 | /// The event lists all provided domains so it will be accepted by each | ||
| 31 | /// relay's write policy. | ||
| 32 | /// | ||
| 33 | /// # Arguments | ||
| 34 | /// * `keys` - Keys for signing | ||
| 35 | /// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") | ||
| 36 | /// * `identifier` - Repository identifier (d-tag) | ||
| 37 | fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { | ||
| 38 | // Build clone URLs for all domains (with .git suffix) | ||
| 39 | let clone_urls: Vec<String> = domains | ||
| 40 | .iter() | ||
| 41 | .map(|d| format!("http://{}/{}.git", d, identifier)) | ||
| 42 | .collect(); | ||
| 43 | |||
| 44 | // Build relay URLs for all domains | ||
| 45 | let relay_urls: Vec<String> = domains.iter().map(|d| format!("ws://{}", d)).collect(); | ||
| 46 | |||
| 47 | // Build tags for repository announcement | ||
| 48 | let tags = vec![ | ||
| 49 | Tag::identifier(identifier), | ||
| 50 | Tag::custom(TagKind::custom("clone"), clone_urls), | ||
| 51 | Tag::custom(TagKind::custom("relays"), relay_urls), | ||
| 52 | ]; | ||
| 53 | |||
| 54 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | ||
| 55 | .tags(tags) | ||
| 56 | .sign_with_keys(keys) | ||
| 57 | .expect("Failed to sign repo announcement") | ||
| 58 | } | ||
| 59 | |||
| 60 | /// Test 5: Live sync Layer 2 events | 27 | /// Test 5: Live sync Layer 2 events |
| 61 | /// | 28 | /// |
| 62 | /// Verifies that Layer 2 events (kind 1618 issues) published to one relay | 29 | /// 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::*; | |||
| 25 | 25 | ||
| 26 | use crate::common::{sync_helpers::*, TestRelay}; | 26 | use crate::common::{sync_helpers::*, TestRelay}; |
| 27 | 27 | ||
| 28 | /// Create a valid repository announcement event for testing sync. | ||
| 29 | /// | ||
| 30 | /// This creates a kind 30617 event with required clone and relays tags. | ||
| 31 | /// The event lists all provided domains so it will be accepted by each | ||
| 32 | /// relay's write policy. | ||
| 33 | /// | ||
| 34 | /// # Arguments | ||
| 35 | /// * `keys` - Keys for signing | ||
| 36 | /// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") | ||
| 37 | /// * `identifier` - Repository identifier (d-tag) | ||
| 38 | fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { | ||
| 39 | // Build clone URLs for all domains (with .git suffix) | ||
| 40 | let clone_urls: Vec<String> = domains | ||
| 41 | .iter() | ||
| 42 | .map(|d| format!("http://{}/{}.git", d, identifier)) | ||
| 43 | .collect(); | ||
| 44 | |||
| 45 | // Build relay URLs for all domains | ||
| 46 | let relay_urls: Vec<String> = domains.iter().map(|d| format!("ws://{}", d)).collect(); | ||
| 47 | |||
| 48 | // Build tags for repository announcement | ||
| 49 | let tags = vec![ | ||
| 50 | Tag::identifier(identifier), | ||
| 51 | Tag::custom(TagKind::custom("clone"), clone_urls), | ||
| 52 | Tag::custom(TagKind::custom("relays"), relay_urls), | ||
| 53 | ]; | ||
| 54 | |||
| 55 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | ||
| 56 | .tags(tags) | ||
| 57 | .sign_with_keys(keys) | ||
| 58 | .expect("Failed to sign repo announcement") | ||
| 59 | } | ||
| 60 | |||
| 61 | // ============================================================================ | 28 | // ============================================================================ |
| 62 | // Layer 2 Tag Variation Tests (Tests 8a-c) | 29 | // Layer 2 Tag Variation Tests (Tests 8a-c) |
| 63 | // ============================================================================ | 30 | // ============================================================================ |