Compare commits

...

2 Commits

Author SHA1 Message Date
Kris Nuttycombe 33474bdbfd
Merge pull request #423 from nuttycom/merkle_hash_orchard_dist
Add `impl Distribution<MerkleHashOrchard> for Standard` for testing.
2024-03-19 12:34:27 -06:00
Kris Nuttycombe 1b6c078942 Add `impl Distribution<MerkleHashOrchard> for Standard` for testing. 2024-03-18 08:54:10 -06:00
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))
}
}
}