Alle configuratiemethoden zijn builder-methoden die aan LiteSVM::new() worden gekoppeld.
Begin niet met LiteSVM::default(). Dit maakt een kale instantie aan zonder
sysvars, programma’s of airdrop-account, waardoor airdrop een panic veroorzaakt en transacties
mislukken. LiteSVM::new() geeft een volledig ingerichte instantie terug die je daarna
kunt aanpassen met de onderstaande methoden.
with_compute_budget
pub fn with_compute_budget(self, compute_budget: ComputeBudget) -> Self
Stel de limieten voor compute units en de heapgrootte in.
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
pub fn with_sigverify(self, sigverify: bool) -> Self
Schakel handtekeningverificatie in of uit. Standaard: true.
// Disable for faster tests
let mut svm = LiteSVM::new()
.with_sigverify(false);
with_blockhash_check
pub fn with_blockhash_check(self, check: bool) -> Self
Schakel blockhash-validatie in of uit. Standaard: true.
// Disable to use any blockhash
let mut svm = LiteSVM::new()
.with_blockhash_check(false);
with_transaction_history
pub fn with_transaction_history(self, capacity: usize) -> Self
Stel het aantal transacties in dat in de geschiedenis wordt bewaard. Standaard: 32. Als je 0 opgeeft,
wordt de transactiegeschiedenis uitgeschakeld, waardoor ook dubbele (identieke)
transacties opnieuw verzonden kunnen worden.
// 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);
In litesvm 0.18 schakelt elke waarde van 32 of lager de geschiedenis stilzwijgend uit, net
als 0: get_transaction geeft None terug en dubbele transacties worden
geaccepteerd. Gebruik een waarde groter dan 32, zoals 100, om de geschiedenis te bewaren. Waarden
boven 32 vergroten de buffer, maar het aantal bewaarde transacties kan
iets afwijken van de waarde die je opgeeft.
with_log_bytes_limit
pub fn with_log_bytes_limit(self, limit: Option<usize>) -> Self
Stel het maximale aantal bytes voor transactielogs in. Standaard: Some(10_000).
// 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
pub fn with_lamports(self, lamports: u64) -> Self
Stel het beginsaldo in van het airdrop-account (faucet) van LiteSVM, waarmee
airdrop-aanroepen worden gefinancierd. Standaard: 1_000_000_000_000_000 (1e15 lamports).
let mut svm = LiteSVM::new()
.with_lamports(10_000_000_000);
with_default_programs
pub fn with_default_programs(self) -> Self
Neem de standaard SPL-programma’s op (Token, Associated Token, enz.).
let mut svm = LiteSVM::new()
.with_default_programs();
with_sysvars
pub fn with_sysvars(self) -> Self
Bevat de standaard sysvars (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory,
enz.).
let mut svm = LiteSVM::new()
.with_sysvars();
with_feature_set
pub fn with_feature_set(self, feature_set: FeatureSet) -> Self
Configureer de Solana-featureset om specifieke runtime-features te testen.
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);
Stel de featureset eerst in, op LiteSVM::default(): de builtins, sysvars en
feature-accounts die daarna worden toegevoegd, volgen die featureset. Als je with_feature_set aan
LiteSVM::new() koppelt, blijven de Rent-sysvar en de feature-accounts behouden die new() voor
de mainnet-features heeft ingesteld.
with_precompiles
#[cfg(feature = "precompiles")]
pub fn with_precompiles(self) -> Self
Bevat de standaard precompile-programma’s (ed25519, secp256k1, secp256r1). Ze maken
geen deel uit van LiteSVM::new(), tenzij de precompiles-feature is ingeschakeld.
let mut svm = LiteSVM::new()
.with_precompiles();
Vereist de feature-flag precompiles:[dev-dependencies]
litesvm = { version = "0.18", features = ["precompiles"] }
with_feature_accounts
pub fn with_feature_accounts(self) -> Self
Neem feature-gate-accounts op in de testomgeving. Dit zorgt ervoor dat
het door feature gates bepaalde gedrag van de Solana-runtime nauwkeurig in je tests wordt weergegeven.
let mut svm = LiteSVM::new()
.with_feature_accounts();
register-tracing-functie
De register-tracing-feature schakelt gedetailleerde SBF-registertracering in tijdens de
uitvoering van transacties. Deze impliceert de invocation-inspect-callback-feature.
[dev-dependencies]
litesvm = { version = "0.18", features = ["register-tracing"] }
Gebruik LiteSVM::new_debuggable(true) om een instantie aan te maken waarbij registertracering
is ingeschakeld:
#[cfg(feature = "register-tracing")]
let mut svm = LiteSVM::new_debuggable(true);
Wanneer dit is ingeschakeld, stel je de omgevingsvariabele SBF_TRACE_DISASSEMBLE in om naast de registertraces
ook de disassembly-uitvoer te dumpen:
SBF_TRACE_DISASSEMBLE=1 cargo test
set_invocation_inspect_callback
pub fn set_invocation_inspect_callback<C: InvocationInspectCallback + 'static>(&mut self, callback: C)
Registreer een callback die vóór en na elke programma-aanroep wordt geactiveerd.
Vereist de invocation-inspect-callback-feature.
[dev-dependencies]
litesvm = { version = "0.18", features = ["invocation-inspect-callback"] }
solana-program-runtime = "4"
solana-transaction = "4"
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);