Two powerful crates for Solana program testing with LiteSVM
| Crate | Description | crates.io | docs.rs |
|---|---|---|---|
| anchor-litesvm | Anchor-specific testing with simplified syntax | ||
| litesvm-utils | Framework-agnostic testing utilities |
- You're testing Anchor programs
- You want simplified syntax similar to anchor-client
- You need Anchor account deserialization and event parsing
- You're testing Native Solana, SPL, or non-Anchor programs
- You want framework-agnostic utilities
- You're building your own testing framework
Note:
anchor-litesvmincludes all oflitesvm-utils, so Anchor users get everything automatically.
┌─────────────────────────────────────┐
│ anchor-litesvm │
│ (Anchor-specific features) │
│ • Simplified syntax │
│ • Account deserialization │
│ • Event parsing │
│ • Discriminator handling │
└─────────────┬───────────────────────┘
│ builds upon
▼
┌─────────────────────────────────────┐
│ litesvm-utils │
│ (Framework-agnostic utilities) │
│ • Account creation & funding │
│ • Token operations │
│ • Transaction helpers │
│ • Assertions │
│ • PDA derivation │
└─────────────┬───────────────────────┘
│ uses
▼
┌─────────────────────────────────────┐
│ LiteSVM │
│ (Fast Solana VM for testing) │
└─────────────────────────────────────┘
[dev-dependencies]
anchor-litesvm = "0.3"use anchor_litesvm::AnchorLiteSVM;
use litesvm_utils::{AssertionHelpers, TestHelpers};
anchor_lang::declare_program!(my_program);
#[test]
fn test_my_program() {
// One-line setup
let mut ctx = AnchorLiteSVM::build_with_program(
my_program::ID,
include_bytes!("../target/deploy/my_program.so"),
);
// Create accounts
let user = ctx.svm.create_funded_account(10_000_000_000).unwrap();
// Build instruction with simplified syntax
let ix = ctx.program()
.accounts(my_program::client::accounts::Initialize { user: user.pubkey(), .. })
.args(my_program::client::args::Initialize { amount: 100 })
.instruction()
.unwrap();
// Execute and verify
ctx.execute_instruction(ix, &[&user]).unwrap().assert_success();
}[dev-dependencies]
litesvm-utils = "0.3"use litesvm_utils::{LiteSVMBuilder, TestHelpers, AssertionHelpers, TransactionHelpers};
#[test]
fn test_my_program() {
// Setup
let mut svm = LiteSVMBuilder::build_with_program(program_id, &program_bytes);
// Create accounts and tokens
let user = svm.create_funded_account(10_000_000_000).unwrap();
let mint = svm.create_token_mint(&user, 9).unwrap();
// Execute and verify
let result = svm.send_instruction(ix, &[&user]).unwrap();
result.assert_success();
svm.assert_token_balance(&token_account, 1_000_000);
}| Metric | Raw LiteSVM | anchor-client | anchor-litesvm |
|---|---|---|---|
| Lines of code | 493 | 279 | 106 |
| Setup lines | 20+ | 15+ | 1 |
| Token mint creation | 30+ lines | 20+ lines | 1 line |
| Compilation | Fast | Slow | Fast |
| Mock RPC needed | No | Yes | No |
- anchor-litesvm README - Anchor-specific features
- litesvm-utils README - Framework-agnostic utilities
- Quick Start Guide - 5-minute tutorial
- API Reference - Complete API docs
- Migration Guide - Migrate from raw LiteSVM
# Run examples
cargo run --example basic_usage
cargo run --example advanced_features# Run all tests (63 total)
cargo test
# Run specific crate tests
cargo test -p anchor-litesvm # 11 tests
cargo test -p litesvm-utils # 52 testsMIT License - see LICENSE for details.
Built on top of LiteSVM, a fast and lightweight Solana VM for testing.