From 283d06bb0804558b43e1c07852f277465a9b1176 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 27 Jan 2020 23:48:41 -0500 Subject: [PATCH] Add (de)serialization roundtrip proptext for shielded_data::(Encrypted,Out)Ciphertext --- zebra-chain/src/transaction/shielded_data.rs | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/zebra-chain/src/transaction/shielded_data.rs b/zebra-chain/src/transaction/shielded_data.rs index deb4c565c..78d348fbe 100644 --- a/zebra-chain/src/transaction/shielded_data.rs +++ b/zebra-chain/src/transaction/shielded_data.rs @@ -327,3 +327,31 @@ impl Arbitrary for OutCiphertext { type Strategy = BoxedStrategy; } + +#[cfg(test)] +proptest! { + + #[test] + fn encrypted_ciphertext_roundtrip(ec in any::()) { + + let mut data = Vec::new(); + + ec.zcash_serialize(&mut data).expect("EncryptedCiphertext should serialize"); + + let ec2 = EncryptedCiphertext::zcash_deserialize(&data[..]).expect("randomized EncryptedCiphertext should deserialize"); + + prop_assert_eq![ec, ec2]; + } + + #[test] + fn out_ciphertext_roundtrip(oc in any::()) { + + let mut data = Vec::new(); + + oc.zcash_serialize(&mut data).expect("OutCiphertext should serialize"); + + let oc2 = OutCiphertext::zcash_deserialize(&data[..]).expect("randomized OutCiphertext should deserialize"); + + prop_assert_eq![oc, oc2]; + } +}