Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ jobs:
light-verifier light-merkle-tree-metadata light-zero-copy light-hash-set light-indexed-merkle-tree light-batched-merkle-tree
test_cmd: |
cargo test -p aligned-sized
cargo test -p light-bloom-filter
cargo test -p light-hasher
cargo test -p light-compressed-account
cargo test -p light-account-checks
cargo test -p light-verifier
cargo test -p light-merkle-tree-metadata
cargo test -p light-bloom-filter --all-features
cargo test -p light-hasher --all-features
cargo test -p light-compressed-account --all-features
cargo test -p light-account-checks --all-features
cargo test -p light-verifier --all-features
cargo test -p light-merkle-tree-metadata --all-features
cargo test -p light-zero-copy --features std
cargo test -p light-hash-set
cargo test -p light-indexed-merkle-tree
cargo test -p light-batched-merkle-tree --features test-only -- --test test_e2e
cargo test -p light-hash-set --all-features
cargo test -p light-indexed-merkle-tree --all-features
cargo test -p light-batched-merkle-tree --all-features -- --test test_e2e
- name: sdk-libs
packages: light-macros light-sdk light-program-test light-client light-batched-merkle-tree
test_cmd: |
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions examples/anchor/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod counter {
address_tree_info: PackedAddressTreeInfo,
output_state_tree_index: u8,
) -> Result<()> {
let program_id = crate::ID.into();
// LightAccount::new_init will create an account with empty output state (no input state).
// Modifying the account will modify the output state that when converted to_account_info()
// is hashed with poseidon hashes, serialized with borsh
Expand All @@ -49,7 +48,7 @@ pub mod counter {
let new_address_params = address_tree_info.into_new_address_params_packed(address_seed);

let mut counter = LightAccount::<'_, CounterAccount>::new_init(
&program_id,
&crate::ID,
Some(address),
output_state_tree_index,
);
Expand All @@ -74,15 +73,14 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMeta,
) -> Result<()> {
let program_id = crate::ID.into();
// LightAccount::new_mut will create an account with input state and output state.
// The input state is hashed immediately when calling new_mut().
// Modifying the account will modify the output state that when converted to_account_info()
// is hashed with poseidon hashes, serialized with borsh
// and created with invoke_light_system_program by invoking the light-system-program.
// The hashing scheme is the account structure derived with LightHasher.
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down Expand Up @@ -116,9 +114,8 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMeta,
) -> Result<()> {
let program_id = crate::ID.into();
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down Expand Up @@ -158,9 +155,8 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMeta,
) -> Result<()> {
let program_id = crate::ID.into();
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down Expand Up @@ -195,12 +191,11 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMetaClose,
) -> Result<()> {
let program_id = crate::ID.into();
// LightAccount::new_close() will create an account with only input state and no output state.
// By providing no output state the account is closed after the instruction.
// The address of a closed account cannot be reused.
let counter = LightAccount::<'_, CounterAccount>::new_close(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down
2 changes: 1 addition & 1 deletion examples/anchor/counter/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #![cfg(feature = "test-sbf")]
#![cfg(feature = "test-sbf")]

use anchor_lang::{AnchorDeserialize, InstructionData, ToAccountMetas};
use counter::CounterAccount;
Expand Down
1 change: 1 addition & 0 deletions examples/anchor/token-escrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ light-compressed-account = { workspace = true, features = ["anchor"] }

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

[dev-dependencies]
light-verifier = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,18 @@ fn create_compressed_pda_data(
let compressed_account_data = CompressedAccountData {
discriminator: 1u64.to_le_bytes(),
data: timelock_compressed_pda.try_to_vec().unwrap(),
data_hash: timelock_compressed_pda
.hash::<Poseidon>()
.map_err(ProgramError::from)?,
data_hash: timelock_compressed_pda.hash::<Poseidon>().unwrap(),
};
let derive_address = derive_address_legacy(
&ctx.remaining_accounts[new_address_params.address_merkle_tree_account_index as usize]
.key(),
.key()
.into(),
&new_address_params.seed,
)
.map_err(|_| ProgramError::InvalidArgument)?;
Ok(OutputCompressedAccountWithPackedContext {
compressed_account: CompressedAccount {
owner: crate::ID,
owner: crate::ID.into(),
lamports: 0,
address: Some(derive_address),
data: Some(compressed_account_data),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use anchor_lang::{InstructionData, ToAccountMetas};
use light_compressed_account::{
address::{add_and_get_remaining_account_indices, pack_new_address_params},
compressed_account::{pack_merkle_context, CompressedAccount, MerkleContext},
compressed_account::{CompressedAccount, MerkleContext},
instruction_data::{
compressed_proof::CompressedProof, cpi_context::CompressedCpiContext,
data::NewAddressParams,
Expand All @@ -14,6 +13,9 @@ use light_compressed_token::process_transfer::{
transfer_sdk::{create_inputs_and_remaining_accounts_checked, to_account_metas},
TokenTransferOutputData,
};
use light_test_utils::pack::{
add_and_get_remaining_account_indices, pack_merkle_context, pack_new_address_params,
};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};

use crate::escrow_with_compressed_pda::escrow::PackedInputCompressedPda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ fn create_compressed_pda_data_based_on_diff(
let old_compressed_account_data = CompressedAccountData {
discriminator: 1u64.to_le_bytes(),
data: old_timelock_compressed_pda.try_to_vec().unwrap(),
data_hash: old_timelock_compressed_pda
.hash::<Poseidon>()
.map_err(ProgramError::from)?,
data_hash: old_timelock_compressed_pda.hash::<Poseidon>().unwrap(),
};
let old_compressed_account = OutputCompressedAccountWithPackedContext {
compressed_account: CompressedAccount {
owner: crate::ID,
owner: crate::ID.into(),
lamports: 0,
address: Some(input_compressed_pda.address),
data: Some(old_compressed_account_data),
Expand All @@ -110,13 +108,11 @@ fn create_compressed_pda_data_based_on_diff(
let new_compressed_account_data = CompressedAccountData {
discriminator: 1u64.to_le_bytes(),
data: new_timelock_compressed_pda.try_to_vec().unwrap(),
data_hash: new_timelock_compressed_pda
.hash::<Poseidon>()
.map_err(ProgramError::from)?,
data_hash: new_timelock_compressed_pda.hash::<Poseidon>().unwrap(),
};
let new_state = OutputCompressedAccountWithPackedContext {
compressed_account: CompressedAccount {
owner: crate::ID,
owner: crate::ID.into(),
lamports: 0,
address: Some(input_compressed_pda.address),
data: Some(new_compressed_account_data),
Expand Down Expand Up @@ -171,7 +167,7 @@ fn cpi_compressed_pda_withdrawal<'info>(
},
)
.unwrap();
verify_borsh(&light_accounts, &inputs_struct).map_err(ProgramError::from)?;
verify_borsh(&light_accounts, &inputs_struct).unwrap();

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/anchor/token-escrow/src/escrow_with_pda/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use anchor_lang::{InstructionData, ToAccountMetas};
use light_compressed_account::{
address::add_and_get_remaining_account_indices,
compressed_account::{CompressedAccount, MerkleContext},
instruction_data::compressed_proof::CompressedProof,
};
Expand All @@ -14,6 +13,7 @@ use light_compressed_token::process_transfer::{
},
TokenTransferOutputData,
};
use light_test_utils::pack::add_and_get_remaining_account_indices;
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};

use crate::escrow_with_compressed_pda::sdk::get_token_owner_pda;
Expand Down
10 changes: 5 additions & 5 deletions examples/anchor/token-escrow/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ pub async fn perform_escrow(
leaf_index: compressed_input_account_with_context
.merkle_context
.leaf_index,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree,
queue_pubkey: env.v1_state_trees[0].nullifier_queue,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree.into(),
queue_pubkey: env.v1_state_trees[0].nullifier_queue.into(),
prove_by_index: false,
tree_type: TreeType::StateV1,
}],
Expand Down Expand Up @@ -331,8 +331,8 @@ pub async fn perform_withdrawal(
leaf_index: compressed_input_account_with_context
.merkle_context
.leaf_index,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree,
queue_pubkey: env.v1_state_trees[0].nullifier_queue,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree.into(),
queue_pubkey: env.v1_state_trees[0].nullifier_queue.into(),
prove_by_index: false,
tree_type: TreeType::StateV1,
}],
Expand Down Expand Up @@ -369,7 +369,7 @@ pub async fn perform_withdrawal_failing(
) -> Result<solana_sdk::signature::Signature, RpcError> {
let instruction = perform_withdrawal(rpc, payer, withdrawal_amount, invalid_signer).await;

rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[&payer])
rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[payer])
.await
}
pub fn assert_withdrawal<I: Indexer + TestIndexerExtensions>(
Expand Down
Loading