HPSVM
📍 Overview
hpsvm is a fast and lightweight library for testing Solana programs. It works by creating an in-process Solana VM optimized for program developers. This makes it much faster to run and compile than alternatives like solana-program-test and solana-test-validator. In a further break from tradition, it has an ergonomic API with sane defaults and extensive configurability for those who want it.
hpsvm is optimized for low-overhead, in-process test execution. It does not try to emulate Sealevel-style concurrent scheduling inside a single VM instance. State-committing APIs such as send_transaction intentionally mutate one in-memory test environment in place.
This is a pure Rust library, making it ideal for Rust-native Solana development workflows.
✨ Features
- 🚀 High Performance: In-process VM avoids validator process and RPC overhead, so tests run significantly faster than external validators
- 🛠️ Easy to Use: Simple API with sensible defaults and comprehensive configuration options
- 🔧 Pure Rust: No external dependencies or runtime requirements beyond Rust
- 📊 Comprehensive Testing: Supports transactions, account management, and program execution
- 🔄 Configurable: Extensive options for customizing the test environment
- 📚 Well Documented: Full API documentation and examples
🚀 Getting Started
Prerequisites
- Rust
- Solana CLI (for building test programs)
🔧 Installation
Add hpsvm as a development dependency to your Solana program project:
To read through live RPC state while keeping execution local, add the companion crate as well:
🤖 Quick Example
Here's a minimal example that demonstrates creating a test environment, airdropping SOL, and executing a transfer transaction:
use HPSVM;
use Address;
use Keypair;
use Message;
use Signer;
use transfer;
use Transaction;
// Create keypairs for testing
let from_keypair = new;
let from = from_keypair.pubkey;
let to = new_unique;
// Initialize the SVM with default configuration
let mut svm = HPSVMnew;
// Airdrop SOL to the sender account
svm.airdrop.unwrap;
// Create a transfer instruction
let instruction = transfer;
// Build and sign the transaction
let tx = new;
// Execute the transaction
let tx_result = svm.send_transaction.unwrap;
// Verify the results
let from_account = svm.get_account.unwrap;
let to_account = svm.get_account.unwrap;
assert_eq!; // 10000 - 64 - fee
assert_eq!;
📖 Usage
For more advanced usage, including custom configurations, program deployment, and complex transaction scenarios, see the full documentation.
Architecture Highlights
hpsvm keeps the HPSVM facade stable while exposing a few sharper seams for advanced test harnesses:
transactcomputes anExecutionOutcomewithout mutating the VM, andcommit_transactionapplies it explicitly when you want to persist the result.with_account_sourcelets the VM read missing accounts from an external source while keeping local writes in the in-memory overlay.block_envexposes the current blockhash and slot snapshot, andwith_inspectorinstalls lightweight top-level execution observers.
use HPSVM;
use Address;
use Keypair;
use Message;
use Signer;
use transfer;
use Transaction;
let mut svm = HPSVMnew;
let payer = new;
let recipient = new_unique;
svm.airdrop.unwrap;
let tx = new;
let outcome = svm.transact;
assert!;
assert_eq!;
let commit = svm.commit_transaction;
assert!;
assert_eq!;
assert_eq!;
Forking RPC State
hpsvm can read missing accounts through a configured account source. The hpsvm-fork-rpc companion crate provides an RPC-backed source with a local cache:
use HPSVM;
use RpcForkSource;
let source = builder
.with_rpc_url
.with_slot
.build;
let svm = HPSVMdefault.with_account_source;
Top-Level Instruction Inspection
Use with_inspector when you need lightweight transaction observation without reaching into the lower-level invocation callback APIs:
use ;
use ;
use Address;
let inspector = default;
let observed = clone;
let _svm = HPSVMnew.with_inspector;
assert_eq!;
🛠️ Developing hpsvm
Building Test Programs
The test suite uses Solana programs that need to be built first:
Running Tests
Run the full test suite:
Running Benchmarks
Code Quality
Format code:
Lint code:
🙏 Acknowledgments
- Initially forked from litesvm
- Built for the Solana ecosystem
- Inspired by the need for faster, more ergonomic testing tools
- Thanks to the Solana community for their contributions and feedback