---
title: Quick Start
description:
  Learn how to use the litesvm-utils crate for streamlined Solana program
  testing
---

<div className="flex items-center gap-3 mb-6">
  <a
    href="https://crates.io/crates/litesvm-utils"
    target="_blank"
    rel="noopener noreferrer"
    className="inline-flex items-center gap-2 px-3 py-1.5 bg-fd-muted/50 hover:bg-fd-muted rounded-lg text-sm font-medium transition-colors border border-fd-border/50"
  >
    <svg
      xmlns="http://www.w3.org/2000/svg"
      viewBox="0 0 512 512"
      className="w-4 h-4"
      fill="currentColor"
    >
      <path d="M239.1 6.3l-208 78c-18.7 7-31.1 25-31.1 45v225.1c0 18.2 10.3 34.8 26.5 42.9l208 104c13.5 6.8 29.4 6.8 42.9 0l208-104c16.3-8.1 26.5-24.8 26.5-42.9V129.3c0-20-12.4-37.9-31.1-44.9l-208-78C262 2.2 250 2.2 239.1 6.3zM256 68.4l192 72v1.1l-192 78-192-78v-1.1l192-72zm32 356V275.5l160-65v133.9l-160 80z" />
    </svg>
    View <code>litesvm-utils</code> on crates.io
  </a>
</div>

## Installation

Make sure you have all the needed dependencies:

```bash
cargo add --dev litesvm litesvm-utils
```

## What is litesvm-utils?

The `litesvm-utils` crate provides essential helper traits and utilities that
simplify Solana program testing. It reduces common testing boilerplate from 30+
lines to minimal, readable code through ergonomic APIs.

<Steps>
<Step>
**TestHelpers Trait**
- Create funded accounts with a single method call
- Set up token mints and token accounts easily
- Derive PDAs without boilerplate
- Manage slots for time-based testing
</Step>

<Step>
  **AssertionHelpers Trait** - Assert account states (exists, closed, owner) -
  Verify token balances and mint supplies - Check SOL balances - Validate
  account data lengths
</Step>

<Step>
  **TransactionHelpers Trait** - Execute instructions with rich result handling
  - Assert transaction success or failure - Check for specific error codes -
  Inspect transaction logs and compute units
</Step>

<Step>
**LiteSVMBuilder**
- Fluent builder pattern for test environment setup
- Deploy programs with method chaining
- Convenient static factory methods
</Step>
</Steps>

## Quick Example

Here's a complete example showing the power of litesvm-utils:

```rust
use litesvm_utils::{AssertionHelpers, LiteSVM, Signer, TestHelpers, TransactionHelpers};
use solana_sdk::{native_token::LAMPORTS_PER_SOL, system_instruction};

#[test]
fn test_with_utils() {
    let mut svm = LiteSVM::new();

    // Create funded accounts in one line
    let alice = svm.create_funded_account(10 * LAMPORTS_PER_SOL).unwrap();
    let bob = svm.create_funded_account(0).unwrap();

    // Create a token mint easily
    let mint = svm.create_token_mint(&alice, 9).unwrap();

    // Create associated token accounts (returns Pubkey)
    let alice_ata = svm.create_associated_token_account(&mint.pubkey(), &alice).unwrap();
    let bob_ata = svm.create_associated_token_account(&mint.pubkey(), &bob).unwrap();

    // Mint tokens
    svm.mint_to(&mint.pubkey(), &alice_ata, &alice, 1000).unwrap();

    // Assert balances
    svm.assert_token_balance(&alice_ata, 1000);
    svm.assert_token_balance(&bob_ata, 0);

    // Execute a SOL transfer with rich result handling
    let transfer_ix = system_instruction::transfer(
        &alice.pubkey(),
        &bob.pubkey(),
        LAMPORTS_PER_SOL,
    );

    let result = svm.send_instruction(transfer_ix, &[&alice]).unwrap();
    result.assert_success();

    // Verify the transfer
    svm.assert_sol_balance(&bob.pubkey(), LAMPORTS_PER_SOL);
}
```

## Key Benefits

### Before litesvm-utils

```rust
// Creating a funded account manually
let keypair = Keypair::new();
let airdrop_tx = Transaction::new_signed_with_payer(
    &[system_instruction::transfer(
        &payer.pubkey(),
        &keypair.pubkey(),
        lamports,
    )],
    Some(&payer.pubkey()),
    &[&payer],
    svm.latest_blockhash(),
);
svm.send_transaction(airdrop_tx).unwrap();
```

### After litesvm-utils

```rust
// One line to create a funded account
let keypair = svm.create_funded_account(lamports).unwrap();
```

## Trait Overview

### TestHelpers

| Method                                         | Returns                | Description                         |
| ---------------------------------------------- | ---------------------- | ----------------------------------- |
| `create_funded_account(lamports)`              | `Result<Keypair>`      | Creates a keypair and funds it      |
| `create_funded_accounts(count, lamports)`      | `Result<Vec<Keypair>>` | Creates multiple funded keypairs    |
| `create_token_mint(authority, decimals)`       | `Result<Keypair>`      | Creates an SPL token mint           |
| `create_token_account(mint, owner)`            | `Result<Keypair>`      | Creates a regular token account     |
| `create_associated_token_account(mint, owner)` | `Result<Pubkey>`       | Creates an ATA, returns its address |
| `mint_to(mint, account, authority, amount)`    | `Result<()>`           | Mints tokens to an account          |
| `derive_pda(seeds, program_id)`                | `(Pubkey, u8)`         | Derives a PDA with bump seed        |
| `get_pda(seeds, program_id)`                   | `Pubkey`               | Gets just the PDA address           |
| `get_pda_with_bump(seeds, program_id)`         | `(Pubkey, u8)`         | Alias for `derive_pda`              |
| `get_current_slot()`                           | `u64`                  | Returns current slot                |
| `advance_slot(slots)`                          | `()`                   | Advances time by N slots            |

### AssertionHelpers

| Method                                  | Description                                    |
| --------------------------------------- | ---------------------------------------------- |
| `assert_account_exists(pubkey)`         | Panics if account does not exist               |
| `assert_account_closed(pubkey)`         | Panics if account exists and has data/lamports |
| `assert_token_balance(account, amount)` | Verifies token balance                         |
| `assert_sol_balance(pubkey, lamports)`  | Verifies SOL balance                           |
| `assert_mint_supply(mint, supply)`      | Verifies mint total supply                     |
| `assert_account_owner(pubkey, owner)`   | Verifies account owner                         |
| `assert_account_data_len(pubkey, len)`  | Verifies data length                           |

### TransactionHelpers

| Method                            | Returns                                       | Description                           |
| --------------------------------- | --------------------------------------------- | ------------------------------------- |
| `send_instruction(ix, signers)`   | `Result<TransactionResult, TransactionError>` | Sends a single instruction            |
| `send_instructions(ixs, signers)` | `Result<TransactionResult, TransactionError>` | Sends multiple instructions in one tx |
| `send_transaction_result(tx)`     | `Result<TransactionResult, TransactionError>` | Sends a raw `Transaction`             |

## Troubleshooting

### Common Errors

| Error               | Cause                                       | Solution                          |
| ------------------- | ------------------------------------------- | --------------------------------- |
| `AccountNotFound`   | Trying to use an account that doesn't exist | Use `create_funded_account` first |
| `InsufficientFunds` | Not enough lamports for transaction         | Increase initial funding amount   |
| `OwnerMismatch`     | Account owned by wrong program              | Verify correct program ID         |
| `AssertionFailed`   | Balance or state doesn't match expected     | Check your test logic             |
