lib

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

tests.rs (2332B)


      1 use super::*;
      2 
      3 #[test]
      4 fn admitted_contract_resolves_registry_entry() {
      5     use crate::test_fixtures::FIXTURE_ALICE_SECRET_KEY_HEX;
      6     use nostr::secp256k1::Message;
      7     use nostr::{Keys, SECP256K1};
      8     use radroots_event::{
      9         envelope::EventEnvelopeParts, envelope::kind::KIND_DELETION_REQUEST,
     10         wire::compute_canonical_nip01_event_id,
     11     };
     12 
     13     let keys =
     14         Keys::parse(FIXTURE_ALICE_SECRET_KEY_HEX).expect("fixed fixture secret key must parse");
     15     let author = keys.public_key().to_string();
     16     let created_at = 1_800_000_300;
     17     let tags = vec![vec!["e".to_string(), "a".repeat(64)]];
     18     let content = "superseded";
     19     let id = compute_canonical_nip01_event_id(
     20         author.as_str(),
     21         created_at,
     22         KIND_DELETION_REQUEST,
     23         &tags,
     24         content,
     25     )
     26     .expect("canonical deletion request id");
     27     let nostr_id = nostr::EventId::from_hex(&id.to_hex()).expect("Nostr event id");
     28     let message = Message::from_digest(nostr_id.to_bytes());
     29     let signature = SECP256K1.sign_schnorr_no_aux_rand(
     30         &message,
     31         &nostr::secp256k1::Keypair::from_secret_key(SECP256K1, keys.secret_key()),
     32     );
     33     let event = EventEnvelope::new(EventEnvelopeParts {
     34         id: id.into_string(),
     35         author,
     36         created_at,
     37         kind: KIND_DELETION_REQUEST,
     38         tags,
     39         content: content.to_string(),
     40         sig: signature.to_string(),
     41     })
     42     .expect("valid deletion request envelope");
     43 
     44     let admitted =
     45         verify_and_admit_nip09_deletion_request_event(event).expect("admitted deletion request");
     46 
     47     assert_eq!(
     48         admitted.contract().id,
     49         "radroots.social.deletion_request.v1"
     50     );
     51     assert_eq!(admitted.contract().kind, KIND_DELETION_REQUEST);
     52 }
     53 
     54 #[test]
     55 fn stable_error_codes_delegate_to_verification_and_projection() {
     56     let verification = RadrootsNip09DeletionAdmissionError::Nip01Verification(
     57         RadrootsNip01VerificationError::SignatureInvalid,
     58     );
     59     let projection = RadrootsNip09DeletionAdmissionError::Projection(
     60         RadrootsNip09DeletionProjectionError::TargetMissing,
     61     );
     62     assert_eq!(verification.code(), "signature_invalid");
     63     assert_eq!(projection.code(), "deletion_target_missing");
     64     assert!(!verification.to_string().is_empty());
     65     assert!(!projection.to_string().is_empty());
     66 }