light_program_test/accounts/
test_accounts.rs

1use light_client::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts, TreeInfo};
2use light_compressed_account::TreeType;
3#[cfg(feature = "devenv")]
4use light_registry::{
5    account_compression_cpi::sdk::get_registered_program_pda,
6    sdk::create_register_program_instruction,
7    utils::{get_forester_pda, get_protocol_config_pda_address},
8};
9#[cfg(feature = "devenv")]
10use solana_sdk::signature::Signer;
11use solana_sdk::{pubkey, pubkey::Pubkey, signature::Keypair};
12
13#[cfg(feature = "devenv")]
14use super::initialize::*;
15use super::test_keypairs::*;
16#[cfg(feature = "devenv")]
17use crate::compressible::FundingPoolConfig;
18
19pub const NOOP_PROGRAM_ID: Pubkey = pubkey!("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV");
20
21#[derive(Debug)]
22pub struct ProtocolAccounts {
23    pub governance_authority: Keypair,
24    pub governance_authority_pda: Pubkey,
25    pub group_pda: Pubkey,
26    pub forester: Keypair,
27    pub registered_program_pda: Pubkey,
28    pub registered_registry_program_pda: Pubkey,
29    pub registered_forester_pda: Pubkey,
30}
31
32#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)]
33pub struct StateMerkleTreeAccountsV2 {
34    pub merkle_tree: Pubkey,
35    pub output_queue: Pubkey,
36    pub cpi_context: Pubkey,
37}
38
39impl From<StateMerkleTreeAccountsV2> for TreeInfo {
40    fn from(value: StateMerkleTreeAccountsV2) -> Self {
41        TreeInfo {
42            tree: value.merkle_tree,
43            queue: value.output_queue,
44            cpi_context: Some(value.cpi_context),
45            tree_type: TreeType::StateV2,
46            next_tree_info: None,
47        }
48    }
49}
50
51#[derive(Debug)]
52pub struct TestAccounts {
53    pub protocol: ProtocolAccounts,
54    #[cfg(feature = "devenv")]
55    pub funding_pool_config: FundingPoolConfig,
56    pub v1_state_trees: Vec<StateMerkleTreeAccounts>,
57    pub v1_address_trees: Vec<AddressMerkleTreeAccounts>,
58    pub v2_state_trees: Vec<StateMerkleTreeAccountsV2>,
59    pub v2_address_trees: Vec<Pubkey>,
60}
61
62impl TestAccounts {
63    pub fn get_local_test_validator_accounts() -> TestAccounts {
64        TestAccounts {
65            protocol: ProtocolAccounts {
66                governance_authority: Keypair::from_bytes(&PAYER_KEYPAIR).unwrap(),
67                governance_authority_pda: Pubkey::default(),
68                group_pda: Pubkey::default(),
69                forester: Keypair::from_bytes(&FORESTER_TEST_KEYPAIR).unwrap(),
70                registered_program_pda: pubkey!("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),
71                registered_registry_program_pda: pubkey!(
72                    "DumMsyvkaGJG4QnQ1BhTgvoRMXsgGxfpKDUCr22Xqu4w"
73                ),
74                registered_forester_pda: Pubkey::default(),
75            },
76            v1_state_trees: vec![
77                StateMerkleTreeAccounts {
78                    merkle_tree: pubkey!("smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT"),
79                    nullifier_queue: pubkey!("nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148"),
80                    cpi_context: pubkey!("cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4"),
81                    tree_type: TreeType::StateV1,
82                },
83                StateMerkleTreeAccounts {
84                    merkle_tree: pubkey!("smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho"),
85                    nullifier_queue: pubkey!("nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X"),
86                    cpi_context: pubkey!("cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK"),
87                    tree_type: TreeType::StateV1,
88                },
89            ],
90
91            v1_address_trees: vec![AddressMerkleTreeAccounts {
92                merkle_tree: pubkey!("amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2"),
93                queue: pubkey!("aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F"),
94            }],
95
96            v2_address_trees: vec![pubkey!("amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx")],
97            v2_state_trees: vec![
98                StateMerkleTreeAccountsV2 {
99                    merkle_tree: pubkey!("bmt1LryLZUMmF7ZtqESaw7wifBXLfXHQYoE4GAmrahU"),
100                    output_queue: pubkey!("oq1na8gojfdUhsfCpyjNt6h4JaDWtHf1yQj4koBWfto"),
101                    cpi_context: pubkey!("cpi15BoVPKgEPw5o8wc2T816GE7b378nMXnhH3Xbq4y"),
102                },
103                StateMerkleTreeAccountsV2 {
104                    merkle_tree: pubkey!("bmt2UxoBxB9xWev4BkLvkGdapsz6sZGkzViPNph7VFi"),
105                    output_queue: pubkey!("oq2UkeMsJLfXt2QHzim242SUi3nvjJs8Pn7Eac9H9vg"),
106                    cpi_context: pubkey!("cpi2yGapXUR3As5SjnHBAVvmApNiLsbeZpF3euWnW6B"),
107                },
108                StateMerkleTreeAccountsV2 {
109                    merkle_tree: pubkey!("bmt3ccLd4bqSVZVeCJnH1F6C8jNygAhaDfxDwePyyGb"),
110                    output_queue: pubkey!("oq3AxjekBWgo64gpauB6QtuZNesuv19xrhaC1ZM1THQ"),
111                    cpi_context: pubkey!("cpi3mbwMpSX8FAGMZVP85AwxqCaQMfEk9Em1v8QK9Rf"),
112                },
113                StateMerkleTreeAccountsV2 {
114                    merkle_tree: pubkey!("bmt4d3p1a4YQgk9PeZv5s4DBUmbF5NxqYpk9HGjQsd8"),
115                    output_queue: pubkey!("oq4ypwvVGzCUMoiKKHWh4S1SgZJ9vCvKpcz6RT6A8dq"),
116                    cpi_context: pubkey!("cpi4yyPDc4bCgHAnsenunGA8Y77j3XEDyjgfyCKgcoc"),
117                },
118                StateMerkleTreeAccountsV2 {
119                    merkle_tree: pubkey!("bmt5yU97jC88YXTuSukYHa8Z5Bi2ZDUtmzfkDTA2mG2"),
120                    output_queue: pubkey!("oq5oh5ZR3yGomuQgFduNDzjtGvVWfDRGLuDVjv9a96P"),
121                    cpi_context: pubkey!("cpi5ZTjdgYpZ1Xr7B1cMLLUE81oTtJbNNAyKary2nV6"),
122                },
123            ],
124            #[cfg(feature = "devenv")]
125            funding_pool_config: FundingPoolConfig::get_v1(),
126        }
127    }
128
129    pub fn get_program_test_test_accounts() -> TestAccounts {
130        #[cfg(feature = "devenv")]
131        let (
132            group_pda,
133            protocol_config_pda,
134            registered_program_pda,
135            registered_registry_program_pda,
136            registered_forester_pda,
137        ) = {
138            let group_seed_keypair = Keypair::from_bytes(&GROUP_PDA_SEED_TEST_KEYPAIR).unwrap();
139            let group_pda = get_group_pda(group_seed_keypair.pubkey());
140            let payer = Keypair::from_bytes(&PAYER_KEYPAIR).unwrap();
141            let protocol_config_pda = get_protocol_config_pda_address();
142            let (_, registered_program_pda) = create_register_program_instruction(
143                payer.pubkey(),
144                protocol_config_pda,
145                group_pda,
146                Pubkey::from(light_sdk::constants::LIGHT_SYSTEM_PROGRAM_ID),
147            );
148            let registered_registry_program_pda =
149                get_registered_program_pda(&pubkey!("Lighton6oQpVkeewmo2mcPTQQp7kYHr4fWpAgJyEmDX"));
150            let forester = Keypair::from_bytes(&FORESTER_TEST_KEYPAIR).unwrap();
151            let registered_forester_pda = get_forester_pda(&forester.pubkey()).0;
152            (
153                group_pda,
154                protocol_config_pda.0,
155                registered_program_pda,
156                registered_registry_program_pda,
157                registered_forester_pda,
158            )
159        };
160
161        #[cfg(not(feature = "devenv"))]
162        let (
163            group_pda,
164            protocol_config_pda,
165            registered_program_pda,
166            registered_registry_program_pda,
167            registered_forester_pda,
168        ) = {
169            // Hardcoded PDAs for non-devenv mode (these match the devenv calculations)
170            let group_pda = pubkey!("Fomh1YizJdDfqvMJhC42cLNdcJM8NMM2NfxgZVEh3rkC");
171            let protocol_config_pda = pubkey!("CuEtcKkkbTn6qy2qxqDswq5U2ADsqoipYDAYfRvxPjcp");
172            let registered_program_pda = pubkey!("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh");
173            let registered_registry_program_pda =
174                pubkey!("DumMsyvkaGJG4QnQ1BhTgvoRMXsgGxfpKDUCr22Xqu4w");
175            let registered_forester_pda = pubkey!("3FBt1BPQHCQkS8k3wrUXMfB6JBhtMhEqQXueHRw2ojZV");
176            (
177                group_pda,
178                protocol_config_pda,
179                registered_program_pda,
180                registered_registry_program_pda,
181                registered_forester_pda,
182            )
183        };
184
185        let payer = Keypair::from_bytes(&PAYER_KEYPAIR).unwrap();
186        let forester = Keypair::from_bytes(&FORESTER_TEST_KEYPAIR).unwrap();
187
188        TestAccounts {
189            protocol: ProtocolAccounts {
190                governance_authority: payer,
191                governance_authority_pda: protocol_config_pda,
192                group_pda,
193                forester,
194                registered_program_pda,
195                registered_registry_program_pda,
196                registered_forester_pda,
197            },
198            v1_state_trees: vec![
199                StateMerkleTreeAccounts {
200                    merkle_tree: pubkey!("smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT"),
201                    nullifier_queue: pubkey!("nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148"),
202                    cpi_context: pubkey!("cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4"),
203                    tree_type: TreeType::StateV1,
204                },
205                StateMerkleTreeAccounts {
206                    merkle_tree: pubkey!("smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho"),
207                    nullifier_queue: pubkey!("nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X"),
208                    cpi_context: pubkey!("cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK"),
209                    tree_type: TreeType::StateV1,
210                },
211            ],
212            v1_address_trees: vec![AddressMerkleTreeAccounts {
213                merkle_tree: pubkey!("amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2"),
214                queue: pubkey!("aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F"),
215            }],
216            v2_state_trees: vec![
217                StateMerkleTreeAccountsV2 {
218                    merkle_tree: pubkey!("bmt1LryLZUMmF7ZtqESaw7wifBXLfXHQYoE4GAmrahU"),
219                    output_queue: pubkey!("oq1na8gojfdUhsfCpyjNt6h4JaDWtHf1yQj4koBWfto"),
220                    cpi_context: pubkey!("cpi15BoVPKgEPw5o8wc2T816GE7b378nMXnhH3Xbq4y"),
221                },
222                StateMerkleTreeAccountsV2 {
223                    merkle_tree: pubkey!("bmt2UxoBxB9xWev4BkLvkGdapsz6sZGkzViPNph7VFi"),
224                    output_queue: pubkey!("oq2UkeMsJLfXt2QHzim242SUi3nvjJs8Pn7Eac9H9vg"),
225                    cpi_context: pubkey!("cpi2yGapXUR3As5SjnHBAVvmApNiLsbeZpF3euWnW6B"),
226                },
227                StateMerkleTreeAccountsV2 {
228                    merkle_tree: pubkey!("bmt3ccLd4bqSVZVeCJnH1F6C8jNygAhaDfxDwePyyGb"),
229                    output_queue: pubkey!("oq3AxjekBWgo64gpauB6QtuZNesuv19xrhaC1ZM1THQ"),
230                    cpi_context: pubkey!("cpi3mbwMpSX8FAGMZVP85AwxqCaQMfEk9Em1v8QK9Rf"),
231                },
232                StateMerkleTreeAccountsV2 {
233                    merkle_tree: pubkey!("bmt4d3p1a4YQgk9PeZv5s4DBUmbF5NxqYpk9HGjQsd8"),
234                    output_queue: pubkey!("oq4ypwvVGzCUMoiKKHWh4S1SgZJ9vCvKpcz6RT6A8dq"),
235                    cpi_context: pubkey!("cpi4yyPDc4bCgHAnsenunGA8Y77j3XEDyjgfyCKgcoc"),
236                },
237                StateMerkleTreeAccountsV2 {
238                    merkle_tree: pubkey!("bmt5yU97jC88YXTuSukYHa8Z5Bi2ZDUtmzfkDTA2mG2"),
239                    output_queue: pubkey!("oq5oh5ZR3yGomuQgFduNDzjtGvVWfDRGLuDVjv9a96P"),
240                    cpi_context: pubkey!("cpi5ZTjdgYpZ1Xr7B1cMLLUE81oTtJbNNAyKary2nV6"),
241                },
242            ],
243            v2_address_trees: vec![pubkey!("amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx")],
244            #[cfg(feature = "devenv")]
245            funding_pool_config: FundingPoolConfig::get_v1(),
246        }
247    }
248}
249
250impl Clone for TestAccounts {
251    fn clone(&self) -> Self {
252        TestAccounts {
253            protocol: ProtocolAccounts {
254                governance_authority: Keypair::from_bytes(
255                    &self.protocol.governance_authority.to_bytes(),
256                )
257                .unwrap(),
258                governance_authority_pda: self.protocol.governance_authority_pda,
259                group_pda: self.protocol.group_pda,
260                forester: Keypair::from_bytes(&self.protocol.forester.to_bytes()).unwrap(),
261                registered_program_pda: self.protocol.registered_program_pda,
262                registered_registry_program_pda: self.protocol.registered_registry_program_pda,
263                registered_forester_pda: self.protocol.registered_forester_pda,
264            },
265            v1_state_trees: self.v1_state_trees.clone(),
266            v1_address_trees: self.v1_address_trees.clone(),
267            v2_state_trees: self.v2_state_trees.clone(),
268            v2_address_trees: self.v2_address_trees.clone(),
269            #[cfg(feature = "devenv")]
270            funding_pool_config: self.funding_pool_config,
271        }
272    }
273}