// ATA address is ALWAYS the same for owner + mintlet ata = get_associated_token_address(&owner.pubkey(), &mint);// Address derived from: [owner_pubkey, token_program_id, mint]
ATA 地址的派生方式:
// The ATA address is a PDA of the Associated Token Program;// the account itself is owned by the Token Programlet (ata, bump) = Pubkey::find_program_address( &[ owner.as_ref(), spl_token::id().as_ref(), mint.as_ref(), ], &spl_associated_token_account::id(), // ATA program);
use litesvm::LiteSVM;use litesvm_token::{ get_spl_account, spl_token::{native_mint::DECIMALS, state::Account as TokenAccount}, CreateAccount, CreateMint, MintTo, Transfer,};use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::{Keypair, Signer},};#[test]fn test_create_and_mint_tokens() { let mut svm = LiteSVM::new(); // Create payer account and fund it let payer = Keypair::new(); svm.airdrop(&payer.pubkey(), 10 * LAMPORTS_PER_SOL).unwrap(); // Create a new SPL token mint with the payer as the mint authority let mint = CreateMint::new(&mut svm, &payer) .authority(&payer.pubkey()) .decimals(DECIMALS) .send() .unwrap(); // Create a token account for the payer let token_account = CreateAccount::new(&mut svm, &payer, &mint) .owner(&payer.pubkey()) .send() .unwrap(); // Mint tokens into the payer's token account MintTo::new(&mut svm, &payer, &mint, &token_account, 1000) .owner(&payer) .send() .unwrap(); // Verify balance let token_account: TokenAccount = get_spl_account(&svm, &token_account).unwrap(); let account_balance = token_account.amount; assert_eq!(account_balance, 1000)}