trezoalitesvm
v0.4.0
Published
This is the NodeJS wrapper for [TrezoaLiteSVM](https://github.com/TrezoaLiteSVM/trezoalitesvm). It brings best-in-class Trezoa testing to NodeJS, giving you a powerful, fast and ergonomic way to test Trezoa programs in TS/JS.
Readme
TrezoaLiteSVM (NodeJS)
This is the NodeJS wrapper for TrezoaLiteSVM. It brings best-in-class Trezoa testing to NodeJS, giving you a powerful, fast and ergonomic way to test Trezoa programs in TS/JS.
For a standard testing workflow, TrezoaLiteSVM offers an experience superior to trezoa-test-validator (slow, unwieldy)
and bankrun (reasonably fast and powerful, but inherits a lot of warts from trezoa-program-test).
Minimal example
This example just transfers lamports from Alice to Bob without loading any programs of our own. It uses the Node.js test runner.
import { test } from "node:test";
import assert from "node:assert/strict";
import { TrezoaLiteSVM } from "trezoalitesvm";
import {
PublicKey,
Transaction,
SystemProgram,
Keypair,
LAMPORTS_PER_TRZ,
} from "@trezoa/web3.js";
test("one transfer", () => {
const svm = new TrezoaLiteSVM();
const payer = new Keypair();
svm.airdrop(payer.publicKey, BigInt(LAMPORTS_PER_TRZ));
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);
assert.strictEqual(balanceAfter, transferLamports);
});Note: by default the TrezoaLiteSVM instance includes some core programs such as
the System Program and TPL Token.
Installation
yarn add trezoalitesvmContributing
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.
