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

# Configuración del entorno

> Métodos del patrón builder para configurar entornos de prueba de LiteSVM

Todos los métodos de configuración son métodos builder encadenados a `LiteSVM::new()`.

<Warning>
  No empieces desde `LiteSVM::default()`. Crea una instancia vacía sin
  sysvars, programas ni cuenta de airdrop, por lo que `airdrop` entra en pánico y las transacciones
  fallan. `LiteSVM::new()` devuelve una instancia completamente configurada que luego puedes
  personalizar con los métodos siguientes.
</Warning>

## with_compute_budget

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

Establece los límites de unidades de cómputo y el tamaño del 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
```

Activa o desactiva la verificación de firmas. Valor predeterminado: `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
```

Activa o desactiva la validación del blockhash. Valor predeterminado: `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
```

Establece el número de transacciones que se conservan en el historial. Valor predeterminado: `32`. Si pasas `0`,
se desactiva el historial de transacciones, lo que también permite reenviar transacciones
duplicadas (idénticas).

```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>
  En litesvm 0.18, cualquier valor de 32 o menos desactiva el historial de forma silenciosa, igual
  que `0`: `get_transaction` devuelve `None` y se aceptan transacciones
  duplicadas. Para conservar el historial, usa un valor mayor que 32, como 100. Los valores
  superiores a 32 amplían el búfer, pero el número de transacciones conservadas puede diferir
  ligeramente del valor que pases.
</Note>

## with_log_bytes_limit

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

Establece el máximo de bytes para los registros de transacciones. Valor predeterminado: `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
```

Establece el saldo inicial de la cuenta de airdrop (faucet) de LiteSVM, que financia
las llamadas a `airdrop`. Valor predeterminado: `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
```

Incluye los programas SPL predeterminados (Token, Associated Token, etc.).

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

## with_sysvars

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

Incluye los sysvars predeterminados (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory,
etc.).

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

## with_feature_set

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

Configura el conjunto de características de Solana para probar funciones específicas 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);
```

Establece primero el conjunto de características, sobre `LiteSVM::default()`: los builtins, sysvars y
cuentas de características que se añaden después se ajustan a él. Si encadenas `with_feature_set` a
`LiteSVM::new()`, se conservan el sysvar Rent y las cuentas de características que `new()` configuró
para las características de la mainnet.

## with_precompiles

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

Incluye los programas precompilados estándar (ed25519, secp256k1, secp256r1). No
forman parte de `LiteSVM::new()` a menos que la característica `precompiles` esté habilitada.

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

<Info>
  Requiere el indicador de característica `precompiles`:

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

</Info>

## with_feature_accounts

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

Incluye las cuentas de feature gate en el entorno de prueba. Esto garantiza que
el comportamiento del runtime de Solana controlado por feature gates se refleje con precisión en tus pruebas.

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

## Característica register-tracing

La característica `register-tracing` habilita el rastreo detallado de registros SBF durante la
ejecución de transacciones. Implica la característica `invocation-inspect-callback`.

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

Usa `LiteSVM::new_debuggable(true)` para crear una instancia con el rastreo de registros
habilitado:

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

Cuando está habilitado, define la variable de entorno `SBF_TRACE_DISASSEMBLE` para volcar también
la salida del desensamblado junto con los rastros de registros:

```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 un callback que se activa antes y después de cada invocación de programa.
Requiere la característica `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);
```
