Bankrun (TS)
Bankrun provides fast in-process Solana VM tests from TypeScript without running solana-test-validator. Use it when your team lives in Anchor TS tests but needs LiteSVM-like speed.
Search across all documentation pages
Bankrun provides fast in-process Solana VM tests from TypeScript without running solana-test-validator. Use it when your team lives in Anchor TS tests but needs LiteSVM-like speed.
Quick-reference recipe card - copy-paste ready.
import { startAnchor, BankrunProvider } from "anchor-bankrun";
import { Program } from "@coral-xyz/anchor";
const context = await startAnchor("", [], []);
const provider = new BankrunProvider(context);
const program = new Program(idl, provider);When to reach for this:
chai over Rust #[test].import { startAnchor, BankrunProvider } from "anchor-bankrun";
import { Program, BN } from "@coral-xyz/anchor";
import { Keypair, PublicKey } from "@solana/web3.js";
import { describe, it } from "node:test";
import assert from "node:assert/strict";
describe("vault bankrun", async () => {
const context = await startAnchor(".", [], []);
const provider = new BankrunProvider(context);
const program = new Program(idl as any, provider);
it("deposits tokens", async () => {
const user = Keypair.generate();
context.setAccount(user.publicKey, {
lamports: 1_000_000_000,
data: Buffer.alloc(0),
owner: PublicKey.default,
executable: false,
});
const [vaultPda] = PublicKey.findProgramAddressSync(
[Buffer.from("vault"), user.publicKey.toBuffer()],
program.programId
);
await program.methods
.deposit(new BN(500_000))
.accounts({ user: user.publicKey, vault: vaultPda })
.signers([user])
.rpc();
const vault = await program.account.vault.fetch(vaultPda);
assert.equal(vault.balance.toNumber(), 500_000);
});
});What this demonstrates:
startAnchor loads workspace programs into in-process VM.BankrunProvider wires Anchor client without localhost RPC.context.setAccount seeds account state before instructions..so artifacts load from workspace paths.| Aspect | Bankrun | anchor test (validator) |
|---|---|---|
| Startup | ~ms | seconds |
| RPC fidelity | High for programs | Full |
| SPL Token | Supported | Native |
| DeFi fork | Limited | Surfpool / clone |
// Warp clock for time-dependent ix
context.warpToSlot(100n);anchor build before tests.spl_token.so in startAnchor program list.setAccount.package.json..signers([user]) on mutating ix. Fix: Mirror validator test patterns.| Alternative | Use When | Don't Use When |
|---|---|---|
| LiteSVM (Rust) | Rust-first team | TS-only developers |
| anchor test | Full RPC needed | Speed critical inner loop |
| Surfpool | Mainnet fork DeFi | Simple program logic |
No - keep validator E2E for RPC-specific paths; Bankrun covers bulk of Anchor logic tests.
Use anchor-bankrun version aligned with your Anchor release - check package README.
Support evolves - verify ALT/versioned tx for your bankrun version; fall back to validator if unsupported.
Enable verbose provider logs or catch transaction errors and print simulation logs field.
Yes - npm test with bankrun only; faster and no port conflicts.
Pass program paths array to startAnchor for CPI dependencies.
Same as validator tests - findProgramAddressSync + program.methods...accounts.
assert.rejects on rpc() expecting Anchor error codes.
Bankrun uses web3.js provider model - kit tests can target bankrun RPC if exposed; Anchor path uses web3.js.
When instruction needs real mainnet pool/oracle accounts not easily mocked.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 16, 2026