pub trait TestHelpers {
// Required methods
fn create_funded_account(
&mut self,
lamports: u64,
) -> Result<Keypair, Box<dyn Error>>;
fn create_funded_accounts(
&mut self,
count: usize,
lamports: u64,
) -> Result<Vec<Keypair>, Box<dyn Error>>;
fn create_token_mint(
&mut self,
authority: &Keypair,
decimals: u8,
) -> Result<Keypair, Box<dyn Error>>;
fn create_token_account(
&mut self,
mint: &Pubkey,
owner: &Keypair,
) -> Result<Keypair, Box<dyn Error>>;
fn create_associated_token_account(
&mut self,
mint: &Pubkey,
owner: &Keypair,
) -> Result<Pubkey, Box<dyn Error>>;
fn mint_to(
&mut self,
mint: &Pubkey,
account: &Pubkey,
authority: &Keypair,
amount: u64,
) -> Result<(), Box<dyn Error>>;
fn derive_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> (Pubkey, u8);
fn get_current_slot(&self) -> u64;
fn advance_slot(&mut self, slots: u64);
// Provided methods
fn get_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> Pubkey { ... }
fn get_pda_with_bump(
&self,
seeds: &[&[u8]],
program_id: &Pubkey,
) -> (Pubkey, u8) { ... }
}Expand description
Test helper methods for LiteSVM
Required Methods§
Sourcefn create_funded_account(
&mut self,
lamports: u64,
) -> Result<Keypair, Box<dyn Error>>
fn create_funded_account( &mut self, lamports: u64, ) -> Result<Keypair, Box<dyn Error>>
Create a new funded keypair
§Example
let account = svm.create_funded_account(1_000_000_000).unwrap();Sourcefn create_funded_accounts(
&mut self,
count: usize,
lamports: u64,
) -> Result<Vec<Keypair>, Box<dyn Error>>
fn create_funded_accounts( &mut self, count: usize, lamports: u64, ) -> Result<Vec<Keypair>, Box<dyn Error>>
Create multiple funded keypairs
§Example
let accounts = svm.create_funded_accounts(3, 1_000_000_000).unwrap();
assert_eq!(accounts.len(), 3);Sourcefn create_token_mint(
&mut self,
authority: &Keypair,
decimals: u8,
) -> Result<Keypair, Box<dyn Error>>
fn create_token_mint( &mut self, authority: &Keypair, decimals: u8, ) -> Result<Keypair, Box<dyn Error>>
Create and initialize a token mint
§Example
let mint = svm.create_token_mint(&authority, 9).unwrap();Sourcefn create_token_account(
&mut self,
mint: &Pubkey,
owner: &Keypair,
) -> Result<Keypair, Box<dyn Error>>
fn create_token_account( &mut self, mint: &Pubkey, owner: &Keypair, ) -> Result<Keypair, Box<dyn Error>>
Create a token account for a mint
§Example
let token_account = svm.create_token_account(&mint.pubkey(), &owner).unwrap();Sourcefn create_associated_token_account(
&mut self,
mint: &Pubkey,
owner: &Keypair,
) -> Result<Pubkey, Box<dyn Error>>
fn create_associated_token_account( &mut self, mint: &Pubkey, owner: &Keypair, ) -> Result<Pubkey, Box<dyn Error>>
Create an associated token account
§Example
let ata = svm.create_associated_token_account(&mint.pubkey(), &owner).unwrap();Sourcefn mint_to(
&mut self,
mint: &Pubkey,
account: &Pubkey,
authority: &Keypair,
amount: u64,
) -> Result<(), Box<dyn Error>>
fn mint_to( &mut self, mint: &Pubkey, account: &Pubkey, authority: &Keypair, amount: u64, ) -> Result<(), Box<dyn Error>>
Mint tokens to an account
§Example
svm.mint_to(&mint.pubkey(), &token_account, &authority, 1_000_000_000).unwrap();Sourcefn derive_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> (Pubkey, u8)
fn derive_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> (Pubkey, u8)
Derive a program-derived address
§Example
let (pda, bump) = svm.derive_pda(&[b"seed"], &program_id);Sourcefn get_current_slot(&self) -> u64
fn get_current_slot(&self) -> u64
Get the current slot
Sourcefn advance_slot(&mut self, slots: u64)
fn advance_slot(&mut self, slots: u64)
Advance the slot by a specified amount
Provided Methods§
Sourcefn get_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> Pubkey
fn get_pda(&self, seeds: &[&[u8]], program_id: &Pubkey) -> Pubkey
Get a program-derived address (convenience wrapper for Pubkey::find_program_address)
This is a more convenient version that returns just the PDA without the bump. Use this when you don’t need the bump seed.
§Example
// Simple usage with multiple seeds
let escrow_pda = svm.get_pda(
&[b"escrow", maker.pubkey().as_ref(), &seed.to_le_bytes()],
&program_id
);