use proptest::{prelude::*, proptest};
use crate::{
block::MAX_BLOCK_BYTES,
primitives::{Bctv14Proof, Groth16Proof},
serialization::{arbitrary::max_allocation_is_big_enough, TrustedPreallocate, ZcashSerialize},
sprout::joinsplit::{JoinSplit, BCTV14_JOINSPLIT_SIZE, GROTH16_JOINSPLIT_SIZE},
};
proptest! {
#[test]
fn joinsplit_btcv14_size_is_correct(joinsplit in <JoinSplit<Bctv14Proof>>::arbitrary_with(())) {
let serialized = joinsplit.zcash_serialize_to_vec().expect("Serialization to vec must succeed");
prop_assert!(serialized.len() as u64 == BCTV14_JOINSPLIT_SIZE)
}
#[test]
fn joinsplit_groth16_size_is_correct(joinsplit in <JoinSplit<Groth16Proof>>::arbitrary_with(())) {
let serialized = joinsplit.zcash_serialize_to_vec().expect("Serialization to vec must succeed");
prop_assert!(serialized.len() as u64 == GROTH16_JOINSPLIT_SIZE)
}
}
proptest! {
#![proptest_config(ProptestConfig::with_cases(128))]
#[test]
fn joinsplit_btcv14_max_allocation_is_correct(joinsplit in <JoinSplit<Bctv14Proof>>::arbitrary_with(())) {
let (
smallest_disallowed_vec_len,
smallest_disallowed_serialized_len,
largest_allowed_vec_len,
largest_allowed_serialized_len,
) = max_allocation_is_big_enough(joinsplit);
prop_assert!(((smallest_disallowed_vec_len - 1) as u64) == <JoinSplit<Bctv14Proof>>::max_allocation());
prop_assert!(smallest_disallowed_serialized_len as u64 > MAX_BLOCK_BYTES);
prop_assert!((largest_allowed_vec_len as u64) == <JoinSplit<Bctv14Proof>>::max_allocation());
prop_assert!(largest_allowed_serialized_len as u64 <= MAX_BLOCK_BYTES);
}
#[test]
fn joinsplit_groth16_max_allocation_is_correct(joinsplit in <JoinSplit<Groth16Proof>>::arbitrary_with(())) {
let (
smallest_disallowed_vec_len,
smallest_disallowed_serialized_len,
largest_allowed_vec_len,
largest_allowed_serialized_len,
) = max_allocation_is_big_enough(joinsplit);
prop_assert!(((smallest_disallowed_vec_len - 1) as u64) == <JoinSplit<Groth16Proof>>::max_allocation());
prop_assert!(smallest_disallowed_serialized_len as u64 > MAX_BLOCK_BYTES);
prop_assert!((largest_allowed_vec_len as u64) == <JoinSplit<Groth16Proof>>::max_allocation());
prop_assert!(largest_allowed_serialized_len as u64 <= MAX_BLOCK_BYTES);
}
}