Skip to content

Commit

Permalink
Add impl Distribution<MerkleHashOrchard> for Standard for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Mar 18, 2024
1 parent e74879d commit 1b6c078
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 1b6c078

Please sign in to comment.