npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solana-bankrun

v0.3.1

Published

<div align="center"> <img src="https://raw.githubusercontent.com/kevinheavey/solana-bankrun/main/logo.png" width="50%" height="50%"> </div>

Downloads

21,038

Readme


Bankrun

Bankrun is a superfast, powerful and lightweight framework for testing Solana programs in NodeJS.

While people often use solana-test-validator for this, bankrun is orders of magnitude faster and far more convenient.

You can also do things that are not possible with solana-test-validator, such as jumping back and forth in time or dynamically setting account data.

If you've used solana-program-test you'll be familiar with bankrun, since that's what it uses under the hood.

For those unfamiliar, bankrun and solana-program-test work by spinning up a lightweight BanksServer that's like an RPC node but much faster, and creating a BanksClient to talk to the server. This author thought solana-program-test was a boring name, so he chose bankrun instead (you're running Solana Banks).

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.

Note: If you have multiple test files you should disable parallel tests using the --runInBand Jest flag for now. There is an open issue where concurrent Jest tests occasionally fail due to the program name getting garbled.

Note: The underlying Rust process may print a lot of logs. You can control these with the RUST_LOG environment variable. If you want to silence these logs your test command would look like RUST_LOG= jest --runInBand.

import { start } from "solana-bankrun";
import { PublicKey, Transaction, SystemProgram } from "@solana/web3.js";

test("one transfer", async () => {
	const context = await start([], []);
	const client = context.banksClient;
	const payer = context.payer;
	const receiver = PublicKey.unique();
	const blockhash = context.lastBlockhash;
	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);
	await client.processTransaction(tx);
	const balanceAfter = await client.getBalance(receiver);
	expect(balanceAfter).toEqual(transferLamports);
});

Some things to note here:

  • The context object contains a banks_client to talk to the BanksServer, a payer keypair that has been funded with a bunch of SOL, and a last_blockhash that we can use in our transactions.
  • We haven't loaded any specific programs, but by default we have access to the System Program, the SPL token programs and the SPL memo program.

Installation

yarn add solana-bankrun

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.