litesvm-utils
Framework-agnostic testing utilities for LiteSVM that dramatically simplify Solana program testing.
This crate provides essential helpers that work with any Solana program (not just Anchor):
- Account creation and funding (one-liners)
- Token operations (mints, accounts, minting)
- Transaction execution with rich result analysis
- Assertion helpers for testing account states
- PDA derivation utilities
- Clock and slot manipulation
Why litesvm-utils?
Before (Raw LiteSVM):
// 30+ lines to create a token mint
let mint = new;
let rent = svm.minimum_balance_for_rent_exemption;
let create_account_ix = create_account;
let init_mint_ix = initialize_mint;
// ... transaction building, signing, sending ...
After (litesvm-utils):
let mint = svm.create_token_mint?; // One line
Features
Test Account Helpers
Create funded accounts, mints, and token accounts in single calls:
let user = svm.create_funded_account?;
let accounts = svm.create_funded_accounts?;
Token Operations
One-line token operations without manual transaction building:
let mint = svm.create_token_mint?;
let token_account = svm.create_associated_token_account?;
svm.mint_to?;
Transaction Helpers
Execute transactions with automatic result analysis:
let result = svm.send_instruction?;
result.assert_success;
assert!;
Assertion Helpers
Clean, readable test assertions:
svm.assert_token_balance;
svm.assert_sol_balance;
svm.assert_account_exists;
svm.assert_account_closed;
PDA Utilities
Convenient PDA derivation:
let pda = svm.get_pda;
let = svm.get_pda_with_bump;
Clock Manipulation
Test time-based logic:
let slot = svm.get_current_slot;
svm.advance_slot;
Quick Start
use ;
use Pubkey;
// 1. Initialize with one line
let program_id = new_unique;
let program_bytes = include_bytes!;
let mut svm = build_with_program;
// 2. Create test accounts in one line each
let maker = svm.create_funded_account.unwrap;
let taker = svm.create_funded_account.unwrap;
// 3. Create token infrastructure
let mint = svm.create_token_mint.unwrap;
let maker_ata = svm.create_associated_token_account.unwrap;
svm.mint_to.unwrap;
// 4. Execute instruction and analyze results
let result = svm.send_instruction.unwrap;
result.assert_success;
assert!;
// 5. Verify with clean assertions
svm.assert_token_balance;
svm.assert_sol_balance;
Complete Example
use ;
Framework Agnostic
Unlike anchor-litesvm, this crate works with any Solana program:
- Native Solana programs
- Anchor programs
- Solana Program Library (SPL) programs
- Custom frameworks
Traits
- [
TestHelpers] - Account and token creation helpers - [
AssertionHelpers] - Test assertion methods - [
TransactionHelpers] - Transaction execution helpers
Modules
- [
assertions] - Assertion helper implementations - [
builder] - Test environment builders - [
test_helpers] - Test helper implementations - [
transaction] - Transaction execution and result analysis