Merge pull request #423 from nuttycom/merkle_hash_orchard_dist

Add `impl Distribution<MerkleHashOrchard> for Standard` for testing.
This commit is contained in:
Kris Nuttycombe 2024-03-19 12:34:27 -06:00 committed by GitHub
commit 33474bdbfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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))
}
}
}