# LiteSVM (NodeJS)

This is the NodeJS wrapper for LiteSVM (opens new window). It brings best-in-class Solana testing to NodeJS, giving you a powerful, fast and ergonomic way to test Solana programs in TS/JS.

For a standard testing workflow, LiteSVM offers an experience superior to solana-test-validator (slow, unwieldy) and bankrun (reasonably fast and powerful, but inherits a lot of warts from solana-program-test).

# Minimal example

This example just transfers lamports from Alice to Bob without loading any programs of our own. It uses the jest (opens new window) test runner but you can use any test runner you like.

import { LiteSVM } from "litesvm";
import {
	PublicKey,
	Transaction,
	SystemProgram,
	Keypair,
	LAMPORTS_PER_SOL,
} from "@solana/web3.js";

test("one transfer", () => {
	const svm = new LiteSVM();
	const payer = new Keypair();
	svm.airdrop(payer.publicKey, BigInt(LAMPORTS_PER_SOL));
	const receiver = PublicKey.unique();
	const blockhash = svm.latestBlockhash();
	const transferLamports = 1_000_000n;
	const ixs = [
		SystemProgram.transfer({
			fromPubkey: payer.publicKey,
			toPubkey: receiver,
			lamports: transferLamports,
		}),
	];
	const tx = new Transaction();
	tx.recentBlockhash = blockhash;
	tx.add(...ixs);
	tx.sign(payer);
	svm.sendTransaction(tx);
	const balanceAfter = svm.getBalance(receiver);
	expect(balanceAfter).toBe(transferLamports);
});

Note: by default the LiteSVM instance includes some core programs such as the System Program and SPL Token.

# Installation

yarn add litesvm

# Contributing

Make sure you have Yarn and the Rust toolchain installed.

Then run yarn to install deps, run yarn build to build the binary and yarn test to run the tests.