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

# Cấu hình môi trường

> Các phương thức builder để cấu hình môi trường kiểm thử LiteSVM

Tất cả các phương thức cấu hình đều là phương thức builder được nối chuỗi trên `LiteSVM::new()`.

<Warning>
  Không nên bắt đầu từ `LiteSVM::default()`. Hàm này tạo ra một instance trống không có
  sysvar, chương trình hay tài khoản airdrop, nên `airdrop` sẽ panic và các giao dịch
  sẽ thất bại. `LiteSVM::new()` trả về một instance đã được thiết lập đầy đủ, sau đó bạn có thể
  tùy chỉnh bằng các phương thức bên dưới.
</Warning>

## with_compute_budget

```rust
pub fn with_compute_budget(self, compute_budget: ComputeBudget) -> Self
```

Đặt giới hạn compute unit và kích thước heap.

```rust
use solana_compute_budget::compute_budget::ComputeBudget;

let mut svm = LiteSVM::new()
    .with_compute_budget(ComputeBudget {
        compute_unit_limit: 1_400_000,
        heap_size: 256 * 1024,
        ..ComputeBudget::new_with_defaults(true)
    });
```

## with_sigverify

```rust
pub fn with_sigverify(self, sigverify: bool) -> Self
```

Bật hoặc tắt xác minh chữ ký. Mặc định: `true`.

```rust
// Disable for faster tests
let mut svm = LiteSVM::new()
    .with_sigverify(false);
```

## with_blockhash_check

```rust
pub fn with_blockhash_check(self, check: bool) -> Self
```

Bật hoặc tắt xác thực blockhash. Mặc định: `true`.

```rust
// Disable to use any blockhash
let mut svm = LiteSVM::new()
    .with_blockhash_check(false);
```

## with_transaction_history

```rust
pub fn with_transaction_history(self, capacity: usize) -> Self
```

Đặt số lượng giao dịch được lưu trong lịch sử. Mặc định: `32`. Truyền `0`
sẽ tắt lịch sử giao dịch, đồng thời cho phép gửi lại các giao dịch trùng lặp (giống hệt nhau).

```rust
// Keep last 100 transactions
let mut svm = LiteSVM::new()
    .with_transaction_history(100);

// Disable history and allow duplicate transactions
let mut svm = LiteSVM::new()
    .with_transaction_history(0);
```

<Note>
  Trong litesvm 0.18, mọi giá trị từ 32 trở xuống sẽ âm thầm tắt lịch sử, giống như
  `0`: `get_transaction` trả về `None` và các giao dịch trùng lặp được
  chấp nhận. Để giữ lịch sử, hãy dùng giá trị lớn hơn 32, chẳng hạn 100. Các giá trị
  trên 32 sẽ mở rộng bộ đệm, nhưng số lượng giao dịch được giữ lại có thể chênh lệch
  đôi chút so với giá trị bạn truyền vào.
</Note>

## with_log_bytes_limit

```rust
pub fn with_log_bytes_limit(self, limit: Option<usize>) -> Self
```

Đặt số byte tối đa cho nhật ký giao dịch. Mặc định: `Some(10_000)`.

```rust
// Unlimited logs
let mut svm = LiteSVM::new()
    .with_log_bytes_limit(None);

// Custom limit (50KB)
let mut svm = LiteSVM::new()
    .with_log_bytes_limit(Some(50_000));
```

## with_lamports

```rust
pub fn with_lamports(self, lamports: u64) -> Self
```

Đặt số dư ban đầu của tài khoản airdrop (faucet) của LiteSVM, tài khoản này cấp tiền cho các lệnh gọi
`airdrop`. Mặc định: `1_000_000_000_000_000` (1e15 lamports).

```rust
let mut svm = LiteSVM::new()
    .with_lamports(10_000_000_000);
```

## with_default_programs

```rust
pub fn with_default_programs(self) -> Self
```

Bao gồm các chương trình SPL mặc định (Token, Associated Token, v.v.).

```rust
let mut svm = LiteSVM::new()
    .with_default_programs();
```

## with_sysvars

```rust
pub fn with_sysvars(self) -> Self
```

Bao gồm các sysvar mặc định (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory,
v.v.).

```rust
let mut svm = LiteSVM::new()
    .with_sysvars();
```

## with_feature_set

```rust
pub fn with_feature_set(self, feature_set: FeatureSet) -> Self
```

Cấu hình feature set của Solana để kiểm thử các tính năng runtime cụ thể.

```rust
use agave_feature_set::FeatureSet;
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);
```

Hãy đặt feature set trước, trên `LiteSVM::default()`: các builtin, sysvar và
tài khoản tính năng được thêm sau đó sẽ tuân theo nó. Nếu nối chuỗi `with_feature_set` vào
`LiteSVM::new()`, sysvar Rent và các tài khoản tính năng mà `new()` đã thiết lập
cho các tính năng của mainnet sẽ được giữ nguyên.

## with_precompiles

```rust
#[cfg(feature = "precompiles")]
pub fn with_precompiles(self) -> Self
```

Bao gồm các chương trình precompile tiêu chuẩn (ed25519, secp256k1, secp256r1). Chúng
không thuộc `LiteSVM::new()` trừ khi tính năng `precompiles` được bật.

```rust
let mut svm = LiteSVM::new()
    .with_precompiles();
```

<Info>
  Yêu cầu cờ tính năng `precompiles`:

```toml
[dev-dependencies]
litesvm = { version = "0.18", features = ["precompiles"] }
```

</Info>

## with_feature_accounts

```rust
pub fn with_feature_accounts(self) -> Self
```

Bao gồm các tài khoản feature gate trong môi trường kiểm thử. Điều này đảm bảo
hành vi runtime của Solana được kiểm soát bằng feature gate được phản ánh chính xác trong các bài kiểm thử của bạn.

```rust
let mut svm = LiteSVM::new()
    .with_feature_accounts();
```

## Tính năng register-tracing

Tính năng `register-tracing` bật tính năng theo dõi thanh ghi SBF chi tiết trong quá trình
thực thi giao dịch. Nó bao hàm tính năng `invocation-inspect-callback`.

```toml
[dev-dependencies]
litesvm = { version = "0.18", features = ["register-tracing"] }
```

Dùng `LiteSVM::new_debuggable(true)` để tạo một instance với tính năng theo dõi thanh ghi
được bật:

```rust
#[cfg(feature = "register-tracing")]
let mut svm = LiteSVM::new_debuggable(true);
```

Khi được bật, hãy đặt biến môi trường `SBF_TRACE_DISASSEMBLE` để xuất thêm
kết quả disassembly cùng với các dấu vết thanh ghi:

```bash
SBF_TRACE_DISASSEMBLE=1 cargo test
```

## set_invocation_inspect_callback

```rust
pub fn set_invocation_inspect_callback<C: InvocationInspectCallback + 'static>(&mut self, callback: C)
```

Đăng ký một callback được kích hoạt trước và sau mỗi lần gọi chương trình.
Yêu cầu tính năng `invocation-inspect-callback`.

```toml
[dev-dependencies]
litesvm = { version = "0.18", features = ["invocation-inspect-callback"] }
solana-program-runtime = "4"
solana-transaction = "4"
```

```rust
use litesvm::{InvocationInspectCallback, LiteSVM};
use solana_program_runtime::invoke_context::InvokeContext;
use solana_transaction::sanitized::SanitizedTransaction;

struct MyInspector;

impl InvocationInspectCallback for MyInspector {
    fn before_invocation(
        &self,
        _svm: &LiteSVM,
        _tx: &SanitizedTransaction,
        _program_indices: &[u16],
        _invoke_context: &mut InvokeContext,
        _enable_register_tracing: bool,
    ) {
        println!("Before program invocation");
    }

    fn after_invocation(
        &self,
        _svm: &LiteSVM,
        _tx: &SanitizedTransaction,
        _program_indices: &[u16],
        _invoke_context: &InvokeContext,
        _enable_register_tracing: bool,
    ) {
        println!("After program invocation");
    }
}

let mut svm = LiteSVM::new();
svm.set_invocation_inspect_callback(MyInspector);
```
