Skip to content

Commit e28b720

Browse files
committed
chore: fix tests and sdks
1 parent 85e5cbb commit e28b720

File tree

90 files changed

+2490
-745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2490
-745
lines changed

.github/workflows/rust.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ jobs:
4545
light-verifier light-merkle-tree-metadata light-zero-copy light-hash-set light-indexed-merkle-tree light-batched-merkle-tree
4646
test_cmd: |
4747
cargo test -p aligned-sized
48-
cargo test -p light-bloom-filter
49-
cargo test -p light-hasher
50-
cargo test -p light-compressed-account
51-
cargo test -p light-account-checks
52-
cargo test -p light-verifier
53-
cargo test -p light-merkle-tree-metadata
48+
cargo test -p light-bloom-filter --all-features
49+
cargo test -p light-hasher --all-features
50+
cargo test -p light-compressed-account --all-features
51+
cargo test -p light-account-checks --all-features
52+
cargo test -p light-verifier --all-features
53+
cargo test -p light-merkle-tree-metadata --all-features
5454
cargo test -p light-zero-copy --features std
55-
cargo test -p light-hash-set
56-
cargo test -p light-indexed-merkle-tree
57-
cargo test -p light-batched-merkle-tree --features test-only -- --test test_e2e
55+
cargo test -p light-hash-set --all-features
56+
cargo test -p light-indexed-merkle-tree --all-features
57+
cargo test -p light-batched-merkle-tree --all-features -- --test test_e2e
5858
- name: sdk-libs
5959
packages: light-macros light-sdk light-program-test light-client light-batched-merkle-tree
6060
test_cmd: |

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/anchor/counter/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub mod counter {
2525
address_tree_info: PackedAddressTreeInfo,
2626
output_state_tree_index: u8,
2727
) -> Result<()> {
28-
let program_id = crate::ID.into();
2928
// LightAccount::new_init will create an account with empty output state (no input state).
3029
// Modifying the account will modify the output state that when converted to_account_info()
3130
// is hashed with poseidon hashes, serialized with borsh
@@ -49,7 +48,7 @@ pub mod counter {
4948
let new_address_params = address_tree_info.into_new_address_params_packed(address_seed);
5049

5150
let mut counter = LightAccount::<'_, CounterAccount>::new_init(
52-
&program_id,
51+
&crate::ID,
5352
Some(address),
5453
output_state_tree_index,
5554
);
@@ -74,15 +73,14 @@ pub mod counter {
7473
counter_value: u64,
7574
account_meta: CompressedAccountMeta,
7675
) -> Result<()> {
77-
let program_id = crate::ID.into();
7876
// LightAccount::new_mut will create an account with input state and output state.
7977
// The input state is hashed immediately when calling new_mut().
8078
// Modifying the account will modify the output state that when converted to_account_info()
8179
// is hashed with poseidon hashes, serialized with borsh
8280
// and created with invoke_light_system_program by invoking the light-system-program.
8381
// The hashing scheme is the account structure derived with LightHasher.
8482
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
85-
&program_id,
83+
&crate::ID,
8684
&account_meta,
8785
CounterAccount {
8886
owner: ctx.accounts.signer.key(),
@@ -116,9 +114,8 @@ pub mod counter {
116114
counter_value: u64,
117115
account_meta: CompressedAccountMeta,
118116
) -> Result<()> {
119-
let program_id = crate::ID.into();
120117
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
121-
&program_id,
118+
&crate::ID,
122119
&account_meta,
123120
CounterAccount {
124121
owner: ctx.accounts.signer.key(),
@@ -158,9 +155,8 @@ pub mod counter {
158155
counter_value: u64,
159156
account_meta: CompressedAccountMeta,
160157
) -> Result<()> {
161-
let program_id = crate::ID.into();
162158
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
163-
&program_id,
159+
&crate::ID,
164160
&account_meta,
165161
CounterAccount {
166162
owner: ctx.accounts.signer.key(),
@@ -195,12 +191,11 @@ pub mod counter {
195191
counter_value: u64,
196192
account_meta: CompressedAccountMetaClose,
197193
) -> Result<()> {
198-
let program_id = crate::ID.into();
199194
// LightAccount::new_close() will create an account with only input state and no output state.
200195
// By providing no output state the account is closed after the instruction.
201196
// The address of a closed account cannot be reused.
202197
let counter = LightAccount::<'_, CounterAccount>::new_close(
203-
&program_id,
198+
&crate::ID,
204199
&account_meta,
205200
CounterAccount {
206201
owner: ctx.accounts.signer.key(),

examples/anchor/counter/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #![cfg(feature = "test-sbf")]
1+
#![cfg(feature = "test-sbf")]
22

33
use anchor_lang::{AnchorDeserialize, InstructionData, ToAccountMetas};
44
use counter::CounterAccount;

examples/anchor/token-escrow/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ light-compressed-account = { workspace = true, features = ["anchor"] }
3030

3131
[target.'cfg(not(target_os = "solana"))'.dependencies]
3232
solana-sdk = { workspace = true }
33+
light-test-utils = { workspace = true, features = ["devenv"] }
3334

3435
[dev-dependencies]
3536
light-verifier = { workspace = true }

examples/anchor/token-escrow/src/escrow_with_compressed_pda/escrow.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,18 @@ fn create_compressed_pda_data(
161161
let compressed_account_data = CompressedAccountData {
162162
discriminator: 1u64.to_le_bytes(),
163163
data: timelock_compressed_pda.try_to_vec().unwrap(),
164-
data_hash: timelock_compressed_pda
165-
.hash::<Poseidon>()
166-
.map_err(ProgramError::from)?,
164+
data_hash: timelock_compressed_pda.hash::<Poseidon>().unwrap(),
167165
};
168166
let derive_address = derive_address_legacy(
169167
&ctx.remaining_accounts[new_address_params.address_merkle_tree_account_index as usize]
170-
.key(),
168+
.key()
169+
.into(),
171170
&new_address_params.seed,
172171
)
173172
.map_err(|_| ProgramError::InvalidArgument)?;
174173
Ok(OutputCompressedAccountWithPackedContext {
175174
compressed_account: CompressedAccount {
176-
owner: crate::ID,
175+
owner: crate::ID.into(),
177176
lamports: 0,
178177
address: Some(derive_address),
179178
data: Some(compressed_account_data),

examples/anchor/token-escrow/src/escrow_with_compressed_pda/sdk.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
use anchor_lang::{InstructionData, ToAccountMetas};
44
use light_compressed_account::{
5-
address::{add_and_get_remaining_account_indices, pack_new_address_params},
6-
compressed_account::{pack_merkle_context, CompressedAccount, MerkleContext},
5+
compressed_account::{CompressedAccount, MerkleContext},
76
instruction_data::{
87
compressed_proof::CompressedProof, cpi_context::CompressedCpiContext,
98
data::NewAddressParams,
@@ -14,6 +13,9 @@ use light_compressed_token::process_transfer::{
1413
transfer_sdk::{create_inputs_and_remaining_accounts_checked, to_account_metas},
1514
TokenTransferOutputData,
1615
};
16+
use light_test_utils::pack::{
17+
add_and_get_remaining_account_indices, pack_merkle_context, pack_new_address_params,
18+
};
1719
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
1820

1921
use crate::escrow_with_compressed_pda::escrow::PackedInputCompressedPda;

examples/anchor/token-escrow/src/escrow_with_compressed_pda/withdrawal.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ fn create_compressed_pda_data_based_on_diff(
8383
let old_compressed_account_data = CompressedAccountData {
8484
discriminator: 1u64.to_le_bytes(),
8585
data: old_timelock_compressed_pda.try_to_vec().unwrap(),
86-
data_hash: old_timelock_compressed_pda
87-
.hash::<Poseidon>()
88-
.map_err(ProgramError::from)?,
86+
data_hash: old_timelock_compressed_pda.hash::<Poseidon>().unwrap(),
8987
};
9088
let old_compressed_account = OutputCompressedAccountWithPackedContext {
9189
compressed_account: CompressedAccount {
92-
owner: crate::ID,
90+
owner: crate::ID.into(),
9391
lamports: 0,
9492
address: Some(input_compressed_pda.address),
9593
data: Some(old_compressed_account_data),
@@ -110,13 +108,11 @@ fn create_compressed_pda_data_based_on_diff(
110108
let new_compressed_account_data = CompressedAccountData {
111109
discriminator: 1u64.to_le_bytes(),
112110
data: new_timelock_compressed_pda.try_to_vec().unwrap(),
113-
data_hash: new_timelock_compressed_pda
114-
.hash::<Poseidon>()
115-
.map_err(ProgramError::from)?,
111+
data_hash: new_timelock_compressed_pda.hash::<Poseidon>().unwrap(),
116112
};
117113
let new_state = OutputCompressedAccountWithPackedContext {
118114
compressed_account: CompressedAccount {
119-
owner: crate::ID,
115+
owner: crate::ID.into(),
120116
lamports: 0,
121117
address: Some(input_compressed_pda.address),
122118
data: Some(new_compressed_account_data),
@@ -171,7 +167,7 @@ fn cpi_compressed_pda_withdrawal<'info>(
171167
},
172168
)
173169
.unwrap();
174-
verify_borsh(&light_accounts, &inputs_struct).map_err(ProgramError::from)?;
170+
verify_borsh(&light_accounts, &inputs_struct).unwrap();
175171

176172
Ok(())
177173
}

examples/anchor/token-escrow/src/escrow_with_pda/sdk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use anchor_lang::{InstructionData, ToAccountMetas};
44
use light_compressed_account::{
5-
address::add_and_get_remaining_account_indices,
65
compressed_account::{CompressedAccount, MerkleContext},
76
instruction_data::compressed_proof::CompressedProof,
87
};
@@ -14,6 +13,7 @@ use light_compressed_token::process_transfer::{
1413
},
1514
TokenTransferOutputData,
1615
};
16+
use light_test_utils::pack::add_and_get_remaining_account_indices;
1717
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
1818

1919
use crate::escrow_with_compressed_pda::sdk::get_token_owner_pda;

examples/anchor/token-escrow/tests/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ pub async fn perform_escrow(
195195
leaf_index: compressed_input_account_with_context
196196
.merkle_context
197197
.leaf_index,
198-
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree,
199-
queue_pubkey: env.v1_state_trees[0].nullifier_queue,
198+
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree.into(),
199+
queue_pubkey: env.v1_state_trees[0].nullifier_queue.into(),
200200
prove_by_index: false,
201201
tree_type: TreeType::StateV1,
202202
}],
@@ -331,8 +331,8 @@ pub async fn perform_withdrawal(
331331
leaf_index: compressed_input_account_with_context
332332
.merkle_context
333333
.leaf_index,
334-
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree,
335-
queue_pubkey: env.v1_state_trees[0].nullifier_queue,
334+
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree.into(),
335+
queue_pubkey: env.v1_state_trees[0].nullifier_queue.into(),
336336
prove_by_index: false,
337337
tree_type: TreeType::StateV1,
338338
}],
@@ -369,7 +369,7 @@ pub async fn perform_withdrawal_failing(
369369
) -> Result<solana_sdk::signature::Signature, RpcError> {
370370
let instruction = perform_withdrawal(rpc, payer, withdrawal_amount, invalid_signer).await;
371371

372-
rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[&payer])
372+
rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[payer])
373373
.await
374374
}
375375
pub fn assert_withdrawal<I: Indexer + TestIndexerExtensions>(

0 commit comments

Comments
 (0)