From eb5b3dfefc30cc19c062304c9bc83e73f3480a74 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 31 Dec 2019 15:37:31 -0500 Subject: [PATCH] Add zcash_[de]serialize roundtrip proptest for Script type --- zebra-chain/src/types.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/zebra-chain/src/types.rs b/zebra-chain/src/types.rs index 7a5dbca2..53943324 100644 --- a/zebra-chain/src/types.rs +++ b/zebra-chain/src/types.rs @@ -8,6 +8,8 @@ use std::{ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use chrono::{DateTime, TimeZone, Utc}; use hex; +#[cfg(test)] +use proptest_derive::Arbitrary; use crate::serialization::{ ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, @@ -83,6 +85,7 @@ impl ZcashDeserialize for LockTime { /// An encoding of a Bitcoin script. #[derive(Clone, Debug, Eq, PartialEq)] +#[cfg_attr(test, derive(Arbitrary))] pub struct Script(pub Vec); impl ZcashSerialize for Script { @@ -133,7 +136,7 @@ mod proptest { use chrono::{TimeZone, Utc}; use proptest::prelude::*; - use super::{BlockHeight, LockTime}; + use super::{BlockHeight, LockTime, Script}; use crate::serialization::{ZcashDeserialize, ZcashSerialize}; impl Arbitrary for LockTime { @@ -163,8 +166,17 @@ mod proptest { let other_locktime = LockTime::zcash_deserialize(&mut bytes)?; prop_assert_eq![locktime, other_locktime]; + } + #[test] + fn script_roundtrip(script in any::