LiteSVM

The Solana LiteSVM library.

class FeatureSet
activated_slot(feature_id)

Find the slot at which a feature was activated.

Parameters:

feature_id (Pubkey) – The feature ID.

Returns

Optional[int]: The activated slot, if it exists.

active

Mapping of feature IDs to the slots at which they were activated.

Type:

Dict[Pubkey, int]

static all_enabled()

Create a new FeatureSet with all featues enabled.

Returns:

The FeatureSet object.

Return type:

FeatureSet

static default()

Create a new FeatureSet with no featues enabled.

Returns:

The FeatureSet object.

Return type:

FeatureSet

inactive

The inactive feature IDs.

Type:

Set[Pubkey]

is_active(feature_id)

Check if a given feature is active.

Parameters:

feature_id (Pubkey) – The feature ID.

Returns

bool: True if the feature is active.

class LiteSVM

The main class in the litesvm library.

Use this to send transactions, query accounts and configure the runtime.

static default() LiteSVM

Create a new LiteSVM instance with minimal functionality enabled.

with_compute_budget(budget: ComputeBudget) LiteSVM

Set the compute budget.

Parameters:

budget – The new compute budget

Returns:

The modified LiteSVM instance

with_sigverify(sigverify: bool) LiteSVM

Enable or disable sigverify.

Parameters:

sigverify – if false, transaction signatures will not be checked.

Returns:

The modified LiteSVM instance

with_blockhash_check(check: bool) LiteSVM

Enables or disables transaction blockhash checking.

Parameters:

check – If false, the blockhash check will be skipped

Returns:

The modified LiteSVM instance

with_sysvars() LiteSVM

Sets up the standard sysvars.

Returns:

The modified LiteSVM instance

with_builtins(feature_set: FeatureSet | None = None) LiteSVM

Adds the standard builtin programs.

Parameters:

feature_set – if provided, decides what builtins to add based on what features are active

Returns:

The modified LiteSVM instance

with_lamports(lamports: int) LiteSVM

Changes the initial lamports in LiteSVM’s airdrop account.

Parameters:

lamports – The number of lamports to set in the airdrop account

Returns:

The modified LiteSVM instance

with_spl_programs() LiteSVM

Adds the standard SPL programs.

Returns:

The modified LiteSVM instance

with_transaction_history(capacity: int) LiteSVM

Changes the capacity of the transaction history.

Parameters:

capacity – How many transactions to store in history. Set this to 0 to disable transaction history and allow duplicate transactions.

Returns:

The modified LiteSVM instance

with_log_bytes_limit(limit: int | None = None) LiteSVM

Set a limit for transaction logs, beyond which they will be truncated.

Parameters:

limit – The limit in bytes. If None, no limit is enforced.

Returns:

The modified LiteSVM instance

with_precompiles(feature_set: FeatureSet | None = None) LiteSVM

Adds the standard precompiles.

Parameters:

feature_set – if provided, decides what precompiles to add based on what features are active

Returns:

The modified LiteSVM instance

minimum_balance_for_rent_exemption(data_len: int) int

Calculates the minimum balance required to make an account rent exempt.

Parameters:

data_len – The number of bytes in the account.

Returns:

The required balance in lamports

get_account(address: Pubkey) Account | None

Return the account at the given address.

If the account is not found, None is returned.

Parameters:

address – The account address to look up.

Returns:

The account object, if the account exists.

set_account(address: Pubkey, account: Account) None

Create or overwrite an account, subverting normal runtime checks.

This method exists to make it easier to set up artificial situations that would be difficult to replicate by sending individual transactions. Beware that it can be used to create states that would not be reachable by sending transactions!

Parameters:
  • address – The address to write to.

  • account – The account object to write.

get_balance(address: Pubkey) int | None

Gets the balance of the provided account address.

Parameters:

address – The account address.

Returns:

The account’s balance in lamports.

latest_blockhash() Hash

Gets the latest blockhash.

Since LiteSVM doesn’t have blocks, this is an arbitrary value controlled by LiteSVM.

Returns:

The designated latest blockhash.

get_transaction(signature: Signature) TransactionMetadata | FailedTransactionMetadata | None

Gets a transaction from the transaction history.

Parameters:

signature – The transaction signature

Returns:

The transaction, if it is found in the history.

airdrop(address: Pubkey, lamports: int) TransactionMetadata | FailedTransactionMetadata

Airdrops the lamport amount specified to the given address.

Parameters:
  • address – The airdrop recipient.

  • lamports – The amount to airdrop.

Returns:

The transaction result.

add_program_from_file(program_id: Pubkey, path: Path) None

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

Parameters:
  • program_id – The program ID.

  • path – The path to the .so file.

add_program(program_id: Pubkey, program_bytes: bytes) None

Adds an SBF program to the test environment.

Parameters:
  • program_id – The program ID.

  • program_bytes – The raw bytes of the compiled program.

send_transaction(tx: Transaction | VersionedTransaction) TransactionMetadata | FailedTransactionMetadata

Processes a transaction and returns the result.

Parameters:

tx – The transaction to send.

Returns:

TransactionMetadata if transaction succeeds, else FailedTransactionMetadata

simulate_transaction(tx: Transaction | VersionedTransaction) SimulatedTransactionInfo | FailedTransactionMetadata

Simulates a transaction.

Parameters:

tx – The transaction to simulate

Returns:

SimulatedTransactionInfo if sim succeeds, else FailedTransactionMetadata

expire_blockhash() None

Expires the current blockhash.

The return value of latest_blockhash() will be different after calling this.

warp_to_slot(slot: int) None

Warps the clock to the specified slot.

This is a convenience wrapper around set_clock().

Parameters:

slot – The new slot.

get_clock() Clock

Get the cluster clock.

Returns:

the clock object.

set_clock(clock: Clock) None

Overwrite the clock sysvar.

Parameters:

clock – The clock object.

get_epoch_rewards() EpochRewards

Get the EpochRewards sysvar.

Returns:

the EpochRewards object.

set_epoch_rewards(rewards: EpochRewards) None

Overwrite the EpochRewards sysvar.

Parameters:

rewards – The EpochRewards object.

get_epoch_schedule() EpochSchedule

Get the EpochSchedule sysvar.

Returns:

the EpochSchedule object.

set_epoch_schedule(schedule: EpochSchedule) None

Overwrite the EpochSchedule sysvar.

Parameters:

schedule – The EpochSchedule object.

get_last_restart_slot() int

Get the last restart slot sysvar.

Returns:

the last restart slot.

set_last_restart_slot(slot: int) None

Overwrite the last restart slot sysvar.

Parameters:

slot – The last restart slot.

get_rent() Rent

Get the cluster rent.

Returns:

The rent object.

set_rent(rent: Rent) None

Overwrite the rent sysvar.

Parameters:

rent – The new rent object.

get_slot_hashes() List[Tuple[int, Hash]]

Get the SlotHashes sysvar.

Returns:

The SlotHash array.

set_slot_hashes(hashes: Sequence[Tuple[int, Hash]]) None

Overwrite the SlotHashes sysvar.

Parameters:

hashes – The SlotHash array.

get_slot_history() SlotHistory

Get the SlotHistory sysvar.

Returns:

The SlotHistory object.

set_slot_history(history: SlotHistory) None

Overwrite the SlotHistory sysvar.

Parameters:

history – The SlotHistory object

get_stake_history() StakeHistory

Get the StakeHistory sysvar.

Returns:

The StakeHistory object.

set_stake_history(history: StakeHistory) None

Overwrite the StakeHistory sysvar.

Parameters:

history – The StakeHistory object