lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

wire.rs (1409B)


      1 use radroots_events::kinds::KIND_POST;
      2 use radroots_events_codec::wire::{
      3     WireEventParts, canonicalize_tags, empty_content, to_frozen_draft,
      4 };
      5 
      6 #[test]
      7 fn canonicalize_tags_trims_sorts_and_dedups() {
      8     let mut tags = vec![
      9         vec![" z ".to_string(), "b".to_string()],
     10         vec!["t".to_string(), "a".to_string()],
     11         vec!["".to_string(), "x".to_string()],
     12         vec![" t ".to_string(), "a ".to_string()],
     13         vec!["t".to_string(), "a".to_string()],
     14     ];
     15 
     16     canonicalize_tags(&mut tags);
     17 
     18     assert_eq!(
     19         tags,
     20         vec![
     21             vec!["t".to_string(), "a".to_string()],
     22             vec!["z".to_string(), "b".to_string()],
     23         ]
     24     );
     25 }
     26 
     27 #[test]
     28 fn to_frozen_draft_copies_fields_and_computes_expected_id() {
     29     let parts = WireEventParts {
     30         kind: KIND_POST,
     31         content: "hello".to_string(),
     32         tags: vec![vec!["t".to_string(), "a".to_string()]],
     33     };
     34 
     35     let draft =
     36         to_frozen_draft(parts, "radroots.social.post.v1", "a".repeat(64), 99).expect("draft");
     37 
     38     assert_eq!(draft.kind, KIND_POST);
     39     assert_eq!(draft.created_at, 99);
     40     assert_eq!(draft.expected_pubkey, "a".repeat(64));
     41     assert_eq!(draft.content, "hello");
     42     assert_eq!(draft.tags.len(), 1);
     43     assert_eq!(draft.expected_event_id.len(), 64);
     44 }
     45 
     46 #[test]
     47 fn empty_content_is_empty_string() {
     48     let content = empty_content();
     49     assert!(content.is_empty());
     50 }