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

# Funkcje pomocnicze do testów

> Narzędzia do tworzenia kont, operacji na tokenach, derywacji PDA oraz obsługi mechanizmu slot

## Tworzenie kont z saldem

Najczęstszą potrzebą podczas testowania jest tworzenie kont z SOL. Trait `TestHelpers`
sprawia, że jest to banalnie proste.

### Pojedyncze konto

```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());
}
```

### Wiele kont

```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());
    }
}
```

## Operacje na tokenach

Twórz mint tokenów i konta bez typowego boilerplate'u.

### Tworzenie mintu tokenu

```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());
}
```

### Tworzenie 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>
  **W większości przypadków używaj ATA.** Każdy associated token account ma deterministyczny adres i jest zgodny z konwencjami Solana. Zwykłych kont typu token account używaj tylko wtedy, gdy potrzebujesz wielu kont dla tej samej pary mint/właściciel.
</Info>

### Emisja tokenów

```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);
}
```

## Derywacja PDA

Łatwo wyprowadzaj adresy PDA (Program Derived Address) na potrzeby testów.

### Podstawowa derywacja 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);
}
```

### Pobieranie samego 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>
  Użyj `derive_pda`, gdy potrzebujesz bump seed (np. do wywołań CPI). Użyj `get_pda`, gdy potrzebujesz tylko adresu.
</Info>

## Zarządzanie mechanizmem slot

Kontroluj upływ czasu, aby testować logikę zależną od czasu.

### Pobierz bieżący 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);
}
```

### Przesuń slot do przodu

```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);
}
```

## Kompletny przykład

Oto kompleksowy przykład wspólnego użycia kilku funkcji pomocniczych do testów:

```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);
}
```
