light_program_test/program_test/
config.rs

1use account_compression::{
2    AddressMerkleTreeConfig, AddressQueueConfig, NullifierQueueConfig, StateMerkleTreeConfig,
3};
4use light_batched_merkle_tree::{
5    initialize_address_tree::InitAddressTreeAccountsInstructionData,
6    initialize_state_tree::InitStateTreeAccountsInstructionData,
7};
8use light_prover_client::prover::ProverConfig;
9use light_registry::protocol_config::state::ProtocolConfig;
10use solana_sdk::pubkey::Pubkey;
11
12#[derive(Debug, Clone)]
13pub struct ProgramTestConfig {
14    pub additional_programs: Option<Vec<(&'static str, Pubkey)>>,
15    pub protocol_config: ProtocolConfig,
16    pub with_prover: bool,
17    pub prover_config: Option<ProverConfig>,
18    pub skip_register_programs: bool,
19    pub skip_v1_trees: bool,
20    pub skip_second_v1_tree: bool,
21    pub v1_state_tree_config: StateMerkleTreeConfig,
22    pub v1_nullifier_queue_config: NullifierQueueConfig,
23    pub v1_address_tree_config: AddressMerkleTreeConfig,
24    pub v1_address_queue_config: AddressQueueConfig,
25    pub v2_state_tree_config: Option<InitStateTreeAccountsInstructionData>,
26    pub v2_address_tree_config: Option<InitAddressTreeAccountsInstructionData>,
27    pub skip_protocol_init: bool,
28    pub log_failed_tx: bool,
29    pub no_logs: bool,
30    pub skip_startup_logs: bool,
31}
32
33impl ProgramTestConfig {
34    pub fn new(
35        with_prover: bool,
36        additional_programs: Option<Vec<(&'static str, Pubkey)>>,
37    ) -> Self {
38        Self {
39            additional_programs,
40            with_prover,
41            ..Default::default()
42        }
43    }
44
45    #[cfg(feature = "v2")]
46    pub fn new_v2(
47        with_prover: bool,
48        additional_programs: Option<Vec<(&'static str, Pubkey)>>,
49    ) -> Self {
50        let mut res = Self::default_with_batched_trees(with_prover);
51        res.additional_programs = additional_programs;
52
53        res
54    }
55
56    #[cfg(feature = "v2")]
57    pub fn default_with_batched_trees(with_prover: bool) -> Self {
58        Self {
59            additional_programs: None,
60            prover_config: Some(ProverConfig::default()),
61            with_prover,
62            v2_state_tree_config: Some(InitStateTreeAccountsInstructionData::test_default()),
63            v2_address_tree_config: Some(InitAddressTreeAccountsInstructionData::test_default()),
64            ..Default::default()
65        }
66    }
67
68    #[cfg(feature = "devenv")]
69    pub fn default_test_forester(with_prover: bool) -> Self {
70        Self {
71            additional_programs: None,
72            with_prover,
73            v2_state_tree_config: Some(InitStateTreeAccountsInstructionData::test_default()),
74            v2_address_tree_config: Some(InitAddressTreeAccountsInstructionData::test_default()),
75            prover_config: Some(ProverConfig::default()),
76            ..Default::default()
77        }
78    }
79
80    // TODO: uncomment once batched trees are on devnet.
81    // #[cfg(not(feature = "devenv"))]
82    // pub fn default_with_batched_trees() -> Self {
83    //     Self {
84    //         additional_programs: None,
85    //         with_prover: false,
86    //         v2_state_tree_config: Some(InitStateTreeAccountsInstructionData::default()),
87    //         v2_address_tree_config: Some(
88    //             InitAddressTreeAccountsInstructionData::default(),
89    //         ),
90    //         ..Default::default()
91    //     }
92    // }
93}
94
95impl Default for ProgramTestConfig {
96    fn default() -> Self {
97        Self {
98            additional_programs: None,
99            protocol_config: ProtocolConfig {
100                // Init with an active epoch which doesn't end
101                active_phase_length: 1_000_000_000,
102                slot_length: 1_000_000_000 - 1,
103                genesis_slot: 0,
104                registration_phase_length: 2,
105                ..Default::default()
106            },
107            with_prover: true,
108            prover_config: None,
109            skip_second_v1_tree: false,
110            skip_register_programs: false,
111            v1_state_tree_config: StateMerkleTreeConfig::default(),
112            v1_address_tree_config: AddressMerkleTreeConfig::default(),
113            v1_address_queue_config: AddressQueueConfig::default(),
114            v1_nullifier_queue_config: NullifierQueueConfig::default(),
115            v2_state_tree_config: None,
116            v2_address_tree_config: None,
117            skip_protocol_init: false,
118            skip_v1_trees: false,
119            log_failed_tx: true,
120            no_logs: false,
121            skip_startup_logs: true,
122        }
123    }
124}