diff options
Diffstat (limited to 'test_utils/src/lib.rs')
| -rw-r--r-- | test_utils/src/lib.rs | 60 |
1 files changed, 26 insertions, 34 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 6708c81..0c5de73 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -11,7 +11,7 @@ use dialoguer::theme::{ColorfulTheme, Theme}; | |||
| 11 | use futures::executor::block_on; | 11 | use futures::executor::block_on; |
| 12 | use git::GitTestRepo; | 12 | use git::GitTestRepo; |
| 13 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; | 13 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; |
| 14 | use nostr_database::NostrDatabase; | 14 | use nostr_database::NostrEventsDatabase; |
| 15 | use nostr_lmdb::NostrLMDB; | 15 | use nostr_lmdb::NostrLMDB; |
| 16 | use nostr_sdk::{serde_json, Client, NostrSigner, TagStandard}; | 16 | use nostr_sdk::{serde_json, Client, NostrSigner, TagStandard}; |
| 17 | use once_cell::sync::Lazy; | 17 | use once_cell::sync::Lazy; |
| @@ -58,51 +58,46 @@ pub fn generate_test_key_1_metadata_event_old(name: &str) -> nostr::Event { | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | pub fn generate_test_key_1_kind_event(kind: Kind) -> nostr::Event { | 60 | pub fn generate_test_key_1_kind_event(kind: Kind) -> nostr::Event { |
| 61 | nostr::event::EventBuilder::new(kind, "", []) | 61 | nostr::event::EventBuilder::new(kind, "") |
| 62 | .tags([]) | ||
| 62 | .sign_with_keys(&TEST_KEY_1_KEYS) | 63 | .sign_with_keys(&TEST_KEY_1_KEYS) |
| 63 | .unwrap() | 64 | .unwrap() |
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | pub fn generate_test_key_1_relay_list_event() -> nostr::Event { | 67 | pub fn generate_test_key_1_relay_list_event() -> nostr::Event { |
| 67 | nostr::event::EventBuilder::new( | 68 | nostr::event::EventBuilder::new(nostr::Kind::RelayList, "") |
| 68 | nostr::Kind::RelayList, | 69 | .tags([ |
| 69 | "", | ||
| 70 | [ | ||
| 71 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { | 70 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 72 | relay_url: nostr::Url::from_str("ws://localhost:8053").unwrap(), | 71 | relay_url: nostr::RelayUrl::from_str("ws://localhost:8053").unwrap(), |
| 73 | metadata: Some(RelayMetadata::Write), | 72 | metadata: Some(RelayMetadata::Write), |
| 74 | }), | 73 | }), |
| 75 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { | 74 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 76 | relay_url: nostr::Url::from_str("ws://localhost:8054").unwrap(), | 75 | relay_url: nostr::RelayUrl::from_str("ws://localhost:8054").unwrap(), |
| 77 | metadata: Some(RelayMetadata::Read), | 76 | metadata: Some(RelayMetadata::Read), |
| 78 | }), | 77 | }), |
| 79 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { | 78 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 80 | relay_url: nostr::Url::from_str("ws://localhost:8055").unwrap(), | 79 | relay_url: nostr::RelayUrl::from_str("ws://localhost:8055").unwrap(), |
| 81 | metadata: None, | 80 | metadata: None, |
| 82 | }), | 81 | }), |
| 83 | ], | 82 | ]) |
| 84 | ) | 83 | .sign_with_keys(&TEST_KEY_1_KEYS) |
| 85 | .sign_with_keys(&TEST_KEY_1_KEYS) | 84 | .unwrap() |
| 86 | .unwrap() | ||
| 87 | } | 85 | } |
| 88 | 86 | ||
| 89 | pub fn generate_test_key_1_relay_list_event_same_as_fallback() -> nostr::Event { | 87 | pub fn generate_test_key_1_relay_list_event_same_as_fallback() -> nostr::Event { |
| 90 | nostr::event::EventBuilder::new( | 88 | nostr::event::EventBuilder::new(nostr::Kind::RelayList, "") |
| 91 | nostr::Kind::RelayList, | 89 | .tags([ |
| 92 | "", | ||
| 93 | [ | ||
| 94 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { | 90 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 95 | relay_url: nostr::Url::from_str("ws://localhost:8051").unwrap(), | 91 | relay_url: nostr::RelayUrl::from_str("ws://localhost:8051").unwrap(), |
| 96 | metadata: Some(RelayMetadata::Write), | 92 | metadata: Some(RelayMetadata::Write), |
| 97 | }), | 93 | }), |
| 98 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { | 94 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 99 | relay_url: nostr::Url::from_str("ws://localhost:8052").unwrap(), | 95 | relay_url: nostr::RelayUrl::from_str("ws://localhost:8052").unwrap(), |
| 100 | metadata: Some(RelayMetadata::Write), | 96 | metadata: Some(RelayMetadata::Write), |
| 101 | }), | 97 | }), |
| 102 | ], | 98 | ]) |
| 103 | ) | 99 | .sign_with_keys(&TEST_KEY_1_KEYS) |
| 104 | .sign_with_keys(&TEST_KEY_1_KEYS) | 100 | .unwrap() |
| 105 | .unwrap() | ||
| 106 | } | 101 | } |
| 107 | 102 | ||
| 108 | pub static TEST_KEY_2_NSEC: &str = | 103 | pub static TEST_KEY_2_NSEC: &str = |
| @@ -133,9 +128,9 @@ pub fn make_event_old_or_change_user( | |||
| 133 | keys: &nostr::Keys, | 128 | keys: &nostr::Keys, |
| 134 | how_old_in_secs: u64, | 129 | how_old_in_secs: u64, |
| 135 | ) -> nostr::Event { | 130 | ) -> nostr::Event { |
| 136 | let mut unsigned = | 131 | let mut unsigned = nostr::event::EventBuilder::new(event.kind, event.content.clone()) |
| 137 | nostr::event::EventBuilder::new(event.kind, event.content.clone(), event.tags.clone()) | 132 | .tags(event.tags.clone()) |
| 138 | .build(keys.public_key()); | 133 | .build(keys.public_key()); |
| 139 | 134 | ||
| 140 | unsigned.created_at = | 135 | unsigned.created_at = |
| 141 | nostr::types::Timestamp::from(nostr::types::Timestamp::now().as_u64() - how_old_in_secs); | 136 | nostr::types::Timestamp::from(nostr::types::Timestamp::now().as_u64() - how_old_in_secs); |
| @@ -159,10 +154,8 @@ pub fn generate_repo_ref_event_with_git_server(git_servers: Vec<String>) -> nost | |||
| 159 | // TODO - this may not be consistant across computers as it might take the | 154 | // TODO - this may not be consistant across computers as it might take the |
| 160 | // author and committer from global git config | 155 | // author and committer from global git config |
| 161 | let root_commit = "9ee507fc4357d7ee16a5d8901bedcd103f23c17d"; | 156 | let root_commit = "9ee507fc4357d7ee16a5d8901bedcd103f23c17d"; |
| 162 | nostr::event::EventBuilder::new( | 157 | nostr::event::EventBuilder::new(nostr::Kind::GitRepoAnnouncement, "") |
| 163 | nostr::Kind::GitRepoAnnouncement, | 158 | .tags([ |
| 164 | "", | ||
| 165 | [ | ||
| 166 | Tag::identifier( | 159 | Tag::identifier( |
| 167 | // root_commit.to_string() | 160 | // root_commit.to_string() |
| 168 | format!("{}-consider-it-random", root_commit), | 161 | format!("{}-consider-it-random", root_commit), |
| @@ -195,10 +188,9 @@ pub fn generate_repo_ref_event_with_git_server(git_servers: Vec<String>) -> nost | |||
| 195 | TEST_KEY_2_KEYS.public_key().to_string(), | 188 | TEST_KEY_2_KEYS.public_key().to_string(), |
| 196 | ], | 189 | ], |
| 197 | ), | 190 | ), |
| 198 | ], | 191 | ]) |
| 199 | ) | 192 | .sign_with_keys(&TEST_KEY_1_KEYS) |
| 200 | .sign_with_keys(&TEST_KEY_1_KEYS) | 193 | .unwrap() |
| 201 | .unwrap() | ||
| 202 | } | 194 | } |
| 203 | 195 | ||
| 204 | /// enough to fool event_is_patch_set_root | 196 | /// enough to fool event_is_patch_set_root |