Skip to content

Commit 313fc3d

Browse files
committed
refactor: use pack_output_tree_index for tree selection
1 parent 00cdac2 commit 313fc3d

10 files changed

Lines changed: 23 additions & 35 deletions

File tree

basic-operations/native/programs/burn/src/test_helpers.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use solana_sdk::{
1111
pub async fn create_compressed_account(
1212
payer: &Keypair,
1313
rpc: &mut LightProgramTest,
14-
merkle_tree_pubkey: &Pubkey,
1514
address_tree_pubkey: Pubkey,
1615
address: [u8; 32],
1716
message: String,
@@ -33,14 +32,16 @@ pub async fn create_compressed_account(
3332
.await?
3433
.value;
3534

36-
let output_state_tree_index = accounts.insert_or_get(*merkle_tree_pubkey);
35+
let output_state_tree_index = rpc
36+
.get_random_state_tree_info()?
37+
.pack_output_tree_index(&mut accounts)?;
3738
let packed_address_tree_info = rpc_result.pack_tree_infos(&mut accounts).address_trees[0];
3839
let (account_metas, _, _) = accounts.to_account_metas();
3940

4041
let instruction_data = CreateInstructionData {
4142
proof: rpc_result.proof,
4243
address_tree_info: packed_address_tree_info,
43-
output_state_tree_index: output_state_tree_index,
44+
output_state_tree_index,
4445
message,
4546
};
4647
let inputs = instruction_data.try_to_vec().unwrap();

basic-operations/native/programs/burn/tests/test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ async fn test_burn() {
3030
&address_tree_pubkey,
3131
&ID,
3232
);
33-
let merkle_tree_pubkey = rpc.get_random_state_tree_info().unwrap().tree;
34-
3533
native_program_burn::test_helpers::create_compressed_account(
3634
&payer,
3735
&mut rpc,
38-
&merkle_tree_pubkey,
3936
address_tree_pubkey,
4037
address,
4138
"Hello, compressed world!".to_string(),

basic-operations/native/programs/close/src/test_helpers.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use solana_sdk::{
1111
pub async fn create_compressed_account(
1212
payer: &Keypair,
1313
rpc: &mut LightProgramTest,
14-
merkle_tree_pubkey: &Pubkey,
1514
address_tree_pubkey: Pubkey,
1615
address: [u8; 32],
1716
message: String,
@@ -33,14 +32,16 @@ pub async fn create_compressed_account(
3332
.await?
3433
.value;
3534

36-
let output_state_tree_index = accounts.insert_or_get(*merkle_tree_pubkey);
35+
let output_state_tree_index = rpc
36+
.get_random_state_tree_info()?
37+
.pack_output_tree_index(&mut accounts)?;
3738
let packed_address_tree_info = rpc_result.pack_tree_infos(&mut accounts).address_trees[0];
3839
let (account_metas, _, _) = accounts.to_account_metas();
3940

4041
let instruction_data = CreateInstructionData {
4142
proof: rpc_result.proof,
4243
address_tree_info: packed_address_tree_info,
43-
output_state_tree_index: output_state_tree_index,
44+
output_state_tree_index,
4445
message,
4546
};
4647
let inputs = instruction_data.try_to_vec().unwrap();

basic-operations/native/programs/close/tests/test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ async fn test_close() {
2828
&address_tree_pubkey,
2929
&ID,
3030
);
31-
let merkle_tree_pubkey = rpc.get_random_state_tree_info().unwrap().tree;
32-
3331
native_program_close::test_helpers::create_compressed_account(
3432
&payer,
3533
&mut rpc,
36-
&merkle_tree_pubkey,
3734
address_tree_pubkey,
3835
address,
3936
"Hello, compressed world!".to_string(),

basic-operations/native/programs/reinit/src/test_helpers.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use solana_sdk::{
1212
pub async fn create_compressed_account(
1313
payer: &Keypair,
1414
rpc: &mut LightProgramTest,
15-
merkle_tree_pubkey: &Pubkey,
1615
address_tree_pubkey: Pubkey,
1716
address: [u8; 32],
1817
message: String,
@@ -34,14 +33,16 @@ pub async fn create_compressed_account(
3433
.await?
3534
.value;
3635

37-
let output_state_tree_index = accounts.insert_or_get(*merkle_tree_pubkey);
36+
let output_state_tree_index = rpc
37+
.get_random_state_tree_info()?
38+
.pack_output_tree_index(&mut accounts)?;
3839
let packed_address_tree_info = rpc_result.pack_tree_infos(&mut accounts).address_trees[0];
3940
let (account_metas, _, _) = accounts.to_account_metas();
4041

4142
let instruction_data = CreateInstructionData {
4243
proof: rpc_result.proof,
4344
address_tree_info: packed_address_tree_info,
44-
output_state_tree_index: output_state_tree_index,
45+
output_state_tree_index,
4546
message,
4647
};
4748
let inputs = instruction_data.try_to_vec().unwrap();

basic-operations/native/programs/reinit/tests/test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ async fn test_reinit() {
3131
&address_tree_pubkey,
3232
&ID,
3333
);
34-
let merkle_tree_pubkey = rpc.get_random_state_tree_info().unwrap().tree;
35-
3634
native_program_reinit::test_helpers::create_compressed_account(
3735
&payer,
3836
&mut rpc,
39-
&merkle_tree_pubkey,
4037
address_tree_pubkey,
4138
address,
4239
"Hello, compressed world!".to_string(),

basic-operations/native/programs/update/src/test_helpers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use solana_sdk::{
1111
pub async fn create_compressed_account(
1212
payer: &Keypair,
1313
rpc: &mut LightProgramTest,
14-
merkle_tree_pubkey: &Pubkey,
1514
address_tree_pubkey: Pubkey,
1615
address: [u8; 32],
1716
message: String,
@@ -33,7 +32,9 @@ pub async fn create_compressed_account(
3332
.await?
3433
.value;
3534

36-
let output_state_tree_index = accounts.insert_or_get(*merkle_tree_pubkey);
35+
let output_state_tree_index = rpc
36+
.get_random_state_tree_info()?
37+
.pack_output_tree_index(&mut accounts)?;
3738
let packed_address_tree_info = rpc_result.pack_tree_infos(&mut accounts).address_trees[0];
3839
let (account_metas, _, _) = accounts.to_account_metas();
3940

basic-operations/native/programs/update/tests/test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ async fn test_update() {
3232
&address_tree_pubkey,
3333
&ID,
3434
);
35-
let merkle_tree_pubkey = rpc.get_random_state_tree_info().unwrap().tree;
36-
3735
native_program_update::test_helpers::create_compressed_account(
3836
&payer,
3937
&mut rpc,
40-
&merkle_tree_pubkey,
4138
address_tree_pubkey,
4239
address,
4340
"Hello, compressed world!".to_string(),

counter/native/tests/test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ async fn test_counter() {
3434
&address_tree_pubkey,
3535
&counter::ID,
3636
);
37-
let merkle_tree_pubkey = rpc.get_random_state_tree_info().unwrap().tree;
38-
3937
create_counter(
4038
&payer,
4139
&mut rpc,
42-
&merkle_tree_pubkey,
4340
address_tree_pubkey,
4441
address,
4542
)
@@ -109,7 +106,6 @@ async fn test_counter() {
109106
pub async fn create_counter(
110107
payer: &Keypair,
111108
rpc: &mut LightProgramTest,
112-
merkle_tree_pubkey: &Pubkey,
113109
address_tree_pubkey: Pubkey,
114110
address: [u8; 32],
115111
) -> Result<(), RpcError> {
@@ -130,14 +126,16 @@ pub async fn create_counter(
130126
.await?
131127
.value;
132128

133-
let output_merkle_tree_index = accounts.insert_or_get(*merkle_tree_pubkey);
129+
let output_state_tree_index = rpc
130+
.get_random_state_tree_info()?
131+
.pack_output_tree_index(&mut accounts)?;
134132
let packed_address_tree_info = rpc_result.pack_tree_infos(&mut accounts).address_trees[0];
135133
let (account_metas, _, _) = accounts.to_account_metas();
136134

137135
let instruction_data = CreateCounterInstructionData {
138136
proof: rpc_result.proof,
139137
address_tree_info: packed_address_tree_info,
140-
output_state_tree_index: output_merkle_tree_index,
138+
output_state_tree_index,
141139
};
142140
let inputs = instruction_data.try_to_vec().unwrap();
143141

counter/pinocchio/tests/test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ async fn test_counter() {
3434
&address_tree_pubkey,
3535
&counter::ID.into(),
3636
);
37-
let merkle_tree_pubkey = rpc.get_random_state_tree_info().unwrap().tree;
38-
3937
create_counter(
4038
&payer,
4139
&mut rpc,
42-
&merkle_tree_pubkey,
4340
address_tree_pubkey,
4441
address,
4542
)
@@ -100,7 +97,6 @@ async fn test_counter() {
10097
pub async fn create_counter(
10198
payer: &Keypair,
10299
rpc: &mut LightProgramTest,
103-
merkle_tree_pubkey: &Pubkey,
104100
address_tree_pubkey: Pubkey,
105101
address: [u8; 32],
106102
) -> Result<(), RpcError> {
@@ -121,14 +117,16 @@ pub async fn create_counter(
121117
.await?
122118
.value;
123119

124-
let output_merkle_tree_index = accounts.insert_or_get(*merkle_tree_pubkey);
120+
let output_state_tree_index = rpc
121+
.get_random_state_tree_info()?
122+
.pack_output_tree_index(&mut accounts)?;
125123
let packed_address_tree_info = rpc_result.pack_tree_infos(&mut accounts).address_trees[0];
126124
let (accounts, _, _) = accounts.to_account_metas();
127125

128126
let instruction_data = CreateCounterInstructionData {
129127
proof: rpc_result.proof,
130128
address_tree_info: packed_address_tree_info,
131-
output_state_tree_index: output_merkle_tree_index,
129+
output_state_tree_index,
132130
};
133131
let inputs = instruction_data.try_to_vec().unwrap();
134132

0 commit comments

Comments
 (0)