Umgebungskonfiguration

Alle Konfigurationsmethoden verwenden das Builder-Pattern mit LiteSVM::default().

with_compute_budget

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

Compute-Unit-Limits und Heap-Größe festlegen.

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

Signaturverifizierung aktivieren oder deaktivieren. Standard: 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

Blockhash-Validierung aktivieren oder deaktivieren. Standard: 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

Anzahl der in der Historie zu speichernden Transaktionen festlegen. Standard: 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

Maximale Bytes für Transaktionsprotokolle festlegen. Standard: 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

Legt die anfänglichen lamport für die Gebührenerhebung fest. Standard: 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

Schließt Standard-SPL-Programme ein (Token, Associated Token, usw.).

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

with_sysvars

pub fn with_sysvars(self) -> Self

Enthält Standard-Sysvars (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory, usw.).

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

with_feature_set

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

Konfiguriert das Solana-Feature-Set zum Testen spezifischer Laufzeit-Features.

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

Enthält Standard-Precompile-Programme (ed25519, secp256k1, secp256r1).

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

Erfordert das precompiles Feature-Flag:

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

with_feature_accounts

pub fn with_feature_accounts(self) -> Self

Schließt Feature-Gate-Konten in die Testumgebung ein. Dies stellt sicher, dass das durch Feature-Gates gesteuerte Laufzeitverhalten von Solana in Ihren Tests korrekt abgebildet wird.

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

register-tracing-Feature

Das register-tracing-Feature ermöglicht detailliertes SBF-Register-Tracing während der Transaktionsausführung. Es impliziert das invocation-inspect-callback-Feature.

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

Verwende LiteSVM::new_debuggable(true), um eine Instanz mit aktiviertem Register-Tracing zu erstellen:

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

Wenn aktiviert, setze die Umgebungsvariable SBF_TRACE_DISASSEMBLE, um auch Disassemblierungsausgaben zusammen mit den Register-Traces auszugeben:

SBF_TRACE_DISASSEMBLE=1 cargo test

set_invocation_inspect_callback

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

Registriere einen Callback, der vor und nach jeder Programmaufrufung ausgelöst wird. Erfordert das invocation-inspect-callback-Feature.

[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?

Inhaltsverzeichnis

Seite bearbeiten
© 2026 Solana Foundation. Alle Rechte vorbehalten.