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

# Bắt đầu nhanh

> Tìm hiểu cách kiểm thử chương trình Solana của bạn với LiteSVM

## Thiết lập

Trước khi kiểm thử chương trình, hãy đảm bảo bạn đã:

1. Build chương trình của bạn để tạo ra tệp `.so`
2. Thêm `litesvm` làm dev dependency vào tệp `Cargo.toml`
3. Thêm các dev dependency bổ sung có thể cần thiết, như `solana-sdk@4` và
   `litesvm-token`
4. Tạo một tệp kiểm thử trong thư mục `tests` của bạn

## Bố cục kiểm thử chương trình cơ bản

Dưới đây là tất cả các bước cơ bản cần thiết để gọi và thực thi một instruction trong
chương trình Solana.

```rust tests/program_test.rs
use litesvm::LiteSVM;
use solana_sdk::{
    instruction::{AccountMeta, Instruction},
    pubkey::Pubkey,
    signature::{Keypair, Signer},
    transaction::Transaction,
};

use my_program;

#[test]
fn test_my_program() {
    // Initialize the test environment
    let mut svm = LiteSVM::new();

    // Deploy your program to the test environment. If your program uses an
    // older solana-program (such as 2.2), its ID is a different Pubkey type,
    // so convert it through its bytes.
    let program_id = Pubkey::new_from_array(my_program::ID.to_bytes());
    let program_bytes = include_bytes!("../../../target/deploy/my_program.so");
    svm.add_program(program_id, program_bytes).unwrap();

    // Create and fund test accounts
    let payer = Keypair::new();
    svm.airdrop(&payer.pubkey(), 10_000_000_000).unwrap();

    // Create your instruction
    let instruction = Instruction {
        program_id,
        accounts: vec![
            AccountMeta::new(payer.pubkey(), true),
        ],
        data: vec![],
    };

    // Build transaction
    let tx = Transaction::new_signed_with_payer(
        &[instruction],
        Some(&payer.pubkey()),
        &[&payer],
        svm.latest_blockhash(),
    );

    // Send transaction
    let result = svm.send_transaction(tx).unwrap();

    // Check transaction succeeded
    println!("Transaction logs: {:?}", result.logs);

    println!("Program executed successfully!");
}
```

Môi trường kiểm thử mặc định được tạo bằng `LiteSVM::new()` sẽ bật
các tính năng runtime hiện đang hoạt động trên mainnet-beta, các sysvar mặc định, các
chương trình spl, sigverify và tất cả chương trình tích hợp sẵn, như system program.
Các precompile (ed25519, secp256k1, secp256r1) được đưa vào khi tính năng `precompiles`
của `litesvm` được bật.

Để xây dựng toàn bộ môi trường từ một bộ tính năng khác, chẳng hạn như
`FeatureSet::all_enabled()` từ crate `agave-feature-set`, hãy bắt đầu từ
`LiteSVM::default()` để các sysvar và tài khoản tính năng khớp với nhau:

```rust
use agave_feature_set::FeatureSet;
use litesvm::LiteSVM;
use solana_sdk::native_token::LAMPORTS_PER_SOL;

let mut svm = LiteSVM::default()
    .with_feature_set(FeatureSet::all_enabled())
    .with_builtins()
    .with_lamports(1_000_000 * LAMPORTS_PER_SOL)
    .with_sysvars()
    .with_feature_accounts()
    .with_default_programs()
    .with_sigverify(true)
    .with_blockhash_check(true);
```

Việc nối `with_feature_set` vào `LiteSVM::new()` chỉ thay đổi bộ tính năng:
sysvar Rent và các tài khoản tính năng vẫn giữ nguyên như cách `new()` thiết lập cho
các tính năng của mainnet.

<Info>
  Nếu bạn muốn tương tác với bất kỳ chương trình nào không có trong môi trường
  kiểm thử mặc định, bạn phải triển khai chương trình đó vào môi trường kiểm thử.
</Info>

## Các bước tiếp theo

Trong phần tiếp theo, chúng ta sẽ tìm hiểu tất cả về việc triển khai chương trình vào môi trường
kiểm thử litesvm.
