#solana #testing

litesvm

A fast and lightweight Solana VM simulator for testing solana programs

7 releases (breaking)

0.6.0 Feb 26, 2025
0.5.0 Jan 24, 2025
0.4.0 Dec 30, 2024
0.3.0 Oct 12, 2024
0.0.1 Feb 8, 2024

#35 in #solana-programs

Download history 115/week @ 2024-11-30 228/week @ 2024-12-07 182/week @ 2024-12-14 46/week @ 2024-12-21 213/week @ 2024-12-28 291/week @ 2025-01-04 195/week @ 2025-01-11 402/week @ 2025-01-18 458/week @ 2025-01-25 450/week @ 2025-02-01 349/week @ 2025-02-08 599/week @ 2025-02-15 724/week @ 2025-02-22 491/week @ 2025-03-01 660/week @ 2025-03-08 506/week @ 2025-03-15

2,498 downloads per month
Used in 5 crates (4 directly)

Apache-2.0

1MB
2K SLoC

Contains (ELF lib, 545KB) src/spl/programs/spl_token_2022-5.0.2.so, (ELF lib, 135KB) src/spl/programs/spl_token-3.5.0.so, (ELF lib, 105KB) spl_associated_token_account-1.1.1.so, (ELF lib, 75KB) src/spl/programs/spl_memo-3.0.0.so, (ELF lib, 18KB) src/spl/programs/spl_memo-1.0.0.so


LiteSVM

github crates.io docs.rs build status

📍 Overview

litesvm is a fast and lightweight library for testing Solana programs. It works by creating an in-process Solana VM optimized for program developers. This makes it much faster to run and compile than alternatives like solana-program-test and solana-test-validator. In a further break from tradition, it has an ergonomic API with sane defaults and extensive configurability for those who want it.

🚀 Getting Started

🔧 Installation

cargo add --dev litesvm

🤖 Minimal Example

use litesvm::LiteSVM;
use solana_keypair::Keypair;
use solana_message::Message;
use solana_pubkey::Pubkey;
use solana_signer::Signer;
use solana_system_interface::instruction::transfer;
use solana_transaction::Transaction;

let from_keypair = Keypair::new();
let from = from_keypair.pubkey();
let to = Pubkey::new_unique();

let mut svm = LiteSVM::new();
svm.airdrop(&from, 10_000).unwrap();

let instruction = transfer(&from, &to, 64);
let tx = Transaction::new(
    &[&from_keypair],
    Message::new(&[instruction], Some(&from)),
    svm.latest_blockhash(),
);
let tx_res = svm.send_transaction(tx).unwrap();

let from_account = svm.get_account(&from);
let to_account = svm.get_account(&to);
assert_eq!(from_account.unwrap().lamports, 4936);
assert_eq!(to_account.unwrap().lamports, 64);

🛠️ Developing litesvm

Run the tests

The tests in this repo use some test programs you need to build first (Solana CLI >= 1.18.8 required):

cd crates/litesvm/test_programs && cargo build-sbf

Then just run cargo test.

Dependencies

~29–40MB
~621K SLoC