Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename token_pool_bump -> token_pool_index, fix comment #1449

Merged
merged 1 commit into from
Jan 4, 2025
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
62 changes: 31 additions & 31 deletions program-tests/compressed-token-test/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use account_compression::errors::AccountCompressionErrorCode;
use anchor_lang::{
prelude::AccountMeta, system_program, AnchorDeserialize, AnchorSerialize, InstructionData,
ToAccountMetas,
prelude::AccountMeta, system_program, AccountDeserialize, AnchorDeserialize, AnchorSerialize,
InstructionData, ToAccountMetas,
};
use anchor_spl::{
token::{Mint, TokenAccount},
Expand All @@ -16,12 +16,12 @@ use light_compressed_token::{
CreateRevokeInstructionInputs,
},
freeze::sdk::{create_instruction, CreateInstructionInputs},
get_token_pool_pda, get_token_pool_pda_with_bump,
get_token_pool_pda, get_token_pool_pda_with_index,
mint_sdk::{create_create_token_pool_instruction, create_mint_to_instruction},
process_transfer::{
get_cpi_authority_pda, transfer_sdk::create_transfer_instruction, TokenTransferOutputData,
},
spl_compression::check_spl_token_pool_derivation_with_bump,
spl_compression::check_spl_token_pool_derivation_with_index,
token_data::{AccountState, TokenData},
ErrorCode,
};
Expand Down Expand Up @@ -321,7 +321,7 @@ async fn test_failing_create_token_pool() {

let token_pool_pubkey = get_token_pool_pda(&mint.pubkey());
let token_pool_account = rpc.get_account(token_pool_pubkey).await.unwrap().unwrap();
check_spl_token_pool_derivation_with_bump(
check_spl_token_pool_derivation_with_index(
&mint.pubkey().to_bytes(),
&token_pool_pubkey,
&[0],
Expand Down Expand Up @@ -517,23 +517,23 @@ pub async fn add_token_pool<R: RpcConnection>(
fee_payer: &Keypair,
mint: &Pubkey,
invalid_mint: Option<Pubkey>,
token_pool_bump: u8,
token_pool_index: u8,
is_token_22: bool,
mode: FailingTestsAddTokenPool,
) -> Result<Signature, RpcError> {
let token_pool_pda = if mode == FailingTestsAddTokenPool::InvalidTokenPoolPda {
Pubkey::new_unique()
} else {
get_token_pool_pda_with_bump(mint, token_pool_bump)
get_token_pool_pda_with_index(mint, token_pool_index)
};
let existing_token_pool_pda = if mode == FailingTestsAddTokenPool::InvalidExistingTokenPoolPda {
get_token_pool_pda_with_bump(mint, token_pool_bump.saturating_sub(2))
get_token_pool_pda_with_index(mint, token_pool_index.saturating_sub(2))
} else if let Some(invalid_mint) = invalid_mint {
get_token_pool_pda_with_bump(&invalid_mint, token_pool_bump.saturating_sub(1))
get_token_pool_pda_with_index(&invalid_mint, token_pool_index.saturating_sub(1))
} else {
get_token_pool_pda_with_bump(mint, token_pool_bump.saturating_sub(1))
get_token_pool_pda_with_index(mint, token_pool_index.saturating_sub(1))
};
let instruction_data = light_compressed_token::instruction::AddTokenPool { token_pool_bump };
let instruction_data = light_compressed_token::instruction::AddTokenPool { token_pool_index };

let token_program: Pubkey = if mode == FailingTestsAddTokenPool::InvalidTokenProgramId {
Pubkey::new_unique()
Expand Down Expand Up @@ -1567,8 +1567,8 @@ pub async fn mint_tokens_to_all_token_pools<R: RpcConnection>(
} else {
iterator
};
for bump in iterator {
let token_pool_pda = get_token_pool_pda_with_bump(mint, bump);
for token_pool_index in iterator {
let token_pool_pda = get_token_pool_pda_with_index(mint, token_pool_index);
let token_pool_account = rpc.get_account(token_pool_pda).await?;
if token_pool_account.is_some() {
mint_tokens_22_helper_with_lamports_and_bump(
Expand All @@ -1581,22 +1581,22 @@ pub async fn mint_tokens_to_all_token_pools<R: RpcConnection>(
recipients.clone(),
None,
is_token22,
bump,
token_pool_index,
)
.await;
}
}
Ok(())
}
use anchor_lang::AccountDeserialize;

/// Assert that every token pool account contains `amount` tokens.
pub async fn assert_minted_to_all_token_pools<R: RpcConnection>(
rpc: &mut R,
amount: u64,
mint: &Pubkey,
) -> Result<(), RpcError> {
for bump in 0..NUM_MAX_POOL_ACCOUNTS {
let token_pool_pda = get_token_pool_pda_with_bump(&mint, bump);
let token_pool_pda = get_token_pool_pda_with_index(&mint, bump);
let mut token_pool_account = rpc.get_account(token_pool_pda).await?.unwrap();
let token_pool_data =
TokenAccount::try_deserialize_unchecked(&mut &*token_pool_account.data.as_mut_slice())
Expand Down Expand Up @@ -1807,7 +1807,7 @@ async fn test_multiple_decompression() {
.map(|x| x.token_data.amount)
.sum();
let mut add_token_pool_accounts = (0..4)
.map(|x| get_token_pool_pda_with_bump(&mint, x.clone()))
.map(|x| get_token_pool_pda_with_index(&mint, x.clone()))
.collect::<Vec<_>>();
add_token_pool_accounts.shuffle(rng);
decompress_test(
Expand Down Expand Up @@ -3007,7 +3007,7 @@ async fn test_burn() {
.merkle_context
.nullifier_queue_pubkey;
let mut additional_token_pool_accounts = (0..4)
.map(|x| get_token_pool_pda_with_bump(&mint, x))
.map(|x| get_token_pool_pda_with_index(&mint, x))
.collect::<Vec<_>>();
let rng = &mut thread_rng();
additional_token_pool_accounts.shuffle(rng);
Expand Down Expand Up @@ -4364,7 +4364,7 @@ async fn test_failing_decompression() {
decompress_amount,
false,
&token_account_keypair.pubkey(),
Some(get_token_pool_pda_with_bump(&mint, NUM_MAX_POOL_ACCOUNTS)),
Some(get_token_pool_pda_with_index(&mint, NUM_MAX_POOL_ACCOUNTS)),
&mint,
anchor_lang::error::ErrorCode::AccountNotInitialized.into(),
is_token_22,
Expand All @@ -4385,11 +4385,11 @@ async fn test_failing_decompression() {
decompress_amount,
false,
&token_account_keypair.pubkey(),
Some(get_token_pool_pda_with_bump(&mint, 3)),
Some(get_token_pool_pda_with_index(&mint, 3)),
&mint,
ErrorCode::InvalidTokenPoolPda.into(),
is_token_22,
Some(vec![get_token_pool_pda_with_bump(
Some(vec![get_token_pool_pda_with_index(
&mint,
NUM_MAX_POOL_ACCOUNTS,
)]),
Expand Down Expand Up @@ -4447,7 +4447,7 @@ async fn test_failing_decompression() {
decompress_amount,
false,
&token_account_keypair.pubkey(),
Some(get_token_pool_pda_with_bump(&mint, 4)),
Some(get_token_pool_pda_with_index(&mint, 4)),
&mint,
ErrorCode::NoMatchingBumpFound.into(),
is_token_22,
Expand All @@ -4458,7 +4458,7 @@ async fn test_failing_decompression() {
}
// Test 9: FailedToDecompress pass multiple correct token accounts with insufficient balance
{
let token_pool = get_token_pool_pda_with_bump(&mint, 3);
let token_pool = get_token_pool_pda_with_index(&mint, 3);
failing_compress_decompress(
&sender,
&mut context,
Expand All @@ -4475,9 +4475,9 @@ async fn test_failing_decompression() {
is_token_22,
Some(vec![
token_pool,
get_token_pool_pda_with_bump(&mint, 1),
get_token_pool_pda_with_bump(&mint, 2),
get_token_pool_pda_with_bump(&mint, 4),
get_token_pool_pda_with_index(&mint, 1),
get_token_pool_pda_with_index(&mint, 2),
get_token_pool_pda_with_index(&mint, 4),
]),
)
.await
Expand All @@ -4497,11 +4497,11 @@ async fn test_failing_decompression() {
decompress_amount,
false,
&token_account_keypair.pubkey(),
Some(get_token_pool_pda_with_bump(&invalid_mint, 0)),
Some(get_token_pool_pda_with_index(&invalid_mint, 0)),
&mint,
ErrorCode::InvalidTokenPoolPda.into(),
is_token_22,
Some(vec![get_token_pool_pda_with_bump(
Some(vec![get_token_pool_pda_with_index(
&mint,
NUM_MAX_POOL_ACCOUNTS,
)]),
Expand All @@ -4521,11 +4521,11 @@ async fn test_failing_decompression() {
decompress_amount,
false,
&token_account_keypair.pubkey(),
Some(get_token_pool_pda_with_bump(&mint, 4)),
Some(get_token_pool_pda_with_index(&mint, 4)),
&mint,
ErrorCode::InvalidTokenPoolPda.into(),
is_token_22,
Some(vec![get_token_pool_pda_with_bump(&invalid_mint, 0)]),
Some(vec![get_token_pool_pda_with_index(&invalid_mint, 0)]),
)
.await
.unwrap();
Expand Down Expand Up @@ -4622,7 +4622,7 @@ async fn test_failing_decompression() {
compress_amount,
true,
&token_account_keypair.pubkey(),
Some(get_token_pool_pda_with_bump(&invalid_mint, 0)),
Some(get_token_pool_pda_with_index(&invalid_mint, 0)),
&mint,
ErrorCode::InvalidTokenPoolPda.into(),
is_token_22,
Expand Down
50 changes: 25 additions & 25 deletions program-tests/utils/src/spl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use light_compressed_token::{
CreateRevokeInstructionInputs,
},
freeze::sdk::{create_instruction, CreateInstructionInputs},
get_token_pool_pda, get_token_pool_pda_with_bump,
get_token_pool_pda, get_token_pool_pda_with_index,
mint_sdk::{
create_add_token_pool_instruction, create_create_token_pool_instruction,
create_mint_to_instruction,
Expand Down Expand Up @@ -166,7 +166,7 @@ pub async fn mint_tokens_22_helper_with_lamports_and_bump<R: RpcConnection, I: I
recipients: Vec<Pubkey>,
lamports: Option<u64>,
token_22: bool,
token_pool_bump: u8,
token_pool_index: u8,
) {
let payer_pubkey = mint_authority.pubkey();
let instruction = create_mint_to_instruction(
Expand All @@ -178,7 +178,7 @@ pub async fn mint_tokens_22_helper_with_lamports_and_bump<R: RpcConnection, I: I
recipients.clone(),
lamports,
token_22,
token_pool_bump,
token_pool_index,
);

let output_merkle_tree_accounts =
Expand All @@ -190,7 +190,7 @@ pub async fn mint_tokens_22_helper_with_lamports_and_bump<R: RpcConnection, I: I
.unwrap()
.supply;

let pool: Pubkey = get_token_pool_pda_with_bump(mint, token_pool_bump);
let pool: Pubkey = get_token_pool_pda_with_index(mint, token_pool_index);
let previous_pool_amount =
spl_token::state::Account::unpack(&rpc.get_account(pool).await.unwrap().unwrap().data)
.unwrap()
Expand Down Expand Up @@ -385,20 +385,20 @@ pub async fn create_additional_token_pools<R: RpcConnection>(
let mut instructions = Vec::new();
let mut created_token_pools = Vec::new();

for token_pool_bump in 0..NUM_MAX_POOL_ACCOUNTS {
for token_pool_index in 0..NUM_MAX_POOL_ACCOUNTS {
if instructions.len() == num as usize {
break;
}
let token_pool_pda = get_token_pool_pda_with_bump(mint, token_pool_bump);
let token_pool_pda = get_token_pool_pda_with_index(mint, token_pool_index);
let account = rpc.get_account(token_pool_pda).await.unwrap();
println!("bump {}", token_pool_bump);
println!("bump {}", token_pool_index);
println!("account exists {:?}", account.is_some());
if account.is_none() {
created_token_pools.push(token_pool_pda);
let instruction = create_add_token_pool_instruction(
&payer.pubkey(),
mint,
token_pool_bump,
token_pool_index,
is_token_22,
);
instructions.push(instruction);
Expand Down Expand Up @@ -733,7 +733,7 @@ pub async fn decompress_test<R: RpcConnection, I: Indexer<R>>(
recipient_token_account: &Pubkey,
transaction_params: Option<TransactionParams>,
is_token_22: bool,
token_pool_bump: u8,
token_pool_index: u8,
additional_pool_accounts: Option<Vec<Pubkey>>,
) {
let max_amount: u64 = input_compressed_accounts
Expand Down Expand Up @@ -767,7 +767,7 @@ pub async fn decompress_test<R: RpcConnection, I: Indexer<R>>(
)
.await;
let mint = input_compressed_accounts[0].token_data.mint;
let token_pool_pda = get_token_pool_pda_with_bump(&mint, token_pool_bump);
let token_pool_pda = get_token_pool_pda_with_index(&mint, token_pool_index);

let instruction = create_transfer_instruction(
&rpc.get_payer().pubkey(),
Expand Down Expand Up @@ -935,7 +935,7 @@ pub async fn perform_compress_spl_token_account<R: RpcConnection, I: Indexer<R>>
merkle_tree_pubkey: &Pubkey,
remaining_amount: Option<u64>,
is_token_22: bool,
token_pool_bump: u8,
token_pool_index: u8,
) -> Result<(), RpcError> {
let pre_token_account_amount = spl_token::state::Account::unpack(
&rpc.get_account(*token_account).await.unwrap().unwrap().data,
Expand All @@ -952,7 +952,7 @@ pub async fn perform_compress_spl_token_account<R: RpcConnection, I: Indexer<R>>
merkle_tree_pubkey,
token_account,
is_token_22,
token_pool_bump,
token_pool_index,
);
let (event, _, _) = rpc
.create_and_send_transaction_with_event::<PublicTransactionEvent>(
Expand Down Expand Up @@ -1009,7 +1009,7 @@ pub async fn compress_test<R: RpcConnection, I: Indexer<R>>(
sender_token_account: &Pubkey,
transaction_params: Option<TransactionParams>,
is_token_22: bool,
token_pool_bump: u8,
token_pool_index: u8,
additional_pool_accounts: Option<Vec<Pubkey>>,
) {
let output_compressed_account = TokenTransferOutputData {
Expand All @@ -1026,13 +1026,13 @@ pub async fn compress_test<R: RpcConnection, I: Indexer<R>>(
&[output_compressed_account], // output_compressed_accounts
&Vec::new(), // root_indices
&None,
&Vec::new(), // input_token_data
&Vec::new(), // input_compressed_accounts
*mint, // mint
None, // owner_if_delegate_is_signer
true, // is_compress
Some(amount), // compression_amount
Some(get_token_pool_pda_with_bump(mint, token_pool_bump)), // token_pool_pda
&Vec::new(), // input_token_data
&Vec::new(), // input_compressed_accounts
*mint, // mint
None, // owner_if_delegate_is_signer
true, // is_compress
Some(amount), // compression_amount
Some(get_token_pool_pda_with_index(mint, token_pool_index)), // token_pool_pda
Some(*sender_token_account), // compress_or_decompress_token_account
true,
None,
Expand Down Expand Up @@ -1569,7 +1569,7 @@ pub async fn burn_test<R: RpcConnection, I: Indexer<R>>(
signer_is_delegate: bool,
transaction_params: Option<TransactionParams>,
is_token_22: bool,
token_pool_bump: u8,
token_pool_index: u8,
) {
let (
input_compressed_account_hashes,
Expand All @@ -1587,7 +1587,7 @@ pub async fn burn_test<R: RpcConnection, I: Indexer<R>>(
signer_is_delegate,
BurnInstructionMode::Normal,
is_token_22,
token_pool_bump,
token_pool_index,
None,
)
.await;
Expand All @@ -1601,7 +1601,7 @@ pub async fn burn_test<R: RpcConnection, I: Indexer<R>>(
Vec::new()
};

let token_pool_pda_address = get_token_pool_pda_with_bump(&mint, token_pool_bump);
let token_pool_pda_address = get_token_pool_pda_with_index(&mint, token_pool_index);
let pre_token_pool_account = rpc
.get_account(token_pool_pda_address)
.await
Expand Down Expand Up @@ -1712,7 +1712,7 @@ pub async fn create_burn_test_instruction<R: RpcConnection, I: Indexer<R>>(
signer_is_delegate: bool,
mode: BurnInstructionMode,
is_token_22: bool,
token_pool_bump: u8,
token_pool_index: u8,
additional_pool_accounts: Option<Vec<Pubkey>>,
) -> (Vec<[u8; 32]>, Vec<Pubkey>, Pubkey, u64, Instruction) {
let input_compressed_account_hashes = input_compressed_accounts
Expand Down Expand Up @@ -1769,7 +1769,7 @@ pub async fn create_burn_test_instruction<R: RpcConnection, I: Indexer<R>>(
signer_is_delegate,
burn_amount,
is_token_22,
token_pool_bump,
token_pool_index,
additional_pool_accounts: additional_pool_accounts.unwrap_or_default(),
};
let input_amount_sum = input_compressed_accounts
Expand Down
Loading
Loading