LiteSVMBuilder

Struct LiteSVMBuilder 

Source
pub struct LiteSVMBuilder { /* private fields */ }
Expand description

Builder for creating a LiteSVM instance with programs pre-deployed

This provides a more ergonomic way to set up test environments compared to manually creating LiteSVM instances and deploying programs.

§Example

use litesvm_utils::LiteSVMBuilder;
use solana_program::pubkey::Pubkey;

// Simple single program setup
let program_id = Pubkey::new_unique();
let program_bytes = include_bytes!("../target/deploy/my_program.so");
let mut svm = LiteSVMBuilder::new()
    .deploy_program(program_id, program_bytes)
    .build();

// Or use the convenience method for single program
let mut svm = LiteSVMBuilder::build_with_program(program_id, program_bytes);

Implementations§

Source§

impl LiteSVMBuilder

Source

pub fn new() -> Self

Create a new test environment builder

Source

pub fn deploy_program(self, program_id: Pubkey, program_bytes: &[u8]) -> Self

Add a program to be deployed

Programs are deployed in the order they are added.

§Arguments
  • program_id - The program ID to deploy at
  • program_bytes - The compiled program bytes (.so file contents)
§Example
builder.deploy_program(program_id, program_bytes)
Source

pub fn build(self) -> LiteSVM

Build the LiteSVM instance with all programs deployed

§Returns

Returns the configured LiteSVM instance with all programs deployed

§Example
let mut svm = builder.build();
Source

pub fn build_with_program(program_id: Pubkey, program_bytes: &[u8]) -> LiteSVM

Convenience method to quickly set up a single program

This is equivalent to:

LiteSVMBuilder::new()
    .deploy_program(program_id, program_bytes)
    .build()
§Arguments
  • program_id - The program ID to deploy at
  • program_bytes - The compiled program bytes
§Returns

Returns a configured LiteSVM instance with the program deployed

§Example
let mut svm = LiteSVMBuilder::build_with_program(program_id, program_bytes);
Source

pub fn build_with_programs(programs: &[(Pubkey, &[u8])]) -> LiteSVM

Convenience method to quickly set up multiple programs

§Arguments
  • programs - A slice of (program_id, program_bytes) tuples
§Returns

Returns a configured LiteSVM instance with all programs deployed

§Example
let programs = vec![
    (program_id1, program_bytes1),
    (program_id2, program_bytes2),
];
let mut svm = LiteSVMBuilder::build_with_programs(&programs);

Trait Implementations§

Source§

impl Default for LiteSVMBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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