> ## 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.

# 테스트 헬퍼

> 계정 생성, 토큰 작업, PDA 파생, slot 관리 유틸리티

## 자금이 충전된 계정 생성

테스트에서 가장 흔히 필요한 작업은 SOL이 들어 있는 계정을 만드는 것입니다. `TestHelpers`
trait을 사용하면 이 작업이 매우 간단해집니다.

### 단일 계정

```rust
use litesvm_utils::{LiteSVM, Signer, TestHelpers};
use solana_sdk::native_token::LAMPORTS_PER_SOL;

#[test]
fn test_create_funded_account() {
    let mut svm = LiteSVM::new();

    // Create a funded account with 10 SOL
    let alice = svm.create_funded_account(10 * LAMPORTS_PER_SOL).unwrap();

    // The keypair is ready to use immediately
    println!("Alice's pubkey: {}", alice.pubkey());
}
```

### 여러 계정

```rust
use litesvm_utils::{LiteSVM, Signer, TestHelpers};
use solana_sdk::native_token::LAMPORTS_PER_SOL;

#[test]
fn test_create_multiple_accounts() {
    let mut svm = LiteSVM::new();

    // Create 5 funded accounts, each with 5 SOL
    let accounts = svm.create_funded_accounts(5, 5 * LAMPORTS_PER_SOL).unwrap();

    assert_eq!(accounts.len(), 5);

    for (i, account) in accounts.iter().enumerate() {
        println!("Account {}: {}", i, account.pubkey());
    }
}
```

## 토큰 작업

불필요한 보일러플레이트 없이 토큰 민트와 계정을 생성하세요.

### 토큰 민트 생성

```rust
use litesvm_utils::{LiteSVM, Signer, TestHelpers};
use solana_sdk::native_token::LAMPORTS_PER_SOL;

#[test]
fn test_create_token_mint() {
    let mut svm = LiteSVM::new();

    // Create authority account
    let authority = svm.create_funded_account(10 * LAMPORTS_PER_SOL).unwrap();

    // Create a token mint with 9 decimals (returns Keypair)
    let mint = svm.create_token_mint(&authority, 9).unwrap();

    println!("Mint address: {}", mint.pubkey());
}
```

### Token account 생성

```rust
use litesvm_utils::{LiteSVM, Signer, TestHelpers};
use solana_sdk::native_token::LAMPORTS_PER_SOL;

#[test]
fn test_create_token_accounts() {
    let mut svm = LiteSVM::new();

    let authority = svm.create_funded_account(10 * LAMPORTS_PER_SOL).unwrap();
    let user = svm.create_funded_account(5 * LAMPORTS_PER_SOL).unwrap();

    // Create mint (returns Keypair)
    let mint = svm.create_token_mint(&authority, 9).unwrap();

    // Create a regular token account (returns Keypair)
    let token_account = svm.create_token_account(&mint.pubkey(), &user).unwrap();

    // Or create an Associated Token Account — ATA (returns Pubkey)
    let ata = svm.create_associated_token_account(&mint.pubkey(), &user).unwrap();

    println!("Token account: {}", token_account.pubkey());
    println!("ATA: {}", ata);
}
```

<Info>
  **대부분의 경우 ATA를 사용하세요.** Associated Token Account는 결정적(deterministic)이며
  Solana 규칙을 따릅니다. 동일한 mint/owner 쌍에 대해 여러 계정이 필요한 경우에만
  일반 token account를 사용하세요.
</Info>

### 토큰 발행

```rust
use litesvm_utils::{AssertionHelpers, LiteSVM, Signer, TestHelpers};
use solana_sdk::native_token::LAMPORTS_PER_SOL;

#[test]
fn test_mint_tokens() {
    let mut svm = LiteSVM::new();

    let authority = svm.create_funded_account(10 * LAMPORTS_PER_SOL).unwrap();
    let user = svm.create_funded_account(5 * LAMPORTS_PER_SOL).unwrap();

    // Create mint with authority
    let mint = svm.create_token_mint(&authority, 9).unwrap();

    // Create ATA for user (returns Pubkey)
    let user_ata = svm.create_associated_token_account(&mint.pubkey(), &user).unwrap();

    // Mint 1000 tokens to user's ATA
    svm.mint_to(&mint.pubkey(), &user_ata, &authority, 1000).unwrap();

    // Verify the balance
    svm.assert_token_balance(&user_ata, 1000);
}
```

## PDA 파생

테스트에 필요한 Program Derived Address를 손쉽게 파생하세요.

### 기본 PDA 파생

```rust
use litesvm_utils::{LiteSVM, Pubkey, TestHelpers};

#[test]
fn test_derive_pda() {
    let mut svm = LiteSVM::new();

    let program_id = Pubkey::new_unique();
    let user = Pubkey::new_unique();

    // Get PDA with bump
    let (pda, bump) = svm.derive_pda(
        &[b"user_account", user.as_ref()],
        &program_id,
    );

    println!("PDA: {}, Bump: {}", pda, bump);
}
```

### PDA만 가져오기

```rust
use litesvm_utils::{LiteSVM, Pubkey, TestHelpers};

#[test]
fn test_get_pda() {
    let mut svm = LiteSVM::new();

    let program_id = Pubkey::new_unique();

    // When you don't need the bump
    let pda = svm.get_pda(&[b"config"], &program_id);

    println!("Config PDA: {}", pda);
}
```

<Info>
  CPI 호출 등에서 bump seed가 필요할 때는 `derive_pda`를 사용하세요.
  주소만 필요할 때는 `get_pda`를 사용하세요.
</Info>

## Slot 관리

시간에 의존하는 로직을 테스트할 수 있도록 시간 진행을 제어하세요.

### 현재 slot 가져오기

```rust
use litesvm_utils::{LiteSVM, TestHelpers};

#[test]
fn test_get_current_slot() {
    let mut svm = LiteSVM::new();

    let slot = svm.get_current_slot();
    println!("Current slot: {}", slot);
}
```

### Slot 진행하기

```rust
use litesvm_utils::{LiteSVM, TestHelpers};

#[test]
fn test_advance_slots() {
    let mut svm = LiteSVM::new();

    let initial_slot = svm.get_current_slot();

    // Advance by 100 slots
    svm.advance_slot(100);

    let new_slot = svm.get_current_slot();
    assert_eq!(new_slot, initial_slot + 100);
}
```

## 전체 예제

다음은 여러 테스트 헬퍼를 함께 사용하는 종합 예제입니다:

```rust
use litesvm_utils::{AssertionHelpers, LiteSVM, Signer, TestHelpers};
use solana_sdk::native_token::LAMPORTS_PER_SOL;

#[test]
fn test_complete_setup() {
    let mut svm = LiteSVM::new();

    // Create accounts
    let admin = svm.create_funded_account(100 * LAMPORTS_PER_SOL).unwrap();
    let users = svm.create_funded_accounts(3, 10 * LAMPORTS_PER_SOL).unwrap();

    // Create token infrastructure (returns Keypair)
    let mint = svm.create_token_mint(&admin, 6).unwrap(); // 6 decimals like USDC

    // Create ATAs and mint tokens to each user
    for (i, user) in users.iter().enumerate() {
        // create_associated_token_account returns Pubkey
        let ata = svm.create_associated_token_account(&mint.pubkey(), user).unwrap();
        let amount = (i as u64 + 1) * 1_000_000; // 1, 2, 3 tokens
        svm.mint_to(&mint.pubkey(), &ata, &admin, amount).unwrap();

        // Verify
        svm.assert_token_balance(&ata, amount);
    }

    // Verify total supply
    let total_supply = 1_000_000 + 2_000_000 + 3_000_000;
    svm.assert_mint_supply(&mint.pubkey(), total_supply);

    // Test time-based logic
    let start_slot = svm.get_current_slot();
    svm.advance_slot(1000);
    assert!(svm.get_current_slot() > start_slot);
}
```
