Tüm yapılandırma yöntemleri, LiteSVM::new() üzerinde zincirleme çağrılan builder yöntemleridir.
LiteSVM::default() ile başlamayın. Bu yöntem; sysvar, program veya airdrop
hesabı içermeyen boş bir örnek oluşturur, bu yüzden airdrop panic verir ve
işlemler başarısız olur. LiteSVM::new() ise tamamen kurulmuş bir örnek
döndürür; bunu aşağıdaki yöntemlerle özelleştirebilirsiniz.
with_compute_budget
pub fn with_compute_budget(self, compute_budget: ComputeBudget) -> Self
Hesaplama birimi limitlerini ve heap boyutunu ayarlayın.
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
İmza doğrulamasını etkinleştirin veya devre dışı bırakın. Varsayılan: 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
Blockhash doğrulamasını etkinleştirin veya devre dışı bırakın. Varsayılan: 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
Geçmişte tutulacak işlem sayısını ayarlayın. Varsayılan: 32. 0 verildiğinde
işlem geçmişi devre dışı kalır; bu durum aynı (özdeş) işlemlerin yeniden
gönderilmesine de olanak tanır.
// 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);
litesvm 0.18’de 32 veya daha küçük herhangi bir değer, 0 gibi geçmişi sessizce
devre dışı bırakır: get_transaction None döndürür ve yinelenen işlemler
kabul edilir. Geçmişi korumak için 100 gibi 32’den büyük bir değer kullanın.
32’nin üzerindeki değerler tamponu büyütür, ancak tutulan işlem sayısı verdiğiniz
değerden biraz farklı olabilir.
with_log_bytes_limit
pub fn with_log_bytes_limit(self, limit: Option<usize>) -> Self
İşlem logları için maksimum bayt sayısını ayarlayın. Varsayılan: 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
airdrop çağrılarını finanse eden LiteSVM airdrop (faucet) hesabının başlangıç
bakiyesini ayarlayın. Varsayılan: 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
Varsayılan SPL programlarını (Token, Associated Token vb.) dahil edin.
let mut svm = LiteSVM::new()
.with_default_programs();
with_sysvars
pub fn with_sysvars(self) -> Self
Varsayılan sysvar’ları (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory
vb.) dahil eder.
let mut svm = LiteSVM::new()
.with_sysvars();
with_feature_set
pub fn with_feature_set(self, feature_set: FeatureSet) -> Self
Belirli çalışma zamanı özelliklerini test etmek için Solana özellik kümesini yapılandırın.
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);
Özellik kümesini önce LiteSVM::default() üzerinde ayarlayın: bundan sonra
eklenen builtin’ler, sysvar’lar ve özellik hesapları bu kümeyi izler.
with_feature_set yöntemini LiteSVM::new() üzerine zincirlemek, new()
tarafından mainnet özellikleri için kurulan Rent sysvar’ını ve özellik
hesaplarını korur.
with_precompiles
#[cfg(feature = "precompiles")]
pub fn with_precompiles(self) -> Self
Standart precompile programlarını (ed25519, secp256k1, secp256r1) dahil eder.
precompiles özelliği etkinleştirilmedikçe LiteSVM::new() kapsamında
bulunmazlar.
let mut svm = LiteSVM::new()
.with_precompiles();
precompiles özellik bayrağı gerekir:[dev-dependencies]
litesvm = { version = "0.18", features = ["precompiles"] }
with_feature_accounts
pub fn with_feature_accounts(self) -> Self
Özellik geçidi (feature gate) hesaplarını test ortamına dahil edin. Bu, özellik
bayrağına bağlı Solana çalışma zamanı davranışının testlerinize doğru şekilde
yansımasını sağlar.
let mut svm = LiteSVM::new()
.with_feature_accounts();
register-tracing özelliği
register-tracing özelliği, işlem yürütme sırasında ayrıntılı SBF register
izlemeyi etkinleştirir. invocation-inspect-callback özelliğini de kapsar.
[dev-dependencies]
litesvm = { version = "0.18", features = ["register-tracing"] }
Register izlemenin etkin olduğu bir örnek oluşturmak için
LiteSVM::new_debuggable(true) kullanın:
#[cfg(feature = "register-tracing")]
let mut svm = LiteSVM::new_debuggable(true);
Etkinleştirildiğinde, register izlerinin yanı sıra disassembly çıktısını da
almak için SBF_TRACE_DISASSEMBLE ortam değişkenini ayarlayın:
SBF_TRACE_DISASSEMBLE=1 cargo test
set_invocation_inspect_callback
pub fn set_invocation_inspect_callback<C: InvocationInspectCallback + 'static>(&mut self, callback: C)
Her program çağrısından önce ve sonra tetiklenen bir callback kaydedin.
invocation-inspect-callback özelliği gerekir.
[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);