light_program_test/accounts/
test_accounts.rs1use light_client::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts, TreeInfo};
2use light_compressed_account::TreeType;
3use light_registry::{
4 account_compression_cpi::sdk::get_registered_program_pda,
5 sdk::create_register_program_instruction,
6 utils::{get_forester_pda, get_protocol_config_pda_address},
7};
8use solana_sdk::{
9 pubkey,
10 pubkey::Pubkey,
11 signature::{Keypair, Signer},
12};
13
14use super::{initialize::*, test_keypairs::*};
15
16pub const NOOP_PROGRAM_ID: Pubkey = pubkey!("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV");
17
18#[derive(Debug)]
19pub struct ProtocolAccounts {
20 pub governance_authority: Keypair,
21 pub governance_authority_pda: Pubkey,
22 pub group_pda: Pubkey,
23 pub forester: Keypair,
24 pub registered_program_pda: Pubkey,
25 pub registered_registry_program_pda: Pubkey,
26 pub registered_forester_pda: Pubkey,
27}
28
29#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)]
30pub struct StateMerkleTreeAccountsV2 {
31 pub merkle_tree: Pubkey,
32 pub output_queue: Pubkey,
33 pub cpi_context: Pubkey,
34}
35
36impl From<StateMerkleTreeAccountsV2> for TreeInfo {
37 fn from(value: StateMerkleTreeAccountsV2) -> Self {
38 TreeInfo {
39 tree: value.merkle_tree,
40 queue: value.output_queue,
41 cpi_context: Some(value.cpi_context),
42 tree_type: TreeType::StateV2,
43 next_tree_info: None,
44 }
45 }
46}
47
48#[derive(Debug)]
49pub struct TestAccounts {
50 pub protocol: ProtocolAccounts,
51 pub v1_state_trees: Vec<StateMerkleTreeAccounts>,
52 pub v1_address_trees: Vec<AddressMerkleTreeAccounts>,
53 pub v2_state_trees: Vec<StateMerkleTreeAccountsV2>,
54 pub v2_address_trees: Vec<Pubkey>,
55}
56
57impl TestAccounts {
58 pub fn get_local_test_validator_accounts() -> TestAccounts {
59 TestAccounts {
60 protocol: ProtocolAccounts {
61 governance_authority: Keypair::from_bytes(&PAYER_KEYPAIR).unwrap(),
62 governance_authority_pda: Pubkey::default(),
63 group_pda: Pubkey::default(),
64 forester: Keypair::from_bytes(&FORESTER_TEST_KEYPAIR).unwrap(),
65 registered_program_pda: get_registered_program_pda(&Pubkey::from(
66 light_sdk::constants::LIGHT_SYSTEM_PROGRAM_ID,
67 )),
68 registered_registry_program_pda: get_registered_program_pda(&light_registry::ID),
69 registered_forester_pda: Pubkey::default(),
70 },
71 v1_state_trees: vec![StateMerkleTreeAccounts {
72 merkle_tree: pubkey!("smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT"),
73 nullifier_queue: pubkey!("nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148"),
74 cpi_context: pubkey!("cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4"),
75 }],
76
77 v1_address_trees: vec![AddressMerkleTreeAccounts {
78 merkle_tree: pubkey!("amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2"),
79 queue: pubkey!("aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F"),
80 }],
81
82 v2_address_trees: vec![pubkey!("EzKE84aVTkCUhDHLELqyJaq1Y7UVVmqxXqZjVHwHY3rK")],
83 v2_state_trees: vec![StateMerkleTreeAccountsV2 {
84 merkle_tree: pubkey!("HLKs5NJ8FXkJg8BrzJt56adFYYuwg5etzDtBbQYTsixu"),
85 output_queue: pubkey!("6L7SzhYB3anwEQ9cphpJ1U7Scwj57bx2xueReg7R9cKU"),
86 cpi_context: pubkey!("7Hp52chxaew8bW1ApR4fck2bh6Y8qA1pu3qwH6N9zaLj"),
87 }],
88 }
89 }
90
91 pub fn get_program_test_test_accounts() -> TestAccounts {
92 let merkle_tree_keypair = Keypair::from_bytes(&MERKLE_TREE_TEST_KEYPAIR).unwrap();
93 let nullifier_queue_keypair = Keypair::from_bytes(&NULLIFIER_QUEUE_TEST_KEYPAIR).unwrap();
94 let group_seed_keypair = Keypair::from_bytes(&GROUP_PDA_SEED_TEST_KEYPAIR).unwrap();
95 let group_pda = get_group_pda(group_seed_keypair.pubkey());
96
97 let payer = Keypair::from_bytes(&PAYER_KEYPAIR).unwrap();
98 let protocol_config_pda = get_protocol_config_pda_address();
99 let (_, registered_program_pda) = create_register_program_instruction(
100 payer.pubkey(),
101 protocol_config_pda,
102 group_pda,
103 Pubkey::from(light_sdk::constants::LIGHT_SYSTEM_PROGRAM_ID),
104 );
105
106 let cpi_context_keypair = Keypair::from_bytes(&SIGNATURE_CPI_TEST_KEYPAIR).unwrap();
107 let registered_registry_program_pda = get_registered_program_pda(&light_registry::ID);
108 let forester = Keypair::from_bytes(&FORESTER_TEST_KEYPAIR).unwrap();
109
110 let forester_pubkey = forester.pubkey();
111 TestAccounts {
112 protocol: ProtocolAccounts {
113 governance_authority: payer,
114 governance_authority_pda: protocol_config_pda.0,
115 group_pda,
116 forester,
117 registered_program_pda,
118 registered_registry_program_pda,
119 registered_forester_pda: get_forester_pda(&forester_pubkey).0,
120 },
121 v1_state_trees: vec![StateMerkleTreeAccounts {
122 merkle_tree: merkle_tree_keypair.pubkey(),
123 nullifier_queue: nullifier_queue_keypair.pubkey(),
124 cpi_context: cpi_context_keypair.pubkey(),
125 }],
126 v1_address_trees: vec![AddressMerkleTreeAccounts {
127 merkle_tree: pubkey!("amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2"),
128 queue: pubkey!("aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F"),
129 }],
130 v2_state_trees: vec![StateMerkleTreeAccountsV2 {
131 merkle_tree: Keypair::from_bytes(&BATCHED_STATE_MERKLE_TREE_TEST_KEYPAIR)
132 .unwrap()
133 .pubkey(),
134 output_queue: Keypair::from_bytes(&BATCHED_OUTPUT_QUEUE_TEST_KEYPAIR)
135 .unwrap()
136 .pubkey(),
137 cpi_context: Keypair::from_bytes(&BATCHED_CPI_CONTEXT_TEST_KEYPAIR)
138 .unwrap()
139 .pubkey(),
140 }],
141 v2_address_trees: vec![
142 Keypair::from_bytes(&BATCHED_ADDRESS_MERKLE_TREE_TEST_KEYPAIR)
143 .unwrap()
144 .pubkey(),
145 ],
146 }
147 }
148}
149
150impl Clone for TestAccounts {
151 fn clone(&self) -> Self {
152 TestAccounts {
153 protocol: ProtocolAccounts {
154 governance_authority: Keypair::from_bytes(
155 &self.protocol.governance_authority.to_bytes(),
156 )
157 .unwrap(),
158 governance_authority_pda: self.protocol.governance_authority_pda,
159 group_pda: self.protocol.group_pda,
160 forester: Keypair::from_bytes(&self.protocol.forester.to_bytes()).unwrap(),
161 registered_program_pda: self.protocol.registered_program_pda,
162 registered_registry_program_pda: self.protocol.registered_registry_program_pda,
163 registered_forester_pda: self.protocol.registered_forester_pda,
164 },
165 v1_state_trees: self.v1_state_trees.clone(),
166 v1_address_trees: self.v1_address_trees.clone(),
167 v2_state_trees: self.v2_state_trees.clone(),
168 v2_address_trees: self.v2_address_trees.clone(),
169 }
170 }
171}