diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
| commit | e237328ec611a5891586530c1d3cb26c16c1093b (patch) | |
| tree | 22ac36baa240354d06ae82eb070609fa3e3fcb82 /test_utils/src/lib.rs | |
| parent | 000901c0cbca8464b5a89bcc93c5474f6564bafd (diff) | |
feat(login) fetch user relays and metadata
get user relay list and metadata events from relays when keys are
used and last fetch attempt was more than an hour ago
uses user's write relays if known, otherwise uses fallback relays
to achieve this a method for intergration testing event fetching
from relays was added
Diffstat (limited to 'test_utils/src/lib.rs')
| -rw-r--r-- | test_utils/src/lib.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index a9d818c..2a06357 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -23,6 +23,39 @@ pub static TEST_KEY_1_ENCRYPTED_WEAK: &str = "ncryptsec1qy8ke0tjqnn8wt3w6lnc86c2 | |||
| 23 | pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = | 23 | pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = |
| 24 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_1_NSEC).unwrap()); | 24 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_1_NSEC).unwrap()); |
| 25 | 25 | ||
| 26 | pub fn generate_test_key_1_metadata_event(name: &str) -> nostr::Event { | ||
| 27 | nostr::event::EventBuilder::set_metadata(nostr::Metadata::new().name(name)) | ||
| 28 | .to_event(&TEST_KEY_1_KEYS) | ||
| 29 | .unwrap() | ||
| 30 | } | ||
| 31 | pub fn generate_test_key_1_metadata_event_old(name: &str) -> nostr::Event { | ||
| 32 | make_event_old_or_change_user( | ||
| 33 | generate_test_key_1_metadata_event(name), | ||
| 34 | &TEST_KEY_1_KEYS, | ||
| 35 | 10000, | ||
| 36 | ) | ||
| 37 | } | ||
| 38 | |||
| 39 | pub fn generate_test_key_1_relay_list_event() -> nostr::Event { | ||
| 40 | nostr::event::EventBuilder::new( | ||
| 41 | nostr::Kind::RelayList, | ||
| 42 | "", | ||
| 43 | &[ | ||
| 44 | nostr::Tag::RelayMetadata( | ||
| 45 | "ws://localhost:8053".into(), | ||
| 46 | Some(nostr::RelayMetadata::Write), | ||
| 47 | ), | ||
| 48 | nostr::Tag::RelayMetadata( | ||
| 49 | "ws://localhost:8054".into(), | ||
| 50 | Some(nostr::RelayMetadata::Read), | ||
| 51 | ), | ||
| 52 | nostr::Tag::RelayMetadata("ws://localhost:8055".into(), None), | ||
| 53 | ], | ||
| 54 | ) | ||
| 55 | .to_event(&TEST_KEY_1_KEYS) | ||
| 56 | .unwrap() | ||
| 57 | } | ||
| 58 | |||
| 26 | pub static TEST_KEY_2_NSEC: &str = | 59 | pub static TEST_KEY_2_NSEC: &str = |
| 27 | "nsec1ypglg6nj6ep0g2qmyfqcv2al502gje3jvpwye6mthmkvj93tqkesknv6qm"; | 60 | "nsec1ypglg6nj6ep0g2qmyfqcv2al502gje3jvpwye6mthmkvj93tqkesknv6qm"; |
| 28 | pub static TEST_KEY_2_NPUB: &str = | 61 | pub static TEST_KEY_2_NPUB: &str = |
| @@ -33,12 +66,41 @@ pub static TEST_KEY_2_ENCRYPTED: &str = "...2"; | |||
| 33 | pub static TEST_KEY_2_KEYS: Lazy<nostr::Keys> = | 66 | pub static TEST_KEY_2_KEYS: Lazy<nostr::Keys> = |
| 34 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_2_NSEC).unwrap()); | 67 | Lazy::new(|| nostr::Keys::from_sk_str(TEST_KEY_2_NSEC).unwrap()); |
| 35 | 68 | ||
| 69 | pub fn generate_test_key_2_metadata_event(name: &str) -> nostr::Event { | ||
| 70 | nostr::event::EventBuilder::set_metadata(nostr::Metadata::new().name(name)) | ||
| 71 | .to_event(&TEST_KEY_2_KEYS) | ||
| 72 | .unwrap() | ||
| 73 | } | ||
| 74 | |||
| 36 | pub static TEST_INVALID_NSEC: &str = "nsec1ppsg5sm2aex"; | 75 | pub static TEST_INVALID_NSEC: &str = "nsec1ppsg5sm2aex"; |
| 37 | pub static TEST_PASSWORD: &str = "769dfd£pwega8SHGv3!#Bsfd5t"; | 76 | pub static TEST_PASSWORD: &str = "769dfd£pwega8SHGv3!#Bsfd5t"; |
| 38 | pub static TEST_INVALID_PASSWORD: &str = "INVALID769dfd£pwega8SHGv3!"; | 77 | pub static TEST_INVALID_PASSWORD: &str = "INVALID769dfd£pwega8SHGv3!"; |
| 39 | pub static TEST_WEAK_PASSWORD: &str = "fhaiuhfwe"; | 78 | pub static TEST_WEAK_PASSWORD: &str = "fhaiuhfwe"; |
| 40 | pub static TEST_RANDOM_TOKEN: &str = "lkjh2398HLKJ43hrweiJ6FaPfdssgtrg"; | 79 | pub static TEST_RANDOM_TOKEN: &str = "lkjh2398HLKJ43hrweiJ6FaPfdssgtrg"; |
| 41 | 80 | ||
| 81 | pub fn make_event_old_or_change_user( | ||
| 82 | event: nostr::Event, | ||
| 83 | keys: &nostr::Keys, | ||
| 84 | how_old_in_secs: u64, | ||
| 85 | ) -> nostr::Event { | ||
| 86 | let mut unsigned = nostr::event::EventBuilder::new(event.kind, event.content, &event.tags) | ||
| 87 | .to_unsigned_event(keys.public_key()); | ||
| 88 | |||
| 89 | unsigned.created_at = nostr::types::Timestamp::try_from( | ||
| 90 | nostr::types::Timestamp::now().as_u64() - how_old_in_secs, | ||
| 91 | ) | ||
| 92 | .unwrap(); | ||
| 93 | unsigned.id = nostr::EventId::new( | ||
| 94 | &keys.public_key(), | ||
| 95 | unsigned.created_at, | ||
| 96 | &unsigned.kind, | ||
| 97 | &unsigned.tags, | ||
| 98 | &unsigned.content, | ||
| 99 | ); | ||
| 100 | |||
| 101 | unsigned.sign(keys).unwrap() | ||
| 102 | } | ||
| 103 | |||
| 42 | /// wrapper for a cli testing tool - currently wraps rexpect and dialoguer | 104 | /// wrapper for a cli testing tool - currently wraps rexpect and dialoguer |
| 43 | /// | 105 | /// |
| 44 | /// 1. allow more accurate articulation of expected behaviour | 106 | /// 1. allow more accurate articulation of expected behaviour |