litesvm

Crates.iolitesvm
lib.rslitesvm
version0.3.0
sourcesrc
created_at2024-02-08 22:28:05.800446
updated_at2024-10-12 07:21:04.890613
descriptionA fast and lightweight Solana VM simulator for testing solana programs
homepage
repositoryhttps://github.com/LiteSVM/litesvm
max_upload_size
id1132718
size1,026,603
Jean Marchand (Exotic Markets) (Aursen)

documentation

README


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_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).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);
}

Development

Run the tests

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

cd test_programs && cargo build-sbf

Then just run cargo test.

Commit count: 81

cargo fmt