Refine Arbitrary impl for JoinSplitData<P>

This commit is contained in:
Deirdre Connolly 2020-01-27 23:22:33 -05:00 committed by Deirdre Connolly
parent 90086d4d2d
commit f8781c3415
2 changed files with 10 additions and 7 deletions

View File

@ -51,7 +51,6 @@ impl ZcashDeserialize for Groth16Proof {
} }
} }
#[cfg(test)] #[cfg(test)]
impl Arbitrary for Groth16Proof { impl Arbitrary for Groth16Proof {
type Parameters = (); type Parameters = ();

View File

@ -4,7 +4,7 @@ use std::{
}; };
#[cfg(test)] #[cfg(test)]
use proptest::{collection::vec, prelude::*}; use proptest::{array, collection::vec, prelude::*};
#[cfg(test)] #[cfg(test)]
use proptest_derive::Arbitrary; use proptest_derive::Arbitrary;
@ -93,22 +93,26 @@ impl<P: ZkSnarkProof> JoinSplitData<P> {
} }
#[cfg(test)] #[cfg(test)]
impl<P: ZkSnarkProof> Arbitrary for JoinSplitData<P> { impl<P: ZkSnarkProof + Arbitrary + 'static> Arbitrary for JoinSplitData<P> {
type Parameters = (); type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
( (
any::<JoinSplit<P>>(), any::<JoinSplit<P>>(),
vec(any::<JoinSplit<P>>()), vec(any::<JoinSplit<P>>(), 0..10),
vec(any::<u8>(), 32), array::uniform32(any::<u8>()),
vec(any::<u8>(), 64), vec(any::<u8>(), 64),
) )
.prop_map(|first, rest, pub_key_bytes, sig_bytes| { .prop_map(|(first, rest, pub_key_bytes, sig_bytes)| {
return Self { return Self {
first: first, first: first,
rest: rest, rest: rest,
pub_key: ed25519_zebra::PublicKeyBytes::from(pub_key_bytes), pub_key: ed25519_zebra::PublicKeyBytes::from(pub_key_bytes),
sig: ed25519_zebra::Signature::from(sig_bytes), sig: ed25519_zebra::Signature::from({
let mut b = [0u8; 64];
b.copy_from_slice(sig_bytes.as_slice());
b
}),
}; };
}) })
.boxed() .boxed()