Quick Start Guide
This guide covers the basics: how to create an account, fund an account, and send a transaction.
Install Dependencies
Add LiteSVM to your dev dependencies:
cargo add --dev litesvm
Several Solana crates enhance the testing experience by providing essential
types and utilities. You can use the solana-sdk convenience crate or the
individual component crates:
cargo add --dev solana-sdk
Create Test File
Inside your workspace, create a folder for tests.
mkdir tests
Create and Fund an Account
Let's write your first LiteSVM test.
Inside your tests folder, create a new file and copy this code:
use litesvm::LiteSVM;use solana_sdk::signature::{Keypair, Signer};#[test]fn create_account() {// Create the test environmentlet mut svm = LiteSVM::new();// Create a test accountlet user = Keypair::new();// Fund the account with SOLsvm.airdrop(&user.pubkey(), 1_000_000_000).unwrap();// Check the balancelet balance = svm.get_balance(&user.pubkey()).unwrap();assert_eq!(balance, 1_000_000_000);println!("Account funded with {} SOL", balance as f64 / 1e9);}
Run Your Test
cargo test create_account -- --show-output
You should see:
running 1 testtest create_account ... oksuccesses:---- create_account stdout ----Account funded with 1 SOLsuccesses:create_account
That's it! You just made your first litesvm test, that covers creating an account and funding it.
Execute a Transaction
Now let's create a transfer transaction.
Create a new test file and copy this code:
use litesvm::LiteSVM;use solana_sdk::{signature::{Keypair, Signer},system_instruction,transaction::Transaction,};#[test]fn test_transfer() {let mut svm = LiteSVM::new();// Create two accountslet alice = Keypair::new();let bob = Keypair::new();// Fund Alicesvm.airdrop(&alice.pubkey(), 2_000_000_000).unwrap();// Create transfer instructionlet transfer = system_instruction::transfer(&alice.pubkey(),&bob.pubkey(),1_000_000_000, // 1 SOL);// Build and sign transactionlet tx = Transaction::new_signed_with_payer(&[transfer],Some(&alice.pubkey()),&[&alice],svm.latest_blockhash(),);// Send it (execution happens immediately)svm.send_transaction(tx).unwrap();// Check new balancesassert_eq!(svm.get_balance(&bob.pubkey()).unwrap(), 1_000_000_000);assert!(svm.get_balance(&alice.pubkey()).unwrap() < 1_000_000_000);println!("Transfer successful!");}
Test complete! This test covers executing the transfer instruction from the system program.
Run All Tests
cargo test -- --show-output
You should see:
running 1 testtest create_account ... oksuccesses:---- create_account stdout ----Account funded with 1 SOLsuccesses:create_accounttest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04sRunning tests/test_transfer.rs (target/debug/deps/test_transfer-f174954e7483f36b)running 1 testtest test_transfer ... oksuccesses:---- test_transfer stdout ----Transfer successful!successes:test_transfertest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s
That's it! Now you've successfully made litesvm tests that create and fund accounts and execute transactions.
Next Steps
Why LiteSVM → Learn why you would want to use LiteSVM for testing
Testing Your Program → Learn
how to test your own Solana program
Examples
→ View copy-paste solutions for common
scenarios and full repository examples
API Reference
→ Learn advanced features and custom
configurations
Is this page helpful?