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 16, 2024
1 parent e74879d commit fca9ec6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,20 @@ impl<'de> Deserialize<'de> for MerkleHashOrchard {
#[cfg(feature = "test-dependencies")]
pub mod testing {
use ff::Field;
use rand::RngCore;
use rand::{RngCore, distributions::{Standard, Distribution}};

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 fca9ec6

Please sign in to comment.