Skip to content

Commit

Permalink
Added tests for the serde implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
d-sonuga committed Nov 27, 2024
1 parent e34731a commit ed52ff1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
30 changes: 23 additions & 7 deletions tests/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,27 @@ fn apk_identity_fails() {
}

#[cfg(feature = "serde")]
#[test]
fn pk_serde() {
let mut rng = StdRng::seed_from_u64(42);
let pk = PublicKey::from(&SecretKey::random(&mut rng));
let ser = serde_json::to_string(&pk);
let deser = serde_json::from_str(&ser.unwrap());
assert_eq!(pk, deser.unwrap());
mod serde_support {
use super::*;

#[test]
fn pk() {
let mut rng = StdRng::seed_from_u64(42);
let pk = PublicKey::from(&SecretKey::random(&mut rng));
let ser = serde_json::to_string(&pk);
let deser = serde_json::from_str(&ser.unwrap());
assert_eq!(pk, deser.unwrap());
}

#[test]
fn multisig_pk() {
let mut rng = StdRng::seed_from_u64(42);
let pk = MultisigPublicKey::aggregate(&[PublicKey::from(
&SecretKey::random(&mut rng),
)])
.unwrap();
let ser = serde_json::to_string(&pk);
let deser = serde_json::from_str(&ser.unwrap());
assert_eq!(pk, deser.unwrap());
}
}
26 changes: 26 additions & 0 deletions tests/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,29 @@ fn random_message(rng: &mut StdRng) -> [u8; 100] {

msg
}

#[cfg(feature = "serde")]
mod serde_support {
use super::*;

#[test]
fn signature() {
let mut rng = StdRng::seed_from_u64(42);
let sk = SecretKey::random(&mut rng);
let signature = sk.sign(b"a message");
let ser = serde_json::to_string(&signature);
let deser = serde_json::from_str(&ser.unwrap());
assert_eq!(signature, deser.unwrap());
}

#[test]
fn multisig_signature() {
let mut rng = StdRng::seed_from_u64(42);
let sk = SecretKey::random(&mut rng);
let pk = PublicKey::from(&sk);
let signature = sk.sign_multisig(&pk, b"a message");
let ser = serde_json::to_string(&signature);
let deser = serde_json::from_str(&ser.unwrap());
assert_eq!(signature, deser.unwrap());
}
}

0 comments on commit ed52ff1

Please sign in to comment.