From dee71eee99db321adda534fe121f25cb8b51f912 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Sat, 16 Mar 2024 08:54:13 -0600 Subject: [PATCH] Add `Node::random` and `Distribution for Standard` for testing. --- src/tree.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tree.rs b/src/tree.rs index 53e609c..1efb9d5 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -171,7 +171,9 @@ impl From 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 for Standard { + fn sample(&self, rng: &mut R) -> Node { + Node::from_scalar(bls12_381::Scalar::random(rng)) + } + } }