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

# 環境設定

> LiteSVM テスト環境を設定するためのビルダーパターンのメソッド

すべての設定メソッドは、`LiteSVM::new()` にチェーンして使用するビルダーメソッドです。

<Warning>
  `LiteSVM::default()` から始めないでください。sysvar、プログラム、エアドロップアカウントがない最小限のインスタンスが作成されるため、`airdrop` はパニックし、トランザクションは失敗します。`LiteSVM::new()` は完全にセットアップされたインスタンスを返すので、以下のメソッドでカスタマイズできます。
</Warning>

## with_compute_budget

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

コンピュートユニットの上限とヒープサイズを設定します。

```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
```

署名検証を有効または無効にします。デフォルト: `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
```

ブロックハッシュの検証を有効または無効にします。デフォルト: `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
```

履歴に保持するトランザクション数を設定します。デフォルト: `32`。`0` を渡すとトランザクション履歴が無効になり、重複（同一）トランザクションの再送信も可能になります。

```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>
  litesvm 0.18 では、32 以下の値を指定すると `0` と同様に履歴が暗黙的に無効になり、`get_transaction` は `None` を返し、重複トランザクションも受け入れられます。履歴を保持するには、100 など 32 より大きい値を使用してください。32 を超える値ではバッファが拡張されますが、実際に保持されるトランザクション数は、指定した値とわずかに異なる場合があります。
</Note>

## with_log_bytes_limit

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

トランザクションログの最大バイト数を設定します。デフォルト: `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
```

`airdrop` の呼び出しの資金源となる、LiteSVM のエアドロップ（ファセット）アカウントの初期残高を設定します。デフォルト: `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
```

デフォルトの SPL プログラム（Token、Associated Token など）を含めます。

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

## with_sysvars

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

デフォルトの sysvar（Clock、Rent、EpochSchedule、SlotHashes、StakeHistory など）を含めます。

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

## with_feature_set

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

特定のランタイム機能をテストするために、Solana のフィーチャーセットを設定します。

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

フィーチャーセットは、最初に `LiteSVM::default()` に対して設定してください。その後に追加されるビルトイン、sysvar、フィーチャーアカウントは、設定したフィーチャーセットに従います。`LiteSVM::new()` に `with_feature_set` をチェーンした場合は、`new()` がメインネットのフィーチャー向けにセットアップした Rent sysvar とフィーチャーアカウントがそのまま保持されます。

## with_precompiles

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

標準のプリコンパイルプログラム（ed25519、secp256k1、secp256r1）を含めます。`precompiles` フィーチャーが有効でない限り、これらは `LiteSVM::new()` には含まれません。

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

<Info>
  `precompiles` フィーチャーフラグが必要です:

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

</Info>

## with_feature_accounts

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

フィーチャーゲートアカウントをテスト環境に含めます。これにより、フィーチャーゲートされた Solana ランタイムの動作がテストに正確に反映されます。

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

## register-tracing 機能

`register-tracing` フィーチャーを有効にすると、トランザクション実行中の詳細な SBF レジスタトレースが可能になります。このフィーチャーには `invocation-inspect-callback` フィーチャーも含まれます。

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

レジスタトレースを有効にしたインスタンスを作成するには、`LiteSVM::new_debuggable(true)` を使用します:

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

有効にした場合、環境変数 `SBF_TRACE_DISASSEMBLE` を設定すると、レジスタトレースと併せて逆アセンブル出力もダンプされます:

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

各プログラム呼び出しの前後に実行されるコールバックを登録します。`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);
```
