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            // TODO: add future network upgrades (#1974)
27        ]
28        .boxed()
29    }
30
31    /// Generates network upgrades from a reduced set
32    pub fn reduced_branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
33        // We use this strategy to test legacy chain
34        // TODO: We can add Canopy after we have a NU5 activation height
35        prop_oneof![
36            Just(NetworkUpgrade::Overwinter),
37            Just(NetworkUpgrade::Sapling),
38            Just(NetworkUpgrade::Blossom),
39            Just(NetworkUpgrade::Heartwood),
40        ]
41        .boxed()
42    }
43}
44
45impl Arbitrary for Network {
46    type Parameters = ();
47
48    fn arbitrary_with(_args: ()) -> Self::Strategy {
49        prop_oneof![Just(Self::Mainnet), Just(Self::new_default_testnet())].boxed()
50    }
51
52    type Strategy = BoxedStrategy<Self>;
53}