LiteSVM gebruikt een builderpatroon voor configuratie. Alle methoden retourneren LiteSVM
zodat ze aaneengeschakeld kunnen worden.
Typische testopzet
import { createClient, generateKeyPairSigner } from "@solana/kit";
import { litesvm } from "@solana/kit-plugin-litesvm";
import { signer } from "@solana/kit-plugin-signer";
const mySigner = await generateKeyPairSigner();
const client = createClient().use(signer(mySigner)).use(litesvm());
client.svm
.withSigverify(false) // Skip signature verification (faster)
.withBlockhashCheck(false) // Skip blockhash validation (simpler)
.withTransactionHistory(100n); // Store last 100 transactions
Een litesvm()-client heeft de sysvars, de ingebouwde programma’s, de
precompiles en de standaardprogramma’s al geladen, dus een typische opzet wijzigt alleen
de controles die nodig zijn.
Handtekening & blockhash
withSigverify
withSigverify(sigverify: boolean): LiteSVM
Schakel handtekeningverificatie in of uit.
// Disable for faster tests (default is enabled)
client.svm.withSigverify(false);
// Enable for production-like testing
client.svm.withSigverify(true);
Het uitschakelen van handtekeningverificatie maakt tests sneller, maar minder realistisch.
withBlockhashCheck
withBlockhashCheck(check: boolean): LiteSVM
Schakel de controle op het verlopen van blockhashes in of uit.
// Disable for simpler tests
client.svm.withBlockhashCheck(false);
Programma’s & sysvars
Deze methoden laden programma’s en sysvars in de VM. Een litesvm()-client
heeft ze al allemaal, dus je hebt ze alleen nodig om een client te resetten of om
een kale LiteSVM.default()-instantie uit het litesvm-pakket op te zetten.
withSysvars
Zet Clock, Rent, EpochSchedule en de andere sysvars terug naar hun standaardwaarden.
Sysvars zijn al beschikbaar op een nieuwe client, dus je hebt dit alleen nodig om
wijzigingen ongedaan te maken. Als je dit aanroept na setClock of warpToSlot, gaat je clock verloren.
client.svm.setClock(myClock);
client.svm.withSysvars(); // the clock is back to its default
withBuiltins
Voeg de ingebouwde programma’s van de runtime toe: het System Program, de BPF-loaders, Vote
en Compute Budget.
client.svm.withBuiltins();
withPrecompiles
withPrecompiles(): LiteSVM
Voeg de precompiles voor handtekeningverificatie toe: ed25519, secp256k1 en secp256r1.
client.svm.withPrecompiles();
withDefaultPrograms
withDefaultPrograms(): LiteSVM
Voeg de standaardprogramma’s toe: Token, Token-2022, Associated Token Account, Memo,
Stake en Address Lookup Table.
client.svm.withDefaultPrograms();
Resourcelimieten
withLamports
withLamports(lamports: bigint): LiteSVM
Stel het saldo in van het interne faucetaccount waaruit airdrop() put.
Airdrops die groter zijn dan dit saldo mislukken.
client.svm.withLamports(1_000_000_000n); // the faucet holds 1 SOL
withLogBytesLimit
withLogBytesLimit(limit?: bigint): LiteSVM
Stel de bytelimiet voor logoutput in.
client.svm.withLogBytesLimit(10000n);
withTransactionHistory
withTransactionHistory(capacity: bigint): LiteSVM
Schakel het opslaan van transactiegeschiedenis in.
// Store last 100 transactions
client.svm.withTransactionHistory(100n);
Featuresets
withFeatureSet
withFeatureSet(featureSet: FeatureSet): LiteSVM
Configureer de featureset om specifieke Solana-versies te testen.