litesvm
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

LiteSVM (NodeJS)

This is the NodeJS wrapper for LiteSVM. 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 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.

Readme

Keywords

none

Package Sidebar

Install

npm i litesvm

Weekly Downloads

10,945

Version

0.2.0

License

MIT

Unpacked Size

79.5 kB

Total Files

8

Last publish

Collaborators

  • kheavey