Skip to content

Commit

Permalink
test keypair generation
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Apr 12, 2023
1 parent 9b91b9f commit d2b6c30
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ferveo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ ark-serialize = {version = "0.4", features = ["derive"]}
serde_with = "2.2.0"
bincode = "1.3.3"
rand = "0.8"
rand_core = "0.6"
rand_core = "0.6"

[dev-dependencies]
ark-bls12-381 = "0.4.0"
21 changes: 21 additions & 0 deletions ferveo-common/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,24 @@ impl<E: Pairing> Keypair<E> {
Ok(Self::new(&mut rng))
}
}

#[cfg(test)]
mod tests {
use super::*;

type E = ark_bls12_381::Bls12_381;

#[test]
fn test_secure_randomness_generation() {
let bytes = [0u8; 32];
let keypair = Keypair::<E>::from_secure_randomness(&bytes);
assert!(keypair.is_ok());
}

#[test]
fn test_secure_randomness_generation_with_invalid_length() {
let bytes = [0u8; 31];
let keypair = Keypair::<E>::from_secure_randomness(&bytes);
assert!(keypair.is_err());
}
}

0 comments on commit d2b6c30

Please sign in to comment.