#programs #solana #simulator #vm #testing

litesvm

A fast and lightweight Solana VM simulator for testing solana programs

1 unstable release

0.1.0 Apr 2, 2024
0.0.1 Feb 8, 2024

#108 in #simulator

Apache-2.0

1MB
1.5K SLoC

Contains (ELF lib, 535KB) src/spl/programs/spl_token_2022-1.0.0.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, (ELF lib, 21KB) tests/programs_bytes/hello_world.so


LiteSVM


📍 Overview

litesvm is a fast and lightweight Solana VM simulator for testing programs. It takes inspiration from the good parts of the solana-program-test crate, while offering superior performance and developer experience.

🚀 Getting Started

🔧 Installation

cargo add --dev litesvm

🤖 Minimal Example

use litesvm::LiteSVM;
use solana_program::{message::Message, pubkey::Pubkey, system_instruction::transfer};
use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};

#[test]
fn system_transfer() {
    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);

    let from_account = svm.get_account(&from);
    let to_account = svm.get_account(&to);

    assert!(tx_res.is_ok());
    assert_eq!(from_account.unwrap().lamports, 4936);
    assert_eq!(to_account.unwrap().lamports, 64);
}

Dependencies

~27–43MB
~747K SLoC