Add `Node::random` and `Distribution<Node> for Standard` for testing.
This commit is contained in:
parent
2122dbed71
commit
dee71eee99
15
src/tree.rs
15
src/tree.rs
|
@ -171,7 +171,9 @@ impl From<Node> for bls12_381::Scalar {
|
|||
|
||||
#[cfg(any(test, feature = "test-dependencies"))]
|
||||
pub(super) mod testing {
|
||||
use ff::Field;
|
||||
use proptest::prelude::*;
|
||||
use rand::distributions::{Distribution, Standard};
|
||||
|
||||
use super::Node;
|
||||
use crate::note::testing::arb_cmu;
|
||||
|
@ -181,4 +183,17 @@ pub(super) mod testing {
|
|||
Node::from_cmu(&cmu)
|
||||
}
|
||||
}
|
||||
|
||||
impl Node {
|
||||
/// Return a random fake `MerkleHashOrchard`.
|
||||
pub fn random(rng: &mut impl RngCore) -> Self {
|
||||
Standard.sample(rng)
|
||||
}
|
||||
}
|
||||
|
||||
impl Distribution<Node> for Standard {
|
||||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Node {
|
||||
Node::from_scalar(bls12_381::Scalar::random(rng))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue