pub struct HPSVM { /* private fields */ }Implementations§
Source§impl HPSVM
impl HPSVM
Sourcepub fn builder() -> HpsvmBuilder
pub fn builder() -> HpsvmBuilder
Create a typed builder for explicit, compile-time-checked environment assembly.
Sourcepub fn with_inspector<I: Inspector + 'static>(self, inspector: I) -> Self
pub fn with_inspector<I: Inspector + 'static>(self, inspector: I) -> Self
Installs an execution inspector that observes top-level transaction activity.
Sourcepub fn new_debuggable(enable_register_tracing: bool) -> Self
Available on crate feature register-tracing only.
pub fn new_debuggable(enable_register_tracing: bool) -> Self
register-tracing only.Create a test environment with debugging features.
This constructor allows enabling low-level VM debugging capabilities, such as register tracing, which are baked into program executables at load time and cannot be changed afterwards.
When enable_register_tracing is true:
- Programs are loaded with register tracing support
- A default
DefaultRegisterTracingCallbackis installed - Trace data is written to
SBF_TRACE_DIR(ortarget/sbf/traceby default)
Sourcepub const fn set_compute_budget(&mut self, compute_budget: ComputeBudget)
pub const fn set_compute_budget(&mut self, compute_budget: ComputeBudget)
Advanced reconfiguration. Replaces the runtime compute budget and invalidates any previously transacted but uncommitted outcomes.
Sourcepub const fn set_sigverify(&mut self, sigverify: bool)
pub const fn set_sigverify(&mut self, sigverify: bool)
Advanced reconfiguration. Enables or disables signature verification for future transactions and invalidates any previously transacted but uncommitted outcomes.
Sourcepub const fn set_blockhash_check(&mut self, check: bool)
pub const fn set_blockhash_check(&mut self, check: bool)
Advanced reconfiguration. Enables or disables blockhash checking for future transactions and invalidates any previously transacted but uncommitted outcomes.
pub fn set_sysvars(&mut self)
Sourcepub fn set_feature_set(
&mut self,
feature_set: FeatureSet,
) -> Result<(), HPSVMError>
pub fn set_feature_set( &mut self, feature_set: FeatureSet, ) -> Result<(), HPSVMError>
Advanced reconfiguration. Replaces the active feature set, rebuilds any materialized feature-dependent state, and invalidates previously transacted but uncommitted outcomes.
pub fn set_feature_accounts(&mut self)
pub fn set_builtins(&mut self)
pub fn set_lamports(&mut self, lamports: u64)
pub fn set_default_programs(&mut self)
pub fn set_spl_programs(&mut self)
Sourcepub fn set_transaction_history(&mut self, capacity: usize)
pub fn set_transaction_history(&mut self, capacity: usize)
Advanced reconfiguration. Changes the transaction history capacity. Set this to 0 to disable history and allow duplicate transactions.
Sourcepub fn set_account_source(&mut self, source: impl AccountSource + 'static)
pub fn set_account_source(&mut self, source: impl AccountSource + 'static)
Advanced reconfiguration. Installs a read-through account source for future lookups and invalidates previously transacted but uncommitted outcomes.
Sourcepub const fn set_log_bytes_limit(&mut self, limit: Option<usize>)
pub const fn set_log_bytes_limit(&mut self, limit: Option<usize>)
Advanced reconfiguration. Adjusts the log truncation limit for future execution and invalidates previously transacted but uncommitted outcomes.
pub fn set_precompiles(&mut self)
Sourcepub fn minimum_balance_for_rent_exemption(&self, data_len: usize) -> u64
pub fn minimum_balance_for_rent_exemption(&self, data_len: usize) -> u64
Returns minimum balance required to make an account with specified data length rent exempt.
Sourcepub fn get_account(&self, address: &Address) -> Option<Account>
pub fn get_account(&self, address: &Address) -> Option<Account>
Returns all information associated with the account of the provided pubkey.
Sourcepub fn try_get_account(
&self,
address: &Address,
) -> Result<Option<Account>, AccountSourceError>
pub fn try_get_account( &self, address: &Address, ) -> Result<Option<Account>, AccountSourceError>
Returns account data while preserving failures from a configured external source.
Sourcepub fn set_account(
&mut self,
address: Address,
data: Account,
) -> Result<(), HPSVMError>
pub fn set_account( &mut self, address: Address, data: Account, ) -> Result<(), HPSVMError>
⚠️ ADVANCED USE ONLY ⚠️
Sets all information associated with the account of the provided pubkey.
This writes directly into the in-memory test state. It does not execute
the owning program or replay the full transaction pipeline, so it is best
used for fixtures, snapshots, and explicit state surgery between
transactions. Prefer airdrop or
send_transaction when you want a
protocol-consistent state transition.
Sourcepub const fn accounts(&self) -> AccountsView<'_>
pub const fn accounts(&self) -> AccountsView<'_>
⚠️ ADVANCED USE ONLY ⚠️
Returns a read-only view of the internal accounts database.
This provides read-only access to the accounts database for advanced inspection.
Use get_account for normal account retrieval.
§Examples
use hpsvm::HPSVM;
let svm = HPSVM::new();
// Read-only access to accounts data
let accounts = svm.accounts();
// ... inspect internal state if neededSourcepub fn get_balance(&self, address: &Address) -> Option<u64>
pub fn get_balance(&self, address: &Address) -> Option<u64>
Gets the balance of the provided account pubkey.
Sourcepub const fn latest_blockhash(&self) -> Hash
pub const fn latest_blockhash(&self) -> Hash
Gets the latest blockhash.
Sourcepub fn set_sysvar<T>(&mut self, sysvar: &T) -> Result<(), HPSVMError>
pub fn set_sysvar<T>(&mut self, sysvar: &T) -> Result<(), HPSVMError>
⚠️ ADVANCED USE ONLY ⚠️
Sets the sysvar in the test environment.
This is a direct override intended for tests that need to manipulate runtime context. It bypasses transaction execution.
Returns an error if serialization fails or if the sysvar account update is rejected by the internal accounts database.
Sourcepub fn get_sysvar<T>(&self) -> T
pub fn get_sysvar<T>(&self) -> T
Gets a sysvar from the test environment.
Sourcepub fn get_transaction(
&self,
signature: &Signature,
) -> Option<&TransactionResult>
pub fn get_transaction( &self, signature: &Signature, ) -> Option<&TransactionResult>
Gets a transaction from the transaction history.
Sourcepub fn airdrop_pubkey(&self) -> Address
pub fn airdrop_pubkey(&self) -> Address
Returns the pubkey of the internal airdrop account.
Sourcepub fn airdrop(&mut self, address: &Address, lamports: u64) -> TransactionResult
pub fn airdrop(&mut self, address: &Address, lamports: u64) -> TransactionResult
Airdrops lamports by submitting an internal system transfer transaction.
Unlike set_account, this goes through the normal
execution pipeline instead of mutating balances directly.
Sourcepub fn add_builtin(
&mut self,
program_id: Address,
entrypoint: BuiltinFunctionWithContext,
)
pub fn add_builtin( &mut self, program_id: Address, entrypoint: BuiltinFunctionWithContext, )
Adds a builtin program to the test environment.
Sourcepub fn add_program_from_file(
&mut self,
program_id: impl Into<Address>,
path: impl AsRef<Path>,
) -> Result<(), HPSVMError>
pub fn add_program_from_file( &mut self, program_id: impl Into<Address>, path: impl AsRef<Path>, ) -> Result<(), HPSVMError>
Adds an SBF program to the test environment from the file specified.
Sourcepub fn add_program(
&mut self,
program_id: impl Into<Address>,
program_bytes: &[u8],
) -> Result<(), HPSVMError>
pub fn add_program( &mut self, program_id: impl Into<Address>, program_bytes: &[u8], ) -> Result<(), HPSVMError>
Adds an SBF program to the test environment.
Uses BPFLoaderUpgradeable by default for the loader.
Sourcepub fn add_program_with_loader(
&mut self,
program_id: impl Into<Address>,
program_bytes: &[u8],
loader_id: Address,
) -> Result<(), HPSVMError>
pub fn add_program_with_loader( &mut self, program_id: impl Into<Address>, program_bytes: &[u8], loader_id: Address, ) -> Result<(), HPSVMError>
Adds an SBF program with a specific loader to match mainnet CU behavior.
Use bpf_loader::id() for BPFLoader2, bpf_loader_deprecated::id() for BPFLoader1,
or bpf_loader_upgradeable::id() for the upgradeable loader.
Sourcepub fn send_transaction(
&mut self,
tx: impl Into<VersionedTransaction>,
) -> TransactionResult
pub fn send_transaction( &mut self, tx: impl Into<VersionedTransaction>, ) -> TransactionResult
Submits a signed transaction and commits its post-state to this VM instance.
This updates accounts, transaction history, and other in-memory runtime
state, so it intentionally requires &mut self. hpsvm is optimized for
fast, in-process testing of a single mutable environment rather than
Sealevel-style concurrent scheduling within one instance.
Sourcepub fn process_instruction_case(
&self,
case: &InstructionCase,
) -> Result<ExecutionOutcome, HPSVMError>
pub fn process_instruction_case( &self, case: &InstructionCase, ) -> Result<ExecutionOutcome, HPSVMError>
Executes a single instruction case against a cloned VM without mutating this instance.
Sourcepub fn process_instruction(
&mut self,
instruction: Instruction,
) -> TransactionResult
pub fn process_instruction( &mut self, instruction: Instruction, ) -> TransactionResult
Processes one instruction as a synthetic transaction and commits its post-state.
This is a convenience for instruction-level harnesses that do not need to construct and sign a full transaction. Signature verification is bypassed for this synthetic transaction only; blockhash and runtime behavior still use this VM’s current environment.
Sourcepub fn process_instruction_with_accounts(
&mut self,
instruction: Instruction,
pre_accounts: impl IntoIterator<Item = (Address, Account)>,
) -> Result<TransactionMetadata, FailedTransactionMetadata>
pub fn process_instruction_with_accounts( &mut self, instruction: Instruction, pre_accounts: impl IntoIterator<Item = (Address, Account)>, ) -> Result<TransactionMetadata, FailedTransactionMetadata>
Processes one instruction after first writing the provided account states.
Explicit accounts are written to the VM before execution, then the
instruction post-state is committed just like HPSVM::process_instruction.
Sourcepub fn process_instruction_chain(
&mut self,
instructions: impl IntoIterator<Item = Instruction>,
) -> TransactionResult
pub fn process_instruction_chain( &mut self, instructions: impl IntoIterator<Item = Instruction>, ) -> TransactionResult
Processes multiple instructions atomically and commits their post-state.
Sourcepub fn process_instruction_chain_with_accounts(
&mut self,
instructions: impl IntoIterator<Item = Instruction>,
pre_accounts: impl IntoIterator<Item = (Address, Account)>,
) -> TransactionResult
pub fn process_instruction_chain_with_accounts( &mut self, instructions: impl IntoIterator<Item = Instruction>, pre_accounts: impl IntoIterator<Item = (Address, Account)>, ) -> TransactionResult
Processes multiple instructions atomically after first writing explicit account states.
Sourcepub fn simulate_instruction(
&self,
instruction: Instruction,
) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
pub fn simulate_instruction( &self, instruction: Instruction, ) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
Simulates one instruction without committing post-state.
Sourcepub fn simulate_instruction_with_accounts(
&self,
instruction: Instruction,
pre_accounts: impl IntoIterator<Item = (Address, Account)>,
) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
pub fn simulate_instruction_with_accounts( &self, instruction: Instruction, pre_accounts: impl IntoIterator<Item = (Address, Account)>, ) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
Simulates one instruction with explicit temporary account states.
Sourcepub fn simulate_instruction_chain(
&self,
instructions: impl IntoIterator<Item = Instruction>,
) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
pub fn simulate_instruction_chain( &self, instructions: impl IntoIterator<Item = Instruction>, ) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
Simulates multiple instructions atomically without committing post-state.
Sourcepub fn simulate_instruction_chain_with_accounts(
&self,
instructions: impl IntoIterator<Item = Instruction>,
pre_accounts: impl IntoIterator<Item = (Address, Account)>,
) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
pub fn simulate_instruction_chain_with_accounts( &self, instructions: impl IntoIterator<Item = Instruction>, pre_accounts: impl IntoIterator<Item = (Address, Account)>, ) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
Simulates multiple instructions atomically with explicit temporary account states.
Sourcepub fn try_transact(
&self,
tx: impl Into<VersionedTransaction>,
) -> Result<ExecutionOutcome, HPSVMError>
pub fn try_transact( &self, tx: impl Into<VersionedTransaction>, ) -> Result<ExecutionOutcome, HPSVMError>
Executes a signed transaction without committing its post-state.
The returned ExecutionOutcome is bound to this VM instance and its
current state version. Commit it back to the same HPSVM before any
intervening state or config mutation. Otherwise
HPSVM::commit_transaction returns ResanitizationNeeded.
pub fn transact(&self, tx: impl Into<VersionedTransaction>) -> ExecutionOutcome
Sourcepub fn commit_transaction(
&mut self,
outcome: ExecutionOutcome,
) -> TransactionResult
pub fn commit_transaction( &mut self, outcome: ExecutionOutcome, ) -> TransactionResult
Commits a previously transacted execution outcome to this VM instance.
Outcomes are valid only for the VM instance and state version that
produced them. If this VM mutated after HPSVM::transact created the
outcome, or if the outcome came from a different VM instance, this
returns ResanitizationNeeded.
Sourcepub fn plan_transaction_batch<T>(
&self,
txs: impl IntoIterator<Item = T>,
) -> Result<TransactionBatchPlan, TransactionBatchError>where
T: Into<VersionedTransaction>,
pub fn plan_transaction_batch<T>(
&self,
txs: impl IntoIterator<Item = T>,
) -> Result<TransactionBatchPlan, TransactionBatchError>where
T: Into<VersionedTransaction>,
Plans a conflict-aware transaction batch without committing any state.
The returned stages contain indexes into the original input order. Stages are built greedily from account read/write conflicts and form the basis for higher-level batch schedulers.
Sourcepub fn send_transaction_batch<T>(
&mut self,
txs: impl IntoIterator<Item = T>,
) -> Result<TransactionBatchExecutionResult, TransactionBatchError>where
T: Into<VersionedTransaction>,
pub fn send_transaction_batch<T>(
&mut self,
txs: impl IntoIterator<Item = T>,
) -> Result<TransactionBatchExecutionResult, TransactionBatchError>where
T: Into<VersionedTransaction>,
Submits a batch of transactions and returns a conflict-aware schedule.
Execution results are returned in the original input order. Transactions in the same conflict-free stage are executed against cloned snapshots in parallel, then their disjoint account deltas are merged back into this VM before the next stage begins.
Sourcepub fn simulate_transaction(
&self,
tx: impl Into<VersionedTransaction>,
) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
pub fn simulate_transaction( &self, tx: impl Into<VersionedTransaction>, ) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>
Simulates a transaction without committing post-state.
Sourcepub fn expire_blockhash(&mut self)
pub fn expire_blockhash(&mut self)
Expires the current blockhash.
Sourcepub fn warp_to_slot(&mut self, slot: u64)
pub fn warp_to_slot(&mut self, slot: u64)
Warps the clock to the specified slot.
Sourcepub const fn get_compute_budget(&self) -> Option<ComputeBudget>
pub const fn get_compute_budget(&self) -> Option<ComputeBudget>
Gets the current compute budget.
pub const fn get_sigverify(&self) -> bool
pub fn get_feature_set(&self) -> Arc<FeatureSet>
internal-test only.pub fn set_invocation_inspect_callback<C: InvocationInspectCallback + 'static>( &mut self, callback: C, )
invocation-inspect-callback only.Sourcepub fn register_custom_syscall(
&mut self,
name: &str,
syscall: BuiltinFunction<InvokeContext<'static, 'static>>,
) -> Result<(), HPSVMError>
pub fn register_custom_syscall( &mut self, name: &str, syscall: BuiltinFunction<InvokeContext<'static, 'static>>, ) -> Result<(), HPSVMError>
Advanced reconfiguration. Registers a custom syscall in both program runtime environments (v1 and v2).
This can be called on a freshly constructed HPSVM::new() instance or on an existing
environment after programs have already been loaded. The runtime environments are refreshed
and cached programs are rebuilt so subsequent executions see the new syscall.
Returns an error if runtime refresh, syscall registration, or program cache rebuilding fails.
Trait Implementations§
Source§impl InvokeContextCallback for HPSVM
Available on crate feature precompiles only.
impl InvokeContextCallback for HPSVM
precompiles only.Source§fn is_precompile(&self, program_id: &Address) -> bool
fn is_precompile(&self, program_id: &Address) -> bool
Source§fn process_precompile(
&self,
program_id: &Address,
data: &[u8],
instruction_data_slices: Vec<&[u8]>,
) -> Result<(), PrecompileError>
fn process_precompile( &self, program_id: &Address, data: &[u8], instruction_data_slices: Vec<&[u8]>, ) -> Result<(), PrecompileError>
Source§fn get_epoch_stake(&self) -> u64
fn get_epoch_stake(&self) -> u64
Source§fn get_epoch_stake_for_vote_account(&self, _vote_address: &Address) -> u64
fn get_epoch_stake_for_vote_account(&self, _vote_address: &Address) -> u64
Auto Trait Implementations§
impl Freeze for HPSVM
impl !RefUnwindSafe for HPSVM
impl Send for HPSVM
impl Sync for HPSVM
impl Unpin for HPSVM
impl UnsafeUnpin for HPSVM
impl !UnwindSafe for HPSVM
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more