diff options
Diffstat (limited to 'test_utils/src/lib.rs')
| -rw-r--r-- | test_utils/src/lib.rs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index f509039..f3f9dcf 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -3,7 +3,7 @@ use std::{ffi::OsStr, path::PathBuf}; | |||
| 3 | use anyhow::{ensure, Context, Result}; | 3 | use anyhow::{ensure, Context, Result}; |
| 4 | use dialoguer::theme::{ColorfulTheme, Theme}; | 4 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 5 | use directories::ProjectDirs; | 5 | use directories::ProjectDirs; |
| 6 | use nostr::{self, prelude::FromSkStr, Tag}; | 6 | use nostr::{self, prelude::FromSkStr, Kind, Tag}; |
| 7 | use once_cell::sync::Lazy; | 7 | use once_cell::sync::Lazy; |
| 8 | use rexpect::session::{Options, PtySession}; | 8 | use rexpect::session::{Options, PtySession}; |
| 9 | use strip_ansi_escapes::strip_str; | 9 | use strip_ansi_escapes::strip_str; |
| @@ -28,10 +28,11 @@ pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = | |||
| 28 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_1_NSEC).unwrap()); | 28 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_1_NSEC).unwrap()); |
| 29 | 29 | ||
| 30 | pub fn generate_test_key_1_metadata_event(name: &str) -> nostr::Event { | 30 | pub fn generate_test_key_1_metadata_event(name: &str) -> nostr::Event { |
| 31 | nostr::event::EventBuilder::set_metadata(nostr::Metadata::new().name(name)) | 31 | nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name)) |
| 32 | .to_event(&TEST_KEY_1_KEYS) | 32 | .to_event(&TEST_KEY_1_KEYS) |
| 33 | .unwrap() | 33 | .unwrap() |
| 34 | } | 34 | } |
| 35 | |||
| 35 | pub fn generate_test_key_1_metadata_event_old(name: &str) -> nostr::Event { | 36 | pub fn generate_test_key_1_metadata_event_old(name: &str) -> nostr::Event { |
| 36 | make_event_old_or_change_user( | 37 | make_event_old_or_change_user( |
| 37 | generate_test_key_1_metadata_event(name), | 38 | generate_test_key_1_metadata_event(name), |
| @@ -40,11 +41,17 @@ pub fn generate_test_key_1_metadata_event_old(name: &str) -> nostr::Event { | |||
| 40 | ) | 41 | ) |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 44 | pub fn generate_test_key_1_kind_event(kind: Kind) -> nostr::Event { | ||
| 45 | nostr::event::EventBuilder::new(kind, "", []) | ||
| 46 | .to_event(&TEST_KEY_1_KEYS) | ||
| 47 | .unwrap() | ||
| 48 | } | ||
| 49 | |||
| 43 | pub fn generate_test_key_1_relay_list_event() -> nostr::Event { | 50 | pub fn generate_test_key_1_relay_list_event() -> nostr::Event { |
| 44 | nostr::event::EventBuilder::new( | 51 | nostr::event::EventBuilder::new( |
| 45 | nostr::Kind::RelayList, | 52 | nostr::Kind::RelayList, |
| 46 | "", | 53 | "", |
| 47 | &[ | 54 | [ |
| 48 | nostr::Tag::RelayMetadata( | 55 | nostr::Tag::RelayMetadata( |
| 49 | "ws://localhost:8053".into(), | 56 | "ws://localhost:8053".into(), |
| 50 | Some(nostr::RelayMetadata::Write), | 57 | Some(nostr::RelayMetadata::Write), |
| @@ -64,7 +71,7 @@ pub fn generate_test_key_1_relay_list_event_same_as_fallback() -> nostr::Event { | |||
| 64 | nostr::event::EventBuilder::new( | 71 | nostr::event::EventBuilder::new( |
| 65 | nostr::Kind::RelayList, | 72 | nostr::Kind::RelayList, |
| 66 | "", | 73 | "", |
| 67 | &[ | 74 | [ |
| 68 | nostr::Tag::RelayMetadata( | 75 | nostr::Tag::RelayMetadata( |
| 69 | "ws://localhost:8051".into(), | 76 | "ws://localhost:8051".into(), |
| 70 | Some(nostr::RelayMetadata::Write), | 77 | Some(nostr::RelayMetadata::Write), |
| @@ -90,7 +97,7 @@ pub static TEST_KEY_2_KEYS: Lazy<nostr::Keys> = | |||
| 90 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_2_NSEC).unwrap()); | 97 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_2_NSEC).unwrap()); |
| 91 | 98 | ||
| 92 | pub fn generate_test_key_2_metadata_event(name: &str) -> nostr::Event { | 99 | pub fn generate_test_key_2_metadata_event(name: &str) -> nostr::Event { |
| 93 | nostr::event::EventBuilder::set_metadata(nostr::Metadata::new().name(name)) | 100 | nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name)) |
| 94 | .to_event(&TEST_KEY_2_KEYS) | 101 | .to_event(&TEST_KEY_2_KEYS) |
| 95 | .unwrap() | 102 | .unwrap() |
| 96 | } | 103 | } |
| @@ -106,13 +113,12 @@ pub fn make_event_old_or_change_user( | |||
| 106 | keys: &nostr::Keys, | 113 | keys: &nostr::Keys, |
| 107 | how_old_in_secs: u64, | 114 | how_old_in_secs: u64, |
| 108 | ) -> nostr::Event { | 115 | ) -> nostr::Event { |
| 109 | let mut unsigned = nostr::event::EventBuilder::new(event.kind, event.content, &event.tags) | 116 | let mut unsigned = |
| 110 | .to_unsigned_event(keys.public_key()); | 117 | nostr::event::EventBuilder::new(event.kind, event.content.clone(), event.tags.clone()) |
| 118 | .to_unsigned_event(keys.public_key()); | ||
| 111 | 119 | ||
| 112 | unsigned.created_at = nostr::types::Timestamp::try_from( | 120 | unsigned.created_at = |
| 113 | nostr::types::Timestamp::now().as_u64() - how_old_in_secs, | 121 | nostr::types::Timestamp::from(nostr::types::Timestamp::now().as_u64() - how_old_in_secs); |
| 114 | ) | ||
| 115 | .unwrap(); | ||
| 116 | unsigned.id = nostr::EventId::new( | 122 | unsigned.id = nostr::EventId::new( |
| 117 | &keys.public_key(), | 123 | &keys.public_key(), |
| 118 | unsigned.created_at, | 124 | unsigned.created_at, |
| @@ -130,15 +136,15 @@ pub fn generate_repo_ref_event() -> nostr::Event { | |||
| 130 | nostr::event::EventBuilder::new( | 136 | nostr::event::EventBuilder::new( |
| 131 | nostr::Kind::Custom(REPOSITORY_KIND), | 137 | nostr::Kind::Custom(REPOSITORY_KIND), |
| 132 | "", | 138 | "", |
| 133 | &[ | 139 | [ |
| 134 | Tag::Identifier(root_commit.to_string()), | 140 | Tag::Identifier(root_commit.to_string()), |
| 135 | Tag::Reference(format!("r-{}", root_commit)), | 141 | Tag::Reference(format!("r-{}", root_commit)), |
| 136 | Tag::Name("example name".to_string()), | 142 | Tag::Name("example name".to_string()), |
| 137 | Tag::Description("example description".to_string()), | 143 | Tag::Description("example description".to_string()), |
| 138 | Tag::Relay("ws://localhost:8055".into()), | 144 | Tag::Relay("ws://localhost:8055".into()), |
| 139 | Tag::Relay("ws://localhost:8056".into()), | 145 | Tag::Relay("ws://localhost:8056".into()), |
| 140 | Tag::PubKey(TEST_KEY_1_KEYS.public_key(), None), | 146 | Tag::public_key(TEST_KEY_1_KEYS.public_key()), |
| 141 | Tag::PubKey(TEST_KEY_2_KEYS.public_key(), None), | 147 | Tag::public_key(TEST_KEY_2_KEYS.public_key()), |
| 142 | ], | 148 | ], |
| 143 | ) | 149 | ) |
| 144 | .to_event(&TEST_KEY_1_KEYS) | 150 | .to_event(&TEST_KEY_1_KEYS) |