Configuración del entorno

Todos los métodos de configuración utilizan el patrón builder con LiteSVM::default().

with_compute_budget

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.

use solana_compute_budget::compute_budget::ComputeBudget;
let mut svm = LiteSVM::default()
.with_compute_budget(ComputeBudget {
compute_unit_limit: 1_400_000,
heap_size: 256 * 1024,
..ComputeBudget::default()
});

with_sigverify

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

Habilita o deshabilita la verificación de firmas. Valor predeterminado: true.

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

with_blockhash_check

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

Habilita o deshabilita la validación de blockhash. Valor predeterminado: true.

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

with_transaction_history

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

Establece el número de transacciones a conservar en el historial. Valor predeterminado: 0.

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

with_log_bytes_limit

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

// Unlimited logs
let mut svm = LiteSVM::default()
.with_log_bytes_limit(None);
// Custom limit (50KB)
let mut svm = LiteSVM::default()
.with_log_bytes_limit(Some(50_000));

with_lamports

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

Establece los lamport iniciales para la recolección de tarifas. Predeterminado: 1_000_000_000.

let mut svm = LiteSVM::default()
.with_lamports(10_000_000_000);

with_default_programs

pub fn with_default_programs(self) -> Self

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

let mut svm = LiteSVM::default()
.with_default_programs();

with_sysvars

pub fn with_sysvars(self) -> Self

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

let mut svm = LiteSVM::default()
.with_sysvars();

with_feature_set

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

Configura el conjunto de características de Solana para probar funcionalidades específicas del entorno de ejecución.

use agave_feature_set::FeatureSet;
let mut svm = LiteSVM::default()
.with_feature_set(FeatureSet::all_enabled());

with_precompiles

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

Incluye los programas precompilados estándar (ed25519, secp256k1, secp256r1).

let mut svm = LiteSVM::default()
.with_precompiles();

Requiere el indicador de función precompiles:

[dev-dependencies]
litesvm = { version = "0.11", features = ["precompiles"] }

with_feature_accounts

pub fn with_feature_accounts(self) -> Self

Incluye cuentas de control de características en el entorno de prueba. Esto garantiza que el comportamiento del entorno de ejecución de Solana con control de características se refleje con precisión en tus pruebas.

let mut svm = LiteSVM::default()
.with_feature_accounts();

Función register-tracing

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

[dev-dependencies]
litesvm = { version = "0.11", features = ["register-tracing"] }

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

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

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

SBF_TRACE_DISASSEMBLE=1 cargo test

set_invocation_inspect_callback

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

Registra un callback que se ejecuta antes y después de cada invocación de programa. Requiere la función invocation-inspect-callback.

[dev-dependencies]
litesvm = { version = "0.11", features = ["invocation-inspect-callback"] }
use litesvm::{LiteSVM, types::InvocationInspectCallback};
use solana_svm::invoke_context::InvokeContext;
use solana_svm_transaction::svm_message::SVMMessage;
struct MyInspector;
impl InvocationInspectCallback for MyInspector {
fn before_invocation(
&self,
_svm: &LiteSVM,
_tx: &impl SVMMessage,
_program_indices: &[u16],
_invoke_context: &InvokeContext,
) {
println!("Before program invocation");
}
fn after_invocation(
&self,
_svm: &LiteSVM,
_invoke_context: &InvokeContext,
_enable_register_tracing: bool,
) {
println!("After program invocation");
}
}
let mut svm = LiteSVM::new();
svm.set_invocation_inspect_callback(MyInspector);

Is this page helpful?

Tabla de Contenidos

Editar Página