diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 5170adf6..e5d603d1 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -8,8 +8,6 @@ mod serialize; mod shielded_data; mod transparent; -#[cfg(test)] -mod test_vectors; #[cfg(test)] mod tests; diff --git a/zebra-chain/src/transaction/joinsplit.rs b/zebra-chain/src/transaction/joinsplit.rs index 1eb5be1e..8a530a74 100644 --- a/zebra-chain/src/transaction/joinsplit.rs +++ b/zebra-chain/src/transaction/joinsplit.rs @@ -1,8 +1,5 @@ -#[cfg(test)] -use proptest::{array, collection::vec, prelude::*}; -use serde::{Deserialize, Serialize}; - use crate::{ed25519_zebra, notes::sprout, proofs::ZkSnarkProof}; +use serde::{Deserialize, Serialize}; /// A _JoinSplit Description_, as described in [protocol specification §7.2][ps]. /// @@ -70,56 +67,6 @@ impl PartialEq for JoinSplit

{ // Because x25519_dalek::PublicKey does not impl Eq impl Eq for JoinSplit

{} -#[cfg(test)] -impl Arbitrary for JoinSplit

{ - type Parameters = (); - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - ( - any::(), - any::(), - array::uniform32(any::()), - array::uniform2(array::uniform32(any::())), - array::uniform2(array::uniform32(any::())), - array::uniform32(any::()), - array::uniform32(any::()), - array::uniform2(array::uniform32(any::())), - any::

(), - array::uniform2(any::()), - ) - .prop_map( - |( - vpub_old, - vpub_new, - anchor, - nullifiers, - commitments, - ephemeral_key_bytes, - random_seed, - vmacs, - zkproof, - enc_ciphertexts, - )| { - Self { - vpub_old, - vpub_new, - anchor, - nullifiers, - commitments, - ephemeral_key: x25519_dalek::PublicKey::from(ephemeral_key_bytes), - random_seed, - vmacs, - zkproof, - enc_ciphertexts, - } - }, - ) - .boxed() - } - - type Strategy = BoxedStrategy; -} - /// A bundle of JoinSplit descriptions and signature data. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct JoinSplitData { @@ -157,30 +104,3 @@ impl JoinSplitData

{ std::iter::once(&self.first).chain(self.rest.iter()) } } - -#[cfg(test)] -impl Arbitrary for JoinSplitData

{ - type Parameters = (); - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - ( - any::>(), - vec(any::>(), 0..10), - array::uniform32(any::()), - vec(any::(), 64), - ) - .prop_map(|(first, rest, pub_key_bytes, sig_bytes)| Self { - first, - rest, - pub_key: ed25519_zebra::VerificationKeyBytes::from(pub_key_bytes), - sig: ed25519_zebra::Signature::from({ - let mut b = [0u8; 64]; - b.copy_from_slice(sig_bytes.as_slice()); - b - }), - }) - .boxed() - } - - type Strategy = BoxedStrategy; -} diff --git a/zebra-chain/src/transaction/shielded_data.rs b/zebra-chain/src/transaction/shielded_data.rs index b680efb5..3776c235 100644 --- a/zebra-chain/src/transaction/shielded_data.rs +++ b/zebra-chain/src/transaction/shielded_data.rs @@ -1,14 +1,10 @@ -use futures::future::Either; - -#[cfg(test)] -use proptest::{arbitrary::Arbitrary, array, collection::vec, prelude::*}; - // XXX this name seems too long? use crate::note_commitment_tree::SaplingNoteTreeRootHash; use crate::notes::sapling; use crate::proofs::Groth16Proof; use crate::redjubjub::{self, Binding, SpendAuth}; use crate::serde_helpers; +use futures::future::Either; /// A _Spend Description_, as described in [protocol specification §7.3][ps]. /// @@ -33,39 +29,6 @@ pub struct Spend { pub spend_auth_sig: redjubjub::Signature, } -#[cfg(test)] -impl Arbitrary for Spend { - type Parameters = (); - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - ( - array::uniform32(any::()), - any::(), - array::uniform32(any::()), - array::uniform32(any::()), - any::(), - vec(any::(), 64), - ) - .prop_map( - |(cv_bytes, anchor, nullifier_bytes, rpk_bytes, proof, sig_bytes)| Self { - anchor, - cv: cv_bytes, - nullifier: nullifier_bytes, - rk: redjubjub::PublicKeyBytes::from(rpk_bytes), - zkproof: proof, - spend_auth_sig: redjubjub::Signature::from({ - let mut b = [0u8; 64]; - b.copy_from_slice(sig_bytes.as_slice()); - b - }), - }, - ) - .boxed() - } - - type Strategy = BoxedStrategy; -} - /// A _Output Description_, as described in [protocol specification §7.4][ps]. /// /// [ps]: https://zips.z.cash/protocol/protocol.pdf#outputencoding @@ -92,37 +55,6 @@ pub struct Output { impl Eq for Output {} -#[cfg(test)] -impl Arbitrary for Output { - type Parameters = (); - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - ( - array::uniform32(any::()), - array::uniform32(any::()), - array::uniform32(any::()).prop_filter("Valid jubjub::AffinePoint", |b| { - jubjub::AffinePoint::from_bytes(*b).is_some().unwrap_u8() == 1 - }), - any::(), - any::(), - any::(), - ) - .prop_map( - |(cv, cmu, ephemeral_key_bytes, enc_ciphertext, out_ciphertext, zkproof)| Self { - cv, - cmu, - ephemeral_key: jubjub::AffinePoint::from_bytes(ephemeral_key_bytes).unwrap(), - enc_ciphertext, - out_ciphertext, - zkproof, - }, - ) - .boxed() - } - - type Strategy = BoxedStrategy; -} - /// Sapling-on-Groth16 spend and output descriptions. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ShieldedData { @@ -197,33 +129,3 @@ impl std::cmp::PartialEq for ShieldedData { } impl std::cmp::Eq for ShieldedData {} - -#[cfg(test)] -impl Arbitrary for ShieldedData { - type Parameters = (); - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - ( - prop_oneof![ - any::().prop_map(Either::Left), - any::().prop_map(Either::Right) - ], - vec(any::(), 0..10), - vec(any::(), 0..10), - vec(any::(), 64), - ) - .prop_map(|(first, rest_spends, rest_outputs, sig_bytes)| Self { - first, - rest_spends, - rest_outputs, - binding_sig: redjubjub::Signature::from({ - let mut b = [0u8; 64]; - b.copy_from_slice(sig_bytes.as_slice()); - b - }), - }) - .boxed() - } - - type Strategy = BoxedStrategy; -} diff --git a/zebra-chain/src/transaction/tests.rs b/zebra-chain/src/transaction/tests.rs index ed78f0dd..73872bc7 100644 --- a/zebra-chain/src/transaction/tests.rs +++ b/zebra-chain/src/transaction/tests.rs @@ -1,18 +1,15 @@ -use proptest::{ - arbitrary::{any, Arbitrary}, - collection::vec, - option, - prelude::*, -}; +use proptest::{arbitrary::any, collection::vec, option, prelude::*}; use crate::{ serialization::{ZcashDeserialize, ZcashSerialize}, - types::{LockTime, Script}, + types::LockTime, }; use super::*; -#[cfg(test)] +mod arbitrary; +mod test_vectors; + impl Transaction { pub fn v1_strategy() -> impl Strategy { ( @@ -99,54 +96,6 @@ impl Transaction { } } -#[cfg(test)] -impl Arbitrary for Transaction { - type Parameters = (); - - fn arbitrary_with(_args: ()) -> Self::Strategy { - prop_oneof![ - Self::v1_strategy(), - Self::v2_strategy(), - Self::v3_strategy(), - Self::v4_strategy() - ] - .boxed() - } - - type Strategy = BoxedStrategy; -} - -#[cfg(test)] -impl Arbitrary for TransparentInput { - type Parameters = (); - - fn arbitrary_with(_args: ()) -> Self::Strategy { - prop_oneof![ - (any::(), any::