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
12use crate::logging::EnhancedLoggingConfig;
13
14/// Configuration for Light Program Test
15#[derive(Debug, Clone)]
16pub struct ProgramTestConfig {
17    pub additional_programs: Option<Vec<(&'static str, Pubkey)>>,
18    pub protocol_config: ProtocolConfig,
19    pub with_prover: bool,
20    pub prover_config: Option<ProverConfig>,
21    pub skip_register_programs: bool,
22    pub skip_v1_trees: bool,
23    pub skip_second_v1_tree: bool,
24    pub v1_state_tree_config: StateMerkleTreeConfig,
25    pub v1_nullifier_queue_config: NullifierQueueConfig,
26    pub v1_address_tree_config: AddressMerkleTreeConfig,
27    pub v1_address_queue_config: AddressQueueConfig,
28    pub v2_state_tree_config: Option<InitStateTreeAccountsInstructionData>,
29    pub v2_address_tree_config: Option<InitAddressTreeAccountsInstructionData>,
30    pub skip_protocol_init: bool,
31    /// Log failed transactions
32    pub log_failed_tx: bool,
33    /// Disable all logging
34    pub no_logs: bool,
35    /// Skip startup logs
36    pub skip_startup_logs: bool,
37    /// Log Light Protocol events (BatchPublicTransactionEvent, etc.)
38    pub log_light_protocol_events: bool,
39    /// Enhanced transaction logging configuration
40    pub enhanced_logging: EnhancedLoggingConfig,
41}
42
43impl ProgramTestConfig {
44    pub fn new(
45        with_prover: bool,
46        additional_programs: Option<Vec<(&'static str, Pubkey)>>,
47    ) -> Self {
48        Self {
49            additional_programs,
50            with_prover,
51            ..Default::default()
52        }
53    }
54
55    #[cfg(feature = "v2")]
56    pub fn new_v2(
57        with_prover: bool,
58        additional_programs: Option<Vec<(&'static str, Pubkey)>>,
59    ) -> Self {
60        let mut res = Self::default_with_batched_trees(with_prover);
61        res.additional_programs = additional_programs;
62
63        res
64    }
65
66    #[cfg(feature = "v2")]
67    pub fn default_with_batched_trees(with_prover: bool) -> Self {
68        Self {
69            additional_programs: None,
70            prover_config: Some(ProverConfig::default()),
71            with_prover,
72            v2_state_tree_config: Some(InitStateTreeAccountsInstructionData::test_default()),
73            v2_address_tree_config: Some(InitAddressTreeAccountsInstructionData::test_default()),
74            ..Default::default()
75        }
76    }
77
78    #[cfg(feature = "devenv")]
79    pub fn default_test_forester(with_prover: bool) -> Self {
80        Self {
81            additional_programs: None,
82            with_prover,
83            v2_state_tree_config: Some(InitStateTreeAccountsInstructionData::test_default()),
84            v2_address_tree_config: Some(InitAddressTreeAccountsInstructionData::test_default()),
85            prover_config: Some(ProverConfig::default()),
86            ..Default::default()
87        }
88    }
89
90    /// Enable Light Protocol event logging
91    pub fn with_light_protocol_events(mut self) -> Self {
92        self.log_light_protocol_events = true;
93        self
94    }
95
96    /// Disable Light Protocol event logging
97    pub fn without_light_protocol_events(mut self) -> Self {
98        self.log_light_protocol_events = false;
99        self
100    }
101}
102
103impl Default for ProgramTestConfig {
104    fn default() -> Self {
105        Self {
106            additional_programs: None,
107            protocol_config: ProtocolConfig {
108                // Init with an active epoch which doesn't end
109                active_phase_length: 1_000_000_000,
110                slot_length: 1_000_000_000 - 1,
111                genesis_slot: 0,
112                registration_phase_length: 2,
113                ..Default::default()
114            },
115            with_prover: true,
116            prover_config: None,
117            skip_second_v1_tree: false,
118            skip_register_programs: false,
119            v1_state_tree_config: StateMerkleTreeConfig::default(),
120            v1_address_tree_config: AddressMerkleTreeConfig::default(),
121            v1_address_queue_config: AddressQueueConfig::default(),
122            v1_nullifier_queue_config: NullifierQueueConfig::default(),
123            v2_state_tree_config: None,
124            v2_address_tree_config: None,
125            skip_protocol_init: false,
126            skip_v1_trees: false,
127            log_failed_tx: true,
128            no_logs: false,
129            skip_startup_logs: true,
130            log_light_protocol_events: false, // Disabled by default
131            enhanced_logging: EnhancedLoggingConfig::from_env(),
132        }
133    }
134}