Proptest v1 and v2 transaction variants
This commit is contained in:
parent
31b759a924
commit
9cbc60a2d7
File diff suppressed because one or more lines are too long
|
@ -5,6 +5,7 @@ use chrono::{TimeZone, Utc};
|
||||||
use proptest::{
|
use proptest::{
|
||||||
arbitrary::{any, Arbitrary},
|
arbitrary::{any, Arbitrary},
|
||||||
collection::vec,
|
collection::vec,
|
||||||
|
option,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,10 +17,8 @@ use crate::{
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl Arbitrary for Transaction {
|
impl Transaction {
|
||||||
type Parameters = ();
|
pub fn v1_strategy() -> impl Strategy<Value = Self> {
|
||||||
|
|
||||||
fn arbitrary_with(_args: ()) -> Self::Strategy {
|
|
||||||
(
|
(
|
||||||
vec(any::<TransparentInput>(), 0..10),
|
vec(any::<TransparentInput>(), 0..10),
|
||||||
vec(any::<TransparentOutput>(), 0..10),
|
vec(any::<TransparentOutput>(), 0..10),
|
||||||
|
@ -33,6 +32,33 @@ impl Arbitrary for Transaction {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn v2_strategy() -> impl Strategy<Value = Self> {
|
||||||
|
(
|
||||||
|
vec(any::<TransparentInput>(), 0..10),
|
||||||
|
vec(any::<TransparentOutput>(), 0..10),
|
||||||
|
any::<LockTime>(),
|
||||||
|
option::of(any::<JoinSplitData<Bctv14Proof>>()),
|
||||||
|
)
|
||||||
|
.prop_map(
|
||||||
|
|(inputs, outputs, lock_time, joinsplit_data)| Transaction::V2 {
|
||||||
|
inputs: inputs,
|
||||||
|
outputs: outputs,
|
||||||
|
lock_time: lock_time,
|
||||||
|
joinsplit_data: joinsplit_data,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.boxed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl Arbitrary for Transaction {
|
||||||
|
type Parameters = ();
|
||||||
|
|
||||||
|
fn arbitrary_with(_args: ()) -> Self::Strategy {
|
||||||
|
prop_oneof![Self::v1_strategy(), Self::v2_strategy()].boxed()
|
||||||
|
}
|
||||||
|
|
||||||
type Strategy = BoxedStrategy<Self>;
|
type Strategy = BoxedStrategy<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,12 +221,16 @@ proptest! {
|
||||||
#[test]
|
#[test]
|
||||||
fn transaction_roundtrip(tx in any::<Transaction>()) {
|
fn transaction_roundtrip(tx in any::<Transaction>()) {
|
||||||
|
|
||||||
|
println!("{:?}", tx);
|
||||||
|
|
||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
|
|
||||||
tx.zcash_serialize(&mut data).expect("tx should serialize");
|
tx.zcash_serialize(&mut data).expect("tx should serialize");
|
||||||
|
|
||||||
let tx2 = Transaction::zcash_deserialize(&data[..]).expect("randomized tx should deserialize");
|
let tx2 = Transaction::zcash_deserialize(&data[..]).expect("randomized tx should deserialize");
|
||||||
|
|
||||||
|
println!("{:?}", tx2);
|
||||||
|
|
||||||
prop_assert_eq![tx, tx2];
|
prop_assert_eq![tx, tx2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue