Skip to main content

Overview

Bankrun is a fast, lightweight testing framework for Solana programs built on top of the Solana Banks client. It provides an ergonomic API for testing Solana programs without the overhead of running a full validator.
Bankrun is primarily used with Solders (Python) and provides similar functionality to LiteSVM, but with a different API design. For TypeScript and Rust testing, consider using [LiteSVMtesting/litesvm) instead.

Key Features

  • Fast Execution - No validator startup time, tests run in-process
  • Lightweight - Minimal resource usage compared to solana-test-validator
  • Direct SVM Access - Tests programs directly against the Solana Virtual Machine
  • Python Support - Part of the Solders Python library ecosystem
  • Time Control - Manipulate clock and slot for testing time-dependent logic

When to Use Bankrun

Bankrun is ideal for:
  • Python-based testing - If your testing workflow uses Python
  • Fast iteration - When you need quick test feedback loops
  • Unit testing - Testing individual program instructions in isolation
  • CI/CD pipelines - Faster test execution in automated environments

Installation

Bankrun is included as part of the Solders library:

Basic Usage

Here’s a simple example of testing a Solana program transfer:

Testing Anchor Programs

To test an Anchor program with Bankrun, you’ll need to:
  1. Build your program with anchor build
  2. Load the program binary in your test
  3. Create and process instructions

Time Manipulation

Bankrun allows you to manipulate the clock for testing time-dependent programs:

Comparison with Other Testing Frameworks

Testing Best Practices

  1. Use fixtures - Create reusable test fixtures for common setups
  2. Test isolation - Each test should start with a fresh context
  3. Async patterns - Leverage Python’s async/await for better test structure
  4. Error cases - Test both success and failure scenarios
  5. State verification - Always verify account states after operations

Example: Full Test Suite

Limitations

  • No RPC methods - Direct account access only, no RPC API
  • Python only - Not available for TypeScript or Rust tests
  • Minimal validator behavior - Doesn’t simulate all validator features
  • Limited ecosystem - Fewer examples and community resources compared to LiteSVM

When to Use solana-test-validator Instead

Consider using solana-test-validator when you need:
  • Full RPC method support
  • Testing validator-specific behavior
  • Integration with external tools and services
  • Testing complex multi-program interactions
  • Realistic production-like testing environment

Additional Resources

Next Steps

  • Explore [LiteSVMtesting/litesvm) for multi-language testing
  • Learn about [Mollusktesting/mollusk) for Rust unit testing
  • Read the [Testing Overviewtesting/overview) for testing strategies