Skip to content

Commit

Permalink
Merge pull request #423 from nuttycom/merkle_hash_orchard_dist
Browse files Browse the repository at this point in the history
Add `impl Distribution<MerkleHashOrchard> for Standard` for testing.
  • Loading branch information
nuttycom authored Mar 19, 2024
2 parents e74879d + 1b6c078 commit 33474bd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down

0 comments on commit 33474bd

Please sign in to comment.