Testing Local Validator
Local testing workflows for programs and clients. Results appear in the same fence: same-line // comments when short, multiline // blocks below the sample when not.
Search across all documentation pages
Local testing workflows for programs and clients. Results appear in the same fence: same-line // comments when short, multiline // blocks below the sample when not.
Run a local cluster.
// solana-test-validator
// RPC http://127.0.0.1:8899Fund test accounts.
// await connection.requestAirdrop(pubkey, 2 * LAMPORTS_PER_SOL)Build + local validator + mocha/jest style tests.
// anchor testIn-process SVM for fast unit tests (Rust/TS bindings).
// let mut svm = LiteSVM::new();
// svm.airdrop(&pk, lamports);solana-program-test BanksClient API.
// let mut context = ProgramTest::new(...).start_with_context().await;Advance clock/slot in program-test.
// context.warp_to_slot(slot)Load .so into local validator.
// solana program deploy target/deploy/prog.soClone mainnet accounts into local for integration tests.
// solana-test-validator --clone <pubkey>Surfpool tooling for local-like workflows.
// surfpool start (see current CLI)Match program logs in tests.
// expect logs to contain "Instruction: Initialize"Isolate keypairs/mints per test.
// Keypair.generate() per caseLedger reset when state is dirty.
// solana-test-validator --resetLocal tests often use processed/confirmed.
// commitment: "processed"Set unix_timestamp in program-test sysvars.
// context.set_sysvar(&Clock { ... })Cache cargo/anchor builds in CI for speed.
// cache ~/.cargo and target/Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, Rust 1.91.1, and @solana/kit 7.0.0.
Reviewed by Chris St. John·Last updated Jul 18, 2026