From 76328634548b0301aaf08c324c79fa5e78f1d834 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 27 Jan 2020 17:47:20 -0500 Subject: [PATCH] Impl Arbitrary for JoinSplitData

Wraps the construction of ed25519 PublicKeyBytes and Signature so we don't need an explicit impl for ed25519 types. --- zebra-chain/src/transaction/joinsplit.rs | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/zebra-chain/src/transaction/joinsplit.rs b/zebra-chain/src/transaction/joinsplit.rs index a2b38995f..008fd799a 100644 --- a/zebra-chain/src/transaction/joinsplit.rs +++ b/zebra-chain/src/transaction/joinsplit.rs @@ -64,7 +64,6 @@ pub struct JoinSplit { /// A bundle of JoinSplit descriptions and signature data. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(test, derive(Arbitrary))] pub struct JoinSplitData { /// The first JoinSplit description, using proofs of type `P`. /// @@ -93,6 +92,31 @@ impl JoinSplitData

{ } } +#[cfg(test)] +impl Arbitrary for JoinSplitData

{ + type Parameters = (); + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + ( + any::>(), + vec(any::>()), + vec(any::(), 32), + vec(any::(), 64), + ) + .prop_map(|first, rest, pub_key_bytes, sig_bytes| { + return Self { + first: first, + rest: rest, + pub_key: ed25519_zebra::PublicKeyBytes::from(pub_key_bytes), + sig: ed25519_zebra::Signature::from(sig_bytes), + }; + }) + .boxed() + } + + type Strategy = BoxedStrategy; +} + /// A ciphertext component for encrypted output notes. pub struct EncryptedCiphertext(pub [u8; 601]);