upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils/src/lib.rs')
-rw-r--r--test_utils/src/lib.rs62
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
23pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = 23pub 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
26pub 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}
31pub 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
39pub 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
26pub static TEST_KEY_2_NSEC: &str = 59pub static TEST_KEY_2_NSEC: &str =
27 "nsec1ypglg6nj6ep0g2qmyfqcv2al502gje3jvpwye6mthmkvj93tqkesknv6qm"; 60 "nsec1ypglg6nj6ep0g2qmyfqcv2al502gje3jvpwye6mthmkvj93tqkesknv6qm";
28pub static TEST_KEY_2_NPUB: &str = 61pub static TEST_KEY_2_NPUB: &str =
@@ -33,12 +66,41 @@ pub static TEST_KEY_2_ENCRYPTED: &str = "...2";
33pub static TEST_KEY_2_KEYS: Lazy<nostr::Keys> = 66pub 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
69pub 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
36pub static TEST_INVALID_NSEC: &str = "nsec1ppsg5sm2aex"; 75pub static TEST_INVALID_NSEC: &str = "nsec1ppsg5sm2aex";
37pub static TEST_PASSWORD: &str = "769dfd£pwega8SHGv3!#Bsfd5t"; 76pub static TEST_PASSWORD: &str = "769dfd£pwega8SHGv3!#Bsfd5t";
38pub static TEST_INVALID_PASSWORD: &str = "INVALID769dfd£pwega8SHGv3!"; 77pub static TEST_INVALID_PASSWORD: &str = "INVALID769dfd£pwega8SHGv3!";
39pub static TEST_WEAK_PASSWORD: &str = "fhaiuhfwe"; 78pub static TEST_WEAK_PASSWORD: &str = "fhaiuhfwe";
40pub static TEST_RANDOM_TOKEN: &str = "lkjh2398HLKJ43hrweiJ6FaPfdssgtrg"; 79pub static TEST_RANDOM_TOKEN: &str = "lkjh2398HLKJ43hrweiJ6FaPfdssgtrg";
41 80
81pub 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