Tutti i metodi di configurazione utilizzano il pattern builder con
LiteSVM::default().
with_compute_budget
pub fn with_compute_budget(self, compute_budget: ComputeBudget) -> Self
Imposta i limiti delle unità di calcolo e la dimensione dell'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
Abilita o disabilita la verifica della firma. Predefinito: true.
// Disable for faster testslet mut svm = LiteSVM::default().with_sigverify(false);
with_blockhash_check
pub fn with_blockhash_check(self, check: bool) -> Self
Abilita o disabilita la validazione del blockhash. Predefinito: true.
// Disable to use any blockhashlet mut svm = LiteSVM::default().with_blockhash_check(false);
with_transaction_history
pub fn with_transaction_history(self, capacity: usize) -> Self
Imposta il numero di transazioni da mantenere nella cronologia. Predefinito:
0.
// Keep last 100 transactionslet mut svm = LiteSVM::default().with_transaction_history(100);
with_log_bytes_limit
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).
// Unlimited logslet 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
Imposta i lamport iniziali per la raccolta delle commissioni. Predefinito:
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
Includi i programmi SPL predefiniti (Token, Associated Token, ecc.).
let mut svm = LiteSVM::default().with_default_programs();
with_sysvars
pub fn with_sysvars(self) -> Self
Include le sysvar predefinite (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory, ecc.).
let mut svm = LiteSVM::default().with_sysvars();
with_feature_set
pub fn with_feature_set(self, feature_set: FeatureSet) -> Self
Configura il feature set di Solana per testare funzionalità specifiche del 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
Include i programmi precompilati standard (ed25519, secp256k1, secp256r1).
let mut svm = LiteSVM::default().with_precompiles();
Richiede il flag di funzionalità precompiles:
[dev-dependencies]litesvm = { version = "0.11", features = ["precompiles"] }
with_feature_accounts
pub fn with_feature_accounts(self) -> Self
Includi gli account feature gate nell'ambiente di test. Questo garantisce che il comportamento del runtime di Solana soggetto a feature gate sia accuratamente riflesso nei tuoi test.
let mut svm = LiteSVM::default().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.
[dev-dependencies]litesvm = { version = "0.11", features = ["register-tracing"] }
Utilizzare LiteSVM::new_debuggable(true) per creare un'istanza con il
tracciamento dei registri abilitato:
#[cfg(feature = "register-tracing")]let mut svm = LiteSVM::new_debuggable(true);
Quando abilitato, impostare la variabile d'ambiente SBF_TRACE_DISASSEMBLE per
visualizzare anche l'output del disassemblaggio insieme alle tracce dei
registri:
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 che viene eseguito prima e dopo ogni invocazione del
programma. Richiede la funzionalità 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?