모든 구성 메서드는 LiteSVM::new()에 체이닝하는 빌더 메서드입니다.
LiteSVM::default()로 시작하지 마세요. sysvar, 프로그램, 에어드롭 계정이 없는
빈 인스턴스가 생성되므로 airdrop이 패닉을 일으키고 트랜잭션이 실패합니다.
LiteSVM::new()는 완전히 설정된 인스턴스를 반환하며, 아래 메서드로
이를 원하는 대로 사용자 지정할 수 있습니다.
with_compute_budget
pub fn with_compute_budget(self, compute_budget: ComputeBudget) -> Self
컴퓨트 유닛 한도와 힙 크기를 설정합니다.
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
서명 검증을 활성화하거나 비활성화합니다. 기본값: 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
블록해시 검증을 활성화하거나 비활성화합니다. 기본값: 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
기록에 보관할 트랜잭션 수를 설정합니다. 기본값: 32. 0을 전달하면
트랜잭션 기록이 비활성화되며, 중복된(동일한) 트랜잭션도 다시 전송할 수 있게
됩니다.
// 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에서는 32 이하의 값이 0과 마찬가지로 기록을 별도 알림 없이
비활성화합니다. get_transaction은 None을 반환하고 중복 트랜잭션이
허용됩니다. 기록을 유지하려면 100처럼 32보다 큰 값을 사용하세요. 32를 넘는
값은 버퍼를 늘리지만, 실제로 보관되는 트랜잭션 수는 전달한 값과 약간 다를
수 있습니다.
with_log_bytes_limit
pub fn with_log_bytes_limit(self, limit: Option<usize>) -> Self
트랜잭션 로그의 최대 바이트 수를 설정합니다. 기본값: 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 호출의 자금원이 되는 LiteSVM의 에어드롭(파우셋) 계정의 초기 잔액을
설정합니다. 기본값: 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
기본 SPL 프로그램(Token, Associated Token 등)을 포함합니다.
let mut svm = LiteSVM::new()
.with_default_programs();
with_sysvars
pub fn with_sysvars(self) -> Self
기본 sysvar(Clock, Rent, EpochSchedule, SlotHashes, StakeHistory 등)를
포함합니다.
let mut svm = LiteSVM::new()
.with_sysvars();
with_feature_set
pub fn with_feature_set(self, feature_set: FeatureSet) -> Self
특정 런타임 기능을 테스트하기 위해 Solana 기능 세트(feature set)를 구성합니다.
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);
기능 세트는 LiteSVM::default()에서 가장 먼저 설정하세요. 그 이후에 추가되는
빌트인, sysvar, 기능 계정이 이를 따릅니다. LiteSVM::new()에
with_feature_set을 체이닝하면 new()가 메인넷 기능에 맞춰 설정한 Rent
sysvar와 기능 계정이 그대로 유지됩니다.
with_precompiles
#[cfg(feature = "precompiles")]
pub fn with_precompiles(self) -> Self
표준 프리컴파일 프로그램(ed25519, secp256k1, secp256r1)을 포함합니다.
precompiles 기능이 활성화되지 않으면 LiteSVM::new()에는 포함되지
않습니다.
let mut svm = LiteSVM::new()
.with_precompiles();
precompiles 기능 플래그가 필요합니다:[dev-dependencies]
litesvm = { version = "0.18", features = ["precompiles"] }
with_feature_accounts
pub fn with_feature_accounts(self) -> Self
테스트 환경에 기능 게이트 계정을 포함합니다. 이를 통해 기능 게이트가 적용된
Solana 런타임 동작이 테스트에 정확하게 반영됩니다.
let mut svm = LiteSVM::new()
.with_feature_accounts();
register-tracing 기능
register-tracing 기능은 트랜잭션 실행 중 상세한 SBF 레지스터 추적을
활성화합니다. 이 기능은 invocation-inspect-callback 기능을 포함합니다.
[dev-dependencies]
litesvm = { version = "0.18", features = ["register-tracing"] }
LiteSVM::new_debuggable(true)를 사용하면 레지스터 추적이 활성화된
인스턴스를 생성할 수 있습니다:
#[cfg(feature = "register-tracing")]
let mut svm = LiteSVM::new_debuggable(true);
활성화한 경우 SBF_TRACE_DISASSEMBLE 환경 변수를 설정하면 레지스터 추적과
함께 디스어셈블리 출력도 덤프합니다:
SBF_TRACE_DISASSEMBLE=1 cargo test
set_invocation_inspect_callback
pub fn set_invocation_inspect_callback<C: InvocationInspectCallback + 'static>(&mut self, callback: C)
각 프로그램 호출 전후에 실행되는 콜백을 등록합니다.
invocation-inspect-callback 기능이 필요합니다.
[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);