環境設定

すべての設定メソッドは、LiteSVM::default()を使用したビルダーパターンを採用しています。

with_compute_budget

pub fn with_compute_budget(self, compute_budget: ComputeBudget) -> Self

コンピュートユニットの上限とヒープサイズを設定します。

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

署名検証を有効または無効にします。デフォルト: true

// Disable for faster tests
let mut svm = LiteSVM::default()
.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::default()
.with_blockhash_check(false);

with_transaction_history

pub fn with_transaction_history(self, capacity: usize) -> Self

履歴に保持するトランザクション数を設定します。デフォルト: 0

// Keep last 100 transactions
let mut svm = LiteSVM::default()
.with_transaction_history(100);

with_log_bytes_limit

pub fn with_log_bytes_limit(self, limit: Option<usize>) -> Self

トランザクションログの最大バイト数を設定します。デフォルト: Some(10_000)

// Unlimited logs
let 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

手数料徴収の初期 lamport を設定します。デフォルト: 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

デフォルトの SPL プログラム(Token、Associated Token など)を含めます。

let mut svm = LiteSVM::default()
.with_default_programs();

with_sysvars

pub fn with_sysvars(self) -> Self

デフォルトの sysvar(Clock、Rent、EpochSchedule、SlotHashes、StakeHistory など)を含めます。

let mut svm = LiteSVM::default()
.with_sysvars();

with_feature_set

pub fn with_feature_set(self, feature_set: FeatureSet) -> Self

特定のランタイム機能をテストするための Solana フィーチャーセットを設定します。

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

標準のプリコンパイルプログラム(ed25519、secp256k1、secp256r1)を含めます。

let mut svm = LiteSVM::default()
.with_precompiles();

precompiles フィーチャーフラグが必要です:

[dev-dependencies]
litesvm = { version = "0.11", features = ["precompiles"] }

with_feature_accounts

pub fn with_feature_accounts(self) -> Self

テスト環境にフィーチャーゲートアカウントを含めます。これにより、フィーチャーゲートされた Solana ランタイムの動作がテストに正確に反映されます。

let mut svm = LiteSVM::default()
.with_feature_accounts();

register-tracing 機能

register-tracing 機能は、トランザクション実行中に詳細な SBF レジスタートレースを有効にします。これは invocation-inspect-callback 機能を暗黙的に有効にします。

[dev-dependencies]
litesvm = { version = "0.11", 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.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?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。