Configuração de Ambiente

Todos os métodos de configuração utilizam o padrão builder com LiteSVM::default().

with_compute_budget

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

Defina limites de unidades de computação e tamanho do 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

Ative ou desative a verificação de assinatura. Padrão: 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

Ative ou desative a validação de blockhash. Padrão: 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

Defina o número de transações a manter no histórico. Padrão: 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

Defina o máximo de bytes para logs de transações. Padrão: 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

Definir os lamports iniciais para cobrança de taxas. Padrão: 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

Inclui os programas SPL padrão (Token, Associated Token, etc.).

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

with_sysvars

pub fn with_sysvars(self) -> Self

Inclui as sysvars padrão (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

Configure o conjunto de funcionalidades do Solana para testar recursos específicos do runtime.

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

Inclui os programas de pré-compilação padrão (ed25519, secp256k1, secp256r1).

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

Requer a flag de funcionalidade precompiles:

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

with_feature_accounts

pub fn with_feature_accounts(self) -> Self

Inclui contas de feature gate no ambiente de teste. Isso garante que o comportamento do runtime do Solana controlado por funcionalidades seja refletido com precisão nos seus testes.

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

Funcionalidade register-tracing

A funcionalidade register-tracing habilita o rastreamento detalhado de registros SBF durante a execução de transações. Ela implica a funcionalidade invocation-inspect-callback.

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

Use LiteSVM::new_debuggable(true) para criar uma instância com o rastreamento de registros habilitado:

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

Quando habilitado, defina a variável de ambiente SBF_TRACE_DISASSEMBLE para também exibir a saída de desmontagem junto com os rastreamentos 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)

Registre um callback que é acionado antes e depois de cada invocação de programa. Requer a funcionalidade 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?

Índice

Editar Página
© 2026 Fundação Solana. Todos os direitos reservados.