Skip to main content

zebra_chain/parameters/
arbitrary.rs

1//! Arbitrary implementations for network parameters
2
3use proptest::prelude::*;
4
5use super::{Network, NetworkUpgrade};
6
7impl NetworkUpgrade {
8    /// Generates network upgrades.
9    pub fn branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
10        prop_oneof![
11            Just(NetworkUpgrade::Overwinter),
12            Just(NetworkUpgrade::Sapling),
13            Just(NetworkUpgrade::Blossom),
14            Just(NetworkUpgrade::Heartwood),
15            Just(NetworkUpgrade::Canopy),
16            Just(NetworkUpgrade::Nu5),
17            // TODO: add future network upgrades (#1974)
18        ]
19        .boxed()
20    }
21
22    /// Generates network upgrades that are valid for V5+ transactions (Nu5 onward).
23    pub fn nu5_branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
24        prop_oneof![
25            Just(NetworkUpgrade::Nu5),
26            Just(NetworkUpgrade::Nu6),
27            Just(NetworkUpgrade::Nu6_1),
28            Just(NetworkUpgrade::Nu6_2),
29            Just(NetworkUpgrade::Nu6_3),
30            Just(NetworkUpgrade::Nu7),
31        ]
32        .boxed()
33    }
34
35    /// Generates network upgrades that are valid for V6 transactions (NU6.3 onward).
36    pub fn nu6_3_branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
37        prop_oneof![Just(NetworkUpgrade::Nu6_3), Just(NetworkUpgrade::Nu7),].boxed()
38    }
39
40    /// Generates network upgrades from a reduced set
41    pub fn reduced_branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
42        // Used to give a transaction a consensus branch id that is inconsistent with its block
43        // height. The upgrades must be NU5 or later so the resulting v5 transactions are still
44        // well-formed and can be assigned a txid by `zcash_primitives`.
45        prop_oneof![
46            Just(NetworkUpgrade::Nu6),
47            Just(NetworkUpgrade::Nu6_1),
48            Just(NetworkUpgrade::Nu6_2),
49        ]
50        .boxed()
51    }
52}
53
54impl Arbitrary for Network {
55    type Parameters = ();
56
57    fn arbitrary_with(_args: ()) -> Self::Strategy {
58        prop_oneof![Just(Self::Mainnet), Just(Self::new_default_testnet())].boxed()
59    }
60
61    type Strategy = BoxedStrategy<Self>;
62}