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 that are valid for V6 transactions (NU6.3 onward).
32 ///
33 /// Does not generate `Nu7`: its consensus branch ID is still a placeholder that
34 /// librustzcash does not recognise, so transactions carrying it cannot round-trip
35 /// through `to_librustzcash` (which computes txids and auth digests).
36 pub fn nu6_3_branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
37 prop_oneof![
38 Just(NetworkUpgrade::Nu6_3),
39 // TODO: add Nu7 once its consensus branch ID is set in librustzcash
40 ]
41 .boxed()
42 }
43
44 /// Generates network upgrades from a reduced set
45 pub fn reduced_branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
46 // Used to give a transaction a consensus branch id that is inconsistent with its block
47 // height. The upgrades must be NU5 or later so the resulting v5 transactions are still
48 // well-formed and can be assigned a txid by `zcash_primitives`.
49 prop_oneof![
50 Just(NetworkUpgrade::Nu6),
51 Just(NetworkUpgrade::Nu6_1),
52 Just(NetworkUpgrade::Nu6_2),
53 ]
54 .boxed()
55 }
56}
57
58impl Arbitrary for Network {
59 type Parameters = ();
60
61 fn arbitrary_with(_args: ()) -> Self::Strategy {
62 prop_oneof![Just(Self::Mainnet), Just(Self::new_default_testnet())].boxed()
63 }
64
65 type Strategy = BoxedStrategy<Self>;
66}