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

# Configurazione dell'ambiente

> Metodi del pattern builder per configurare gli ambienti di test LiteSVM

Tutti i metodi di configurazione sono metodi builder concatenati a `LiteSVM::new()`.

<Warning>
  Non partire da `LiteSVM::default()`. Crea un'istanza vuota, senza
  sysvar, programmi o account per l'airdrop, quindi `airdrop` va in panic e le transazioni
  falliscono. `LiteSVM::new()` restituisce un'istanza completamente configurata che puoi poi
  personalizzare con i metodi riportati di seguito.
</Warning>

## with_compute_budget

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

Imposta i limiti delle compute unit e la dimensione dell'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
```

Abilita o disabilita la verifica delle firme. Predefinito: `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
```

Abilita o disabilita la validazione del blockhash. Predefinito: `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
```

Imposta il numero di transazioni da conservare nella cronologia. Predefinito: `32`. Passando `0`
la cronologia delle transazioni viene disabilitata, il che consente anche di inviare nuovamente
transazioni duplicate (identiche).

```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>
  In litesvm 0.18, qualsiasi valore pari o inferiore a 32 disabilita silenziosamente la cronologia, come
  `0`: `get_transaction` restituisce `None` e le transazioni duplicate vengono
  accettate. Per mantenere la cronologia, usa un valore maggiore di 32, ad esempio 100. I valori
  superiori a 32 ampliano il buffer, ma il numero di transazioni conservate può differire
  leggermente dal valore passato.
</Note>

## with_log_bytes_limit

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

Imposta il numero massimo di byte per i log delle transazioni. Predefinito: `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
```

Imposta il saldo iniziale dell'account di airdrop (faucet) di LiteSVM, che finanzia
le chiamate a `airdrop`. Predefinito: `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
```

Include i programmi SPL predefiniti (Token, Associated Token, ecc.).

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

## with_sysvars

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

Include i sysvar predefiniti (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory,
ecc.).

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

## with_feature_set

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

Configura il feature set di Solana per testare specifiche funzionalità del runtime.

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

Imposta prima il feature set, su `LiteSVM::default()`: i builtin, i sysvar e gli account
delle feature aggiunti dopo di esso lo seguono. Concatenare `with_feature_set` a
`LiteSVM::new()` mantiene il sysvar Rent e gli account delle feature che `new()` ha configurato
per le feature della mainnet.

## with_precompiles

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

Include i programmi precompilati standard (ed25519, secp256k1, secp256r1). Non
fanno parte di `LiteSVM::new()` a meno che la feature `precompiles` non sia abilitata.

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

<Info>
  Richiede il feature flag `precompiles`:

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

</Info>

## with_feature_accounts

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

Include gli account dei feature gate nell'ambiente di test. Questo garantisce che
il comportamento del runtime Solana soggetto a feature gate sia rispecchiato fedelmente nei tuoi test.

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

## Funzionalità register-tracing

La funzionalità `register-tracing` abilita il tracciamento dettagliato dei registri SBF durante
l'esecuzione delle transazioni. Implica la funzionalità `invocation-inspect-callback`.

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

Usa `LiteSVM::new_debuggable(true)` per creare un'istanza con il tracciamento dei registri
abilitato:

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

Quando è abilitato, imposta la variabile d'ambiente `SBF_TRACE_DISASSEMBLE` per ottenere anche
l'output del disassemblato insieme alle tracce dei registri:

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

Registra una callback che viene eseguita prima e dopo ogni invocazione di programma.
Richiede la funzionalità `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);
```
