LiteSVM

Struct LiteSVM 

Source
pub struct LiteSVM { /* private fields */ }

Implementations§

Source§

impl LiteSVM

Source

pub fn new() -> LiteSVM

Creates the basic test environment.

Source

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

Sets the compute budget.

Source

pub fn with_sigverify(self, sigverify: bool) -> LiteSVM

Enables or disables sigverify.

Source

pub fn with_blockhash_check(self, check: bool) -> LiteSVM

Enables or disables the blockhash check.

Source

pub fn with_sysvars(self) -> LiteSVM

Includes the default sysvars.

Source

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

Set the FeatureSet used by the VM instance.

Source

pub fn with_builtins(self) -> LiteSVM

Changes the default builtins.

Source

pub fn with_lamports(self, lamports: u64) -> LiteSVM

Changes the initial lamports in LiteSVM’s airdrop account.

Source

pub fn with_default_programs(self) -> LiteSVM

Includes the standard SPL programs.

Source

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

Changes the capacity of the transaction history. Set this to 0 to disable transaction history and allow duplicate transactions.

Source

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

Source

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.

Source

pub fn get_account(&self, pubkey: &Address) -> Option<Account>

Returns all information associated with the account of the provided pubkey.

Source

pub fn set_account( &mut self, pubkey: Address, data: Account, ) -> Result<(), LiteSVMError>

Sets all information associated with the account of the provided pubkey.

Source

pub fn accounts_db(&self) -> &AccountsDb

⚠️ ADVANCED USE ONLY ⚠️

Returns a reference to 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 litesvm::LiteSVM;

let svm = LiteSVM::new();

// Read-only access to accounts database
let accounts_db = svm.accounts_db();
// ... inspect internal state if needed
Source

pub fn get_balance(&self, pubkey: &Address) -> Option<u64>

Gets the balance of the provided account pubkey.

Source

pub fn latest_blockhash(&self) -> Hash

Gets the latest blockhash.

Source

pub fn set_sysvar<T>(&mut self, sysvar: &T)

Sets the sysvar to the test environment.

Source

pub fn get_sysvar<T>(&self) -> T

Gets a sysvar from the test environment.

Source

pub fn get_transaction( &self, signature: &Signature, ) -> Option<&Result<TransactionMetadata, FailedTransactionMetadata>>

Gets a transaction from the transaction history.

Source

pub fn airdrop_pubkey(&self) -> Address

Returns the pubkey of the internal airdrop account.

Source

pub fn airdrop( &mut self, pubkey: &Address, lamports: u64, ) -> Result<TransactionMetadata, FailedTransactionMetadata>

Airdrops the account with the lamports specified.

Source

pub fn add_builtin( &mut self, program_id: Address, entrypoint: fn(*mut EbpfVm<'_, InvokeContext<'static>>, u64, u64, u64, u64, u64), )

Adds a builtin program to the test environment.

Source

pub fn add_program_from_file( &mut self, program_id: impl Into<Address>, path: impl AsRef<Path>, ) -> Result<(), LiteSVMError>

Adds an SBF program to the test environment from the file specified.

Source

pub fn add_program( &mut self, program_id: impl Into<Address>, program_bytes: &[u8], ) -> Result<(), LiteSVMError>

Adds am SBF program to the test environment.

Source

pub fn send_transaction( &mut self, tx: impl Into<VersionedTransaction>, ) -> Result<TransactionMetadata, FailedTransactionMetadata>

Submits a signed transaction.

Source

pub fn simulate_transaction( &self, tx: impl Into<VersionedTransaction>, ) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata>

Simulates a transaction.

Source

pub fn expire_blockhash(&mut self)

Expires the current blockhash.

Source

pub fn warp_to_slot(&mut self, slot: u64)

Warps the clock to the specified slot.

Source

pub fn get_compute_budget(&self) -> Option<ComputeBudget>

Gets the current compute budget.

Source

pub fn get_sigverify(&self) -> bool

Trait Implementations§

Source§

impl AssertionHelpers for LiteSVM

Source§

fn assert_account_closed(&self, pubkey: &Pubkey)

Assert that an account is closed (doesn’t exist or has 0 lamports and 0 data) Read more
Source§

fn assert_account_exists(&self, pubkey: &Pubkey)

Assert that an account exists Read more
Source§

fn assert_token_balance(&self, token_account: &Pubkey, expected: u64)

Assert token account balance Read more
Source§

fn assert_sol_balance(&self, pubkey: &Pubkey, expected: u64)

Assert SOL balance Read more
Source§

fn assert_mint_supply(&self, mint: &Pubkey, expected: u64)

Assert token mint supply Read more
Source§

fn assert_account_owner(&self, account: &Pubkey, expected_owner: &Pubkey)

Assert that an account is owned by a specific program Read more
Source§

fn assert_account_data_len(&self, account: &Pubkey, expected_len: usize)

Assert that an account has a specific data length Read more
Source§

impl Clone for LiteSVM

Source§

fn clone(&self) -> LiteSVM

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for LiteSVM

Source§

fn default() -> LiteSVM

Returns the “default value” for a type. Read more
Source§

impl InvokeContextCallback for LiteSVM

Available on non-crate feature precompiles only.
Source§

fn get_epoch_stake(&self) -> u64

Returns the total current epoch stake for the network.
Source§

fn get_epoch_stake_for_vote_account(&self, _vote_address: &Address) -> u64

Returns the current epoch stake for the given vote account.
Source§

fn is_precompile(&self, _program_id: &Address) -> bool

Returns true if the program_id corresponds to a precompiled program
Source§

fn process_precompile( &self, _program_id: &Address, _data: &[u8], _instruction_datas: Vec<&[u8]>, ) -> Result<(), PrecompileError>

Calls the precompiled program corresponding to the given program ID.
Source§

impl ProgramTestExt for LiteSVM

Source§

fn deploy_program(&mut self, program_id: Pubkey, program_bytes: &[u8])

Deploy a program to this LiteSVM instance Read more
Source§

impl TestHelpers for LiteSVM

Source§

fn create_funded_account( &mut self, lamports: u64, ) -> Result<Keypair, Box<dyn Error>>

Create a new funded keypair Read more
Source§

fn create_funded_accounts( &mut self, count: usize, lamports: u64, ) -> Result<Vec<Keypair>, Box<dyn Error>>

Create multiple funded keypairs Read more
Source§

fn create_token_mint( &mut self, authority: &Keypair, decimals: u8, ) -> Result<Keypair, Box<dyn Error>>

Create and initialize a token mint Read more
Source§

fn create_token_account( &mut self, mint: &Pubkey, owner: &Keypair, ) -> Result<Keypair, Box<dyn Error>>

Create a token account for a mint Read more
Source§

fn create_associated_token_account( &mut self, mint: &Pubkey, owner: &Keypair, ) -> Result<Pubkey, Box<dyn Error>>

Create an associated token account Read more
Source§

fn mint_to( &mut self, mint: &Pubkey, account: &Pubkey, authority: &Keypair, amount: u64, ) -> Result<(), Box<dyn Error>>

Mint tokens to an account Read more
Source§

fn derive_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> (Pubkey, u8)

Derive a program-derived address Read more
Source§

fn get_current_slot(&self) -> u64

Get the current slot
Source§

fn advance_slot(&mut self, slots: u64)

Advance the slot by a specified amount
Source§

fn get_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> Pubkey

Get a program-derived address (convenience wrapper for Pubkey::find_program_address) Read more
Source§

fn get_pda_with_bump( &self, seeds: &[&[u8]], program_id: &Pubkey, ) -> (Pubkey, u8)

Get a program-derived address with bump (alias for derive_pda for consistency) Read more
Source§

impl TransactionHelpers for LiteSVM

Source§

fn send_instruction( &mut self, instruction: Instruction, signers: &[&Keypair], ) -> Result<TransactionResult, TransactionError>

Send a single instruction and return a wrapped result Read more
Source§

fn send_instructions( &mut self, instructions: &[Instruction], signers: &[&Keypair], ) -> Result<TransactionResult, TransactionError>

Send multiple instructions in a single transaction Read more
Source§

fn send_transaction_result( &mut self, transaction: Transaction, ) -> Result<TransactionResult, TransactionError>

Send a transaction and return a wrapped result Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V