Tất cả các phương thức cấu hình đều sử dụng builder pattern với
LiteSVM::default().
with_compute_budget
pub fn with_compute_budget(self, compute_budget: ComputeBudget) -> Self
Đặt giới hạn đơn vị tính toán và kích thước 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
Bật hoặc tắt xác minh chữ ký. Mặc định: true.
// Disable for faster testslet mut svm = LiteSVM::default().with_sigverify(false);
with_blockhash_check
pub fn with_blockhash_check(self, check: bool) -> Self
Bật hoặc tắt xác thực blockhash. Mặc định: 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
Đặt số lượng giao dịch cần lưu trong lịch sử. Mặc định: 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
Đặt số byte tối đa cho nhật ký giao dịch. Mặc định: 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
Đặt lamport ban đầu để thu phí. Mặc định: 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
Bao gồm các chương trình SPL mặc định (Token, Associated Token, v.v.).
let mut svm = LiteSVM::default().with_default_programs();
with_sysvars
pub fn with_sysvars(self) -> Self
Bao gồm các sysvar mặc định (Clock, Rent, EpochSchedule, SlotHashes, StakeHistory, v.v.).
let mut svm = LiteSVM::default().with_sysvars();
with_feature_set
pub fn with_feature_set(self, feature_set: FeatureSet) -> Self
Cấu hình feature set của Solana để kiểm tra các tính năng runtime cụ thể.
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
Bao gồm các chương trình precompile chuẩn (ed25519, secp256k1, secp256r1).
let mut svm = LiteSVM::default().with_precompiles();
Yêu cầu feature flag precompiles:
[dev-dependencies]litesvm = { version = "0.11", features = ["precompiles"] }
with_feature_accounts
pub fn with_feature_accounts(self) -> Self
Bao gồm các tài khoản feature gate trong môi trường kiểm thử. Điều này đảm bảo hành vi runtime của Solana được kiểm soát bởi feature gate được phản ánh chính xác trong các bài kiểm thử của bạn.
let mut svm = LiteSVM::default().with_feature_accounts();
Tính năng register-tracing
Tính năng register-tracing cho phép theo dõi chi tiết các thanh ghi SBF trong
quá trình thực thi giao dịch. Tính năng này bao gồm tính năng
invocation-inspect-callback.
[dev-dependencies]litesvm = { version = "0.11", features = ["register-tracing"] }
Sử dụng LiteSVM::new_debuggable(true) để tạo một instance với tính năng theo
dõi thanh ghi được bật:
#[cfg(feature = "register-tracing")]let mut svm = LiteSVM::new_debuggable(true);
Khi được bật, hãy đặt biến môi trường SBF_TRACE_DISASSEMBLE để cũng xuất đầu
ra disassembly cùng với các trace thanh ghi:
SBF_TRACE_DISASSEMBLE=1 cargo test
set_invocation_inspect_callback
pub fn set_invocation_inspect_callback<C: InvocationInspectCallback + 'static>(&mut self, callback: C)
Đăng ký một callback được kích hoạt trước và sau mỗi lần gọi chương trình. Yêu
cầu tính năng 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?