Skip to content
Open
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
6 changes: 5 additions & 1 deletion Cargo.lock

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

56 changes: 31 additions & 25 deletions forester/tests/test_indexer_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
/// This test creates various account types for testing the indexer's interface racing logic.
/// After running, use `cargo xtask export-photon-test-data --test-name indexer_interface`
/// to export transactions to the indexer's test snapshot directory.
///
/// Scenarios covered:
/// 1. Light Token Mint - mint for token operations
/// 2. Token accounts (via light-token-client MintTo) - for getTokenAccountInterface
/// 3. Registered v2 address in batched address tree - for address tree verification
/// 4. Compressible token accounts - on-chain accounts that can be compressed
use std::collections::HashMap;

use anchor_lang::Discriminator;
use anchor_lang::{AnchorDeserialize, Discriminator};
use borsh::BorshSerialize;
use create_address_test_program::create_invoke_cpi_instruction;
use light_client::{
Expand Down Expand Up @@ -368,6 +362,13 @@ async fn test_indexer_interface_scenarios() {
compressed_mint_pda, create_mint_sig
);

// Warp forward so rent expires - required before CompressAndCloseMint
let current_slot = rpc.get_slot().await.unwrap();
let target_slot = current_slot + light_compressible::rent::SLOTS_PER_EPOCH * 30;
rpc.warp_to_slot(target_slot)
.await
.expect("warp_to_slot so mint rent expires");

// Now compress and close the mint to make it fully compressed
println!("Compressing mint via CompressAndCloseMint...");

Expand Down Expand Up @@ -483,36 +484,41 @@ async fn test_indexer_interface_scenarios() {
);
println!(" PASSED: Compressible account resolved from on-chain");

// ============ Test 2: getTokenAccountInterface with compressible token account (on-chain) ============
println!("\nTest 2: getTokenAccountInterface with compressible token account (on-chain)...");
let compressible_token_interface = photon_indexer
.get_token_account_interface(&compressible_token_account, None)
println!("\nTest 2: getAccountInterface for compressible token account (on-chain)...");
let compressible_token_interface = rpc
.get_account_interface(&compressible_token_account, None)
.await
.expect("getTokenAccountInterface should not error")
.expect("getAccountInterface should not error")
.value
.expect("Compressible token account should be found via token interface");
.expect("Compressible token account should be found");

assert!(
compressible_token_interface.account.is_hot(),
compressible_token_interface.is_hot(),
"Token account should be hot (on-chain)"
);
assert!(
compressible_token_interface.account.cold.is_none(),
compressible_token_interface.cold.is_none(),
"On-chain token account should not have cold context"
);
assert_eq!(
compressible_token_interface.account.key, compressible_token_account,
compressible_token_interface.key, compressible_token_account,
"Token account key should match"
);
assert_eq!(
compressible_token_interface.token.mint, decompressed_mint_pda,
"Token mint should match decompressed mint"
);
assert_eq!(
compressible_token_interface.token.owner,
compressible_owner.pubkey(),
"Token owner should match compressible owner"
);
{
let token = light_token_interface::state::Token::deserialize(
&mut &compressible_token_interface.account.data[..],
)
.expect("parse token account");
assert_eq!(
token.mint, decompressed_mint_pda,
"Token mint should match decompressed mint"
);
assert_eq!(
token.owner,
compressible_owner.pubkey(),
"Token owner should match compressible owner"
);
}
println!(" PASSED: Token account interface resolved with correct token data");

// ============ Test 3: getMultipleAccountInterfaces batch lookup ============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use light_test_utils::{
};
use light_token::{
instruction::{
derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, CreateTokenAccount,
TransferFromSpl,
get_associated_token_address, CompressibleParams, CreateAssociatedTokenAccount,
CreateTokenAccount, TransferFromSpl,
},
utils::get_associated_token_address_and_bump,
};
Expand Down Expand Up @@ -347,7 +347,7 @@ async fn test_ata_decompress_to_different_ata_fails() {
let mint2_pubkey = mint2_keypair.pubkey();

// Create ATA for same owner but different mint
let ata2_pubkey = derive_token_ata(&context.owner.pubkey(), &mint2_pubkey);
let ata2_pubkey = get_associated_token_address(&context.owner.pubkey(), &mint2_pubkey);

let create_ata2_ix = CreateAssociatedTokenAccount::new(
context.payer.pubkey(),
Expand Down
6 changes: 4 additions & 2 deletions program-tests/compressed-token-test/tests/light_token/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ use light_test_utils::{
actions::legacy::instructions::mint_action::DecompressMintParams,
assert_ctoken_burn::assert_ctoken_burn,
};
use light_token::instruction::{derive_token_ata, Burn, CreateAssociatedTokenAccount, MintTo};
use light_token::instruction::{
get_associated_token_address, Burn, CreateAssociatedTokenAccount, MintTo,
};

use super::shared::*;

Expand Down Expand Up @@ -336,7 +338,7 @@ async fn setup_burn_test() -> BurnTestContext {
let (mint_pda, _) = find_mint_address(&mint_seed.pubkey());

// Step 1: Create Light Token ATA for owner
let ctoken_ata = derive_token_ata(&owner_keypair.pubkey(), &mint_pda);
let ctoken_ata = get_associated_token_address(&owner_keypair.pubkey(), &mint_pda);

let create_ata_ix =
CreateAssociatedTokenAccount::new(payer.pubkey(), owner_keypair.pubkey(), mint_pda)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ async fn test_compress_and_close_owner_scenarios() {
.await;

// Set token balance on ATA
use light_token::instruction::derive_token_ata;
let ata_pubkey = derive_token_ata(&context.owner_keypair.pubkey(), &context.mint_pubkey);
use light_token::instruction::get_associated_token_address;
let ata_pubkey =
get_associated_token_address(&context.owner_keypair.pubkey(), &context.mint_pubkey);

let mut ata_account = context.rpc.get_account(ata_pubkey).await.unwrap().unwrap();

Expand Down
25 changes: 13 additions & 12 deletions program-tests/compressed-token-test/tests/light_token/create_ata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async fn test_create_compressible_ata() {
.unwrap();

// Verify ATA was created at the expected address
let expected_ata = derive_token_ata(&owner_and_mint, &owner_and_mint);
let expected_ata = get_associated_token_address(&owner_and_mint, &owner_and_mint);
let account = context.rpc.get_account(expected_ata).await.unwrap();
assert!(
account.is_some(),
Expand Down Expand Up @@ -419,7 +419,8 @@ async fn test_create_ata_failing() {

// Use different mint for this test
context.mint_pubkey = solana_sdk::pubkey::Pubkey::new_unique();
let ata_pubkey = derive_token_ata(&context.owner_keypair.pubkey(), &context.mint_pubkey);
let ata_pubkey =
get_associated_token_address(&context.owner_keypair.pubkey(), &context.mint_pubkey);

// Manually build instruction data with compress_to_account_pubkey (forbidden for ATAs)
let compress_to_pubkey = CompressToPubkey {
Expand Down Expand Up @@ -768,7 +769,7 @@ async fn test_create_ata_failing() {
let owner = solana_sdk::pubkey::Pubkey::new_unique();

// Derive ATA address
let ata_pubkey = derive_token_ata(&owner, &mint_with_restricted_ext);
let ata_pubkey = get_associated_token_address(&owner, &mint_with_restricted_ext);

// Build instruction data with compressible_config: None (non-compressible)
let instruction_data = CreateAssociatedTokenAccountInstructionData {
Expand Down Expand Up @@ -923,9 +924,9 @@ async fn test_ata_multiple_mints_same_owner() {
assert_ne!(ata2, ata3, "ATA for mint2 and mint3 should be different");

// Verify each ATA is derived correctly for its mint
let expected_ata1 = derive_token_ata(&owner, &mint1);
let expected_ata2 = derive_token_ata(&owner, &mint2);
let expected_ata3 = derive_token_ata(&owner, &mint3);
let expected_ata1 = get_associated_token_address(&owner, &mint1);
let expected_ata2 = get_associated_token_address(&owner, &mint2);
let expected_ata3 = get_associated_token_address(&owner, &mint3);

assert_eq!(ata1, expected_ata1, "ATA1 should match expected derivation");
assert_eq!(ata2, expected_ata2, "ATA2 should match expected derivation");
Expand Down Expand Up @@ -978,7 +979,7 @@ async fn test_ata_multiple_owners_same_mint() {
.await
.unwrap();

let ata1 = derive_token_ata(&owner1, &mint);
let ata1 = get_associated_token_address(&owner1, &mint);

// Assert ATA1 was created correctly
assert_create_associated_token_account(
Expand All @@ -1001,7 +1002,7 @@ async fn test_ata_multiple_owners_same_mint() {
.await
.unwrap();

let ata2 = derive_token_ata(&owner2, &mint);
let ata2 = get_associated_token_address(&owner2, &mint);

// Assert ATA2 was created correctly
assert_create_associated_token_account(
Expand All @@ -1024,7 +1025,7 @@ async fn test_ata_multiple_owners_same_mint() {
.await
.unwrap();

let ata3 = derive_token_ata(&owner3, &mint);
let ata3 = get_associated_token_address(&owner3, &mint);

// Assert ATA3 was created correctly
assert_create_associated_token_account(
Expand All @@ -1042,9 +1043,9 @@ async fn test_ata_multiple_owners_same_mint() {
assert_ne!(ata2, ata3, "ATA for owner2 and owner3 should be different");

// Verify each ATA is derived correctly for its owner
let expected_ata1 = derive_token_ata(&owner1, &mint);
let expected_ata2 = derive_token_ata(&owner2, &mint);
let expected_ata3 = derive_token_ata(&owner3, &mint);
let expected_ata1 = get_associated_token_address(&owner1, &mint);
let expected_ata2 = get_associated_token_address(&owner2, &mint);
let expected_ata3 = get_associated_token_address(&owner3, &mint);

assert_eq!(ata1, expected_ata1, "ATA1 should match expected derivation");
assert_eq!(ata2, expected_ata2, "ATA2 should match expected derivation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn create_and_assert_ata2(
let payer_pubkey = context.payer.pubkey();
let owner_pubkey = context.owner_keypair.pubkey();

let ata_pubkey = derive_token_ata(&owner_pubkey, &context.mint_pubkey);
let ata_pubkey = get_associated_token_address(&owner_pubkey, &context.mint_pubkey);

let create_ata_ix = if let Some(compressible) = compressible_data.as_ref() {
let compressible_params = CompressibleParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async fn test_associated_token_account_operations() {

// Test closing compressible ATA
let compressible_ata_pubkey =
derive_token_ata(&compressible_owner_pubkey, &context.mint_pubkey);
get_associated_token_address(&compressible_owner_pubkey, &context.mint_pubkey);

// Create a separate destination account
let destination = Keypair::new();
Expand Down Expand Up @@ -272,7 +272,7 @@ async fn test_create_ata_with_prefunded_lamports() {
let owner_pubkey = context.owner_keypair.pubkey();

// Derive ATA address
let ata = derive_token_ata(&owner_pubkey, &context.mint_pubkey);
let ata = get_associated_token_address(&owner_pubkey, &context.mint_pubkey);

// Pre-fund the ATA address with lamports (simulating attacker donation DoS attempt)
let prefund_amount = 1_000; // 1000 lamports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub use light_test_utils::{
Rpc, RpcError,
};
pub use light_token::instruction::{
derive_token_ata, Approve, CloseAccount, CompressibleParams, CreateAssociatedTokenAccount,
CreateTokenAccount, Revoke,
get_associated_token_address, Approve, CloseAccount, CompressibleParams,
CreateAssociatedTokenAccount, CreateTokenAccount, Revoke,
};
pub use serial_test::serial;
pub use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer};
Expand Down Expand Up @@ -384,7 +384,7 @@ pub async fn create_and_assert_ata(
let owner_pubkey = context.owner_keypair.pubkey();

// Derive ATA address
let ata_pubkey = derive_token_ata(&owner_pubkey, &context.mint_pubkey);
let ata_pubkey = get_associated_token_address(&owner_pubkey, &context.mint_pubkey);

// Build instruction based on whether it's compressible
let create_ata_ix = if let Some(compressible) = compressible_data.as_ref() {
Expand Down
4 changes: 2 additions & 2 deletions program-tests/compressed-token-test/tests/mint/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use light_test_utils::{
actions::legacy::instructions::mint_action::DecompressMintParams,
assert_ctoken_burn::assert_ctoken_burn, Rpc,
};
use light_token::instruction::{derive_token_ata, Burn, CreateAssociatedTokenAccount};
use light_token::instruction::{get_associated_token_address, Burn, CreateAssociatedTokenAccount};
use light_token_interface::instructions::mint_action::Recipient;
use serial_test::serial;
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer};
Expand Down Expand Up @@ -40,7 +40,7 @@ async fn setup_burn_test(mint_amount: u64) -> BurnTestContext {
let (mint_pda, _) = find_mint_address(&mint_seed.pubkey());

// Step 1: Create Light Token ATA for owner first (needed before minting)
let ctoken_ata = derive_token_ata(&owner_keypair.pubkey(), &mint_pda);
let ctoken_ata = get_associated_token_address(&owner_keypair.pubkey(), &mint_pda);

let create_ata_ix =
CreateAssociatedTokenAccount::new(payer.pubkey(), owner_keypair.pubkey(), mint_pda)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use light_test_utils::{
Rpc,
};
use light_token::instruction::{
derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount,
get_associated_token_address, CompressibleParams, CreateAssociatedTokenAccount,
};
use light_token_interface::{
instructions::extensions::token_metadata::TokenMetadataInstructionData,
Expand Down Expand Up @@ -566,7 +566,7 @@ async fn test_cmint_all_operations() {
},
// MintToCToken (decompressed recipient)
MintActionType::MintToCToken {
account: derive_token_ata(&recipient.pubkey(), &spl_mint_pda),
account: get_associated_token_address(&recipient.pubkey(), &spl_mint_pda),
amount: 2000,
},
// UpdateMintAuthority
Expand Down Expand Up @@ -967,7 +967,7 @@ async fn test_decompress_with_mint_to_ctoken() {
write_top_up: 0,
},
MintActionType::MintToCToken {
account: derive_token_ata(&recipient.pubkey(), &spl_mint_pda),
account: get_associated_token_address(&recipient.pubkey(), &spl_mint_pda),
amount: 5000,
},
];
Expand Down Expand Up @@ -1103,7 +1103,7 @@ async fn test_decompress_with_all_operations() {
},
// MintToCToken (decompressed recipient)
MintActionType::MintToCToken {
account: derive_token_ata(&recipient.pubkey(), &spl_mint_pda),
account: get_associated_token_address(&recipient.pubkey(), &spl_mint_pda),
amount: 2000,
},
// UpdateMintAuthority
Expand Down
5 changes: 4 additions & 1 deletion program-tests/compressed-token-test/tests/mint/edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ async fn functional_all_in_one_instruction() {
},
// 2. MintToCToken - mint to decompressed account
MintActionType::MintToCToken {
account: light_token::instruction::derive_token_ata(&recipient.pubkey(), &spl_mint_pda),
account: light_token::instruction::get_associated_token_address(
&recipient.pubkey(),
&spl_mint_pda,
),
amount: 2000u64,
},
// 3. UpdateMintAuthority
Expand Down
9 changes: 6 additions & 3 deletions program-tests/compressed-token-test/tests/mint/failing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,10 @@ async fn functional_and_failing_tests() {
.await
.unwrap();

let recipient_ata =
light_token::instruction::derive_token_ata(&recipient2.pubkey(), &spl_mint_pda);
let recipient_ata = light_token::instruction::get_associated_token_address(
&recipient2.pubkey(),
&spl_mint_pda,
);

// Try to mint with valid NEW authority (since we updated it)
let result = light_test_utils::actions::mint_action_comprehensive(
Expand Down Expand Up @@ -883,7 +885,8 @@ async fn test_mint_to_ctoken_max_top_up_exceeded() {
.await
.unwrap();

let ctoken_ata = light_token::instruction::derive_token_ata(&recipient.pubkey(), &spl_mint_pda);
let ctoken_ata =
light_token::instruction::get_associated_token_address(&recipient.pubkey(), &spl_mint_pda);

// 3. Build MintToCToken instruction with max_top_up = 1 (too low)
// Get current compressed mint state
Expand Down
Loading
Loading