Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse ConsensusBranchId into NetworkUpgrade for transaction v5 #2075

Merged
merged 13 commits into from
Apr 29, 2021
35 changes: 14 additions & 21 deletions zebra-chain/src/transaction/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Transaction {
/// Generate a proptest strategy for V5 Transactions
pub fn v5_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
(
any::<NetworkUpgrade>(),
Self::branch_id_strategy(),
any::<LockTime>(),
any::<block::Height>(),
transparent::Input::vec_strategy(ledger_state, 10),
Expand Down Expand Up @@ -132,6 +132,19 @@ impl Transaction {
.boxed()
}

// A custom strategy to use only some of the NetworkUpgrade values
fn branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
prop_oneof![
Just(NetworkUpgrade::Overwinter),
Just(NetworkUpgrade::Sapling),
Just(NetworkUpgrade::Blossom),
Just(NetworkUpgrade::Heartwood),
Just(NetworkUpgrade::Canopy),
Just(NetworkUpgrade::Nu5),
]
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
.boxed()
}

/// Proptest Strategy for creating a Vector of transactions where the first
/// transaction is always the only coinbase transaction
pub fn vec_strategy(
Expand Down Expand Up @@ -186,26 +199,6 @@ impl Arbitrary for LockTime {
type Strategy = BoxedStrategy<Self>;
}

// We manually implement here because not all the values from the
// `NetworkUpgrade` are valid.
impl Arbitrary for NetworkUpgrade {
type Parameters = ();

fn arbitrary_with(_args: ()) -> Self::Strategy {
prop_oneof![
Just(NetworkUpgrade::Overwinter),
Just(NetworkUpgrade::Sapling),
Just(NetworkUpgrade::Blossom),
Just(NetworkUpgrade::Heartwood),
Just(NetworkUpgrade::Canopy),
Just(NetworkUpgrade::Nu5),
]
.boxed()
}

type Strategy = BoxedStrategy<Self>;
}

impl<P: ZkSnarkProof + Arbitrary + 'static> Arbitrary for JoinSplitData<P> {
type Parameters = ();

Expand Down