Add `impl Distribution<MerkleHashOrchard> for Standard` for testing.

This commit is contained in:
Kris Nuttycombe 2024-03-16 08:38:10 -06:00
parent e74879dd0a
commit 1b6c078942
1 changed files with 11 additions and 2 deletions

View File

@ -264,14 +264,23 @@ impl<'de> Deserialize<'de> for MerkleHashOrchard {
#[cfg(feature = "test-dependencies")]
pub mod testing {
use ff::Field;
use rand::RngCore;
use rand::{
distributions::{Distribution, Standard},
RngCore,
};
use super::MerkleHashOrchard;
impl MerkleHashOrchard {
/// Return a random fake `MerkleHashOrchard`.
pub fn random(rng: &mut impl RngCore) -> Self {
Self(pasta_curves::Fp::random(rng))
Standard.sample(rng)
}
}
impl Distribution<MerkleHashOrchard> for Standard {
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> MerkleHashOrchard {
MerkleHashOrchard(pasta_curves::Fp::random(rng))
}
}
}