> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# SPL 토큰 작업

> litesvm-token을 사용하여 SPL 토큰으로 테스트를 작성하는 방법

<Note>
  `cargo add --dev litesvm litesvm-token solana-sdk@4 spl-token` 실행이 필요합니다
</Note>

## 전체 테스트

```rust tests/spl_token_test.rs
use litesvm::LiteSVM;
use litesvm_token::{
    get_spl_account,
    spl_token::{native_mint::DECIMALS, state::Account as TokenAccount},
    CreateAssociatedTokenAccount, CreateMint, MintTo, Transfer,
};
use solana_sdk::{
    native_token::LAMPORTS_PER_SOL,
    signature::{Keypair, Signer},
};

#[test]
fn test_token_transfer() {
        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 two users
    let alice = Keypair::new();
    let bob = Keypair::new();

    // Create a new SPL token mint with alice as the mint authority
    let mint = CreateMint::new(&mut svm, &payer)
        .authority(&alice.pubkey())
        .decimals(DECIMALS)
        .send()
        .unwrap();

    // Create associated token accounts (ATAs) for alice and bob
    let alice_token_account = CreateAssociatedTokenAccount::new(&mut svm, &payer, &mint)
        .owner(&alice.pubkey())
        .send()
        .unwrap();

    let bob_token_account = CreateAssociatedTokenAccount::new(&mut svm, &payer, &mint)
        .owner(&bob.pubkey())
        .send()
        .unwrap();

    // Mint 1000 tokens to Alice's account
    MintTo::new(&mut svm, &payer, &mint, &alice_token_account, 1000)
        .owner(&alice)
        .send()
        .unwrap();

    // Transfer 400 tokens from Alice to Bob
    Transfer::new(&mut svm, &payer, &mint, &bob_token_account, 400)
        .source(&alice_token_account)
        .owner(&alice)
        .send()
        .unwrap();

    // Verify balances
    let alice_account: TokenAccount = get_spl_account(&svm, &alice_token_account).unwrap();
    let bob_account: TokenAccount = get_spl_account(&svm, &bob_token_account).unwrap();

    let alice_balance = alice_account.amount;
    let bob_balance = bob_account.amount;

    assert_eq!(alice_balance, 600);
    assert_eq!(bob_balance, 400);

    println!("SPL token transfer successful!");
}
```

## 핵심 포인트

1. **litesvm-token**: SPL 토큰 테스트를 간소화하는 헬퍼 크레이트
2. **민트 생성**: 지정한 소수점 자릿수(decimals)와 권한으로 민트를 생성합니다
3. **token account**: 사용자의 토큰을 보관할 token account를 생성합니다
   - 이것과 ATA의 차이점을 이해하려면
     [이 섹션](/developers/docs/tools/litesvm/additional-crates/testing-with-spl-tokens#types-of-token-accounts)을 읽어보세요.
4. **민팅**: 민트 권한을 사용하여 token account에 토큰을 발행합니다
5. **소수점 자릿수**: 금액을 지정할 때 소수점 자릿수를 반드시 고려하세요

## 참고 항목

- [SPL 토큰으로 테스트하기](/developers/docs/tools/litesvm/additional-crates/testing-with-spl-tokens) -
  SPL 토큰 테스트에 대한 종합 가이드
