Testing and local simulation
Solana testing uses fast in-process checks for focused program behavior and Surfpool for full transaction flows against a local network. Surfpool supplies realistic forked state, controlled time, state setup, transaction inspection, and a standard RPC surface. This page supports the wider Solana development practices, with links to application client development, on-chain program development, and secure token and payment features.
Testing workflow
The testing workflow moves from focused program checks to realistic network checks and then to a small set of cluster checks. Each stage answers a different question, so a slow or remote test should not replace a fast test that can catch the same local error. Surfpool is the integration stage because it combines a normal RPC surface with local control of state and time.
flowchart LR
A[Instruction behavior] --> B[In-process unit test]
B --> C[Full transaction flow]
C --> D[Surfpool integration test]
D --> E[Cluster smoke test]
D --> F[Compute and state review]
Unit behavior
Unit tests check one instruction or a small program rule in an in-process Solana VM. LiteSVM supports Rust and client-language flows with fast execution and compute-unit reporting, while Mollusk supports Rust tests that need direct account control or compute-unit checks. These tests form the fast CI gate.
References: skills/…/testing.md• L20-37 skills/…/testing.md• L109-127 skills/…/testing.md• L129-138
Integration behavior
Integration tests check how instructions work together through a full JSON-RPC and WebSocket surface. Surfpool is the main environment for these tests because it provides realistic account state, lazy remote forking, and complex cross-program flows without the startup cost of a full validator.
References: skills/…/testing.md• L20-26 skills/…/testing.md• L207-217
Fuzz testing
Fuzz tests vary instruction data and account state to find edge cases that fixed examples can miss. They complement unit and integration tests by exploring many valid and invalid inputs, including transaction sequences that model user flows.
References: skills/…/testing.md• L387-395
Cluster validation
Cluster smoke tests run a small happy-path set against devnet or another shared cluster before release. They confirm that deployment and explorer-visible effects work outside local simulation, but remote state and network conditions make them too slow and variable for the normal pull-request gate.
References: skills/…/testing.md• L383-385
Surfpool local simulation
Surfpool is a local Solana network called a surfnet. It aims to give local development and integration tests a normal RPC endpoint with fast startup, on-demand remote state, runtime state controls, and transaction inspection. It is the default local runner for Anchor 1.0 and later, and it can run as a CLI service or inside the test process.
Local network lifecycle
The CLI starts a surfnet for local work and can detect an Anchor or Pinocchio project for program deployment. A test suite can also start the network inside its own process through the embedded SDK. The embedded form gives each client its own lifecycle and dynamic ports, so the suite does not need a separate daemon or fixed port.
sequenceDiagram
participant Test as Test suite
participant Surfnet as Surfpool surfnet
participant RPC as Solana RPC client
Test->>Surfnet: Start local network
Surfnet-->>Test: Provide payer and RPC endpoints
Test->>RPC: Build and send transactions
RPC->>Surfnet: Execute against local state
Surfnet-->>Test: Return results and account state
Test->>Surfnet: Stop network
References: skills/…/testing.md• L236-243 skills/…/testing.md• L373-375 skills/…/kit-plugin.md• L46-86
Forked network state
Surfpool uses mainnet as its default data source and fetches accounts when a test first needs them. It caches that state locally, which lets a test exercise real programs, tokens, and protocol accounts without maintaining a manual clone list. Tests can select devnet or testnet, use a custom RPC source, or run offline when all needed state is local.
References: skills/…/testing.md• L358-371
CLI and embedded modes
The CLI mode is useful for local development, Studio inspection, and a shared network. The embedded SDK is the preferred mode for integration suites because the test owns startup and shutdown. Embedded CI uses the native package supplied by @solana/surfpool, so it does not need a separate Surfpool CLI install. On platforms without the embedded native binary, the Kit client can attach to a running CLI surfnet instead. Embedded clients can also use disposal support, but module-scoped test clients still need an explicit stop hook. Agent-run Surfpool commands use NO_DNA=1 to avoid unwanted environment behavior.
References: skills/…/testing.md• L236-243 skills/…/testing.md• L413-468 skills/…/kit-plugin.md• L40-44 skills/…/kit-plugin.md• L82-86 skills/…/kit-plugin.md• L229-256
Local transaction versions
Surfpool 1.5 and newer enable transaction v1 at startup. This lets local tests cover the larger transaction format and its message-level resource settings before a client sends the flow to a live cluster. Readers still need to request transaction version 1 when they fetch simulated transactions or blocks.
References: skills/…/transactions-v1.md• L8-12 skills/…/transactions-v1.md• L83-85 skills/…/transactions-v1.md• L412-423 skills/…/compatibility-matrix.md• L325-337
Surfpool cheatcodes
Cheatcodes are typed or JSON-RPC controls that change the simulated network without making setup transactions. They reduce test setup time and make conditions such as future time, funded token accounts, forked protocol state, and compute limits repeatable. Surfpool also supports confidential Token-2022 balance setup and inspection through this control surface.
Account and program state
Account cheatcodes create the state that a test needs before it exercises the real transaction path. They can set general account data, set regular or confidential token balances, restore or pin forked accounts, and clone or write programs. A token account still needs an existing mint, and the mint and token account must use the same token program. The mint must be created, forked, or written before the balance is set.
| State need | Cheatcode group | Testing purpose |
|---|---|---|
| General account data | setAccount, resetAccount | Create or restore account state directly |
| Token balances | setTokenAccount, confidential-balance controls | Give a holder tokens without a funding flow |
| Remote account state | streamAccount, offlineAccount | Choose live refresh or local pinning |
| Program state | cloneProgramAccount, writeProgram, setProgramAuthority | Prepare the program surface for a flow |
References: skills/…/cheatcodes.md• L12-39 skills/…/cheatcodes.md• L95-147 skills/…/kit-plugin.md• L104-168 skills/…/tokens.md• L19-37 skills/…/token-2022.md• L29-64
Clock and protocol scenarios
Time controls let tests check expiry, vesting, and other slot-dependent rules without waiting for the simulated clock. Scenario controls apply planned account overrides for protocol and oracle state, which lets a test model market or risk conditions without deploying mock protocol programs. The same cheatcode surface can derive keys for and inspect confidential Token-2022 balances, so token privacy paths can use local fixtures instead of a separate setup flow.
References: skills/…/testing.md• L218-222 skills/…/testing.md• L368-371 skills/…/cheatcodes.md• L24-29 skills/…/cheatcodes.md• L118-147
Transaction profiles and snapshots
Profiling simulates a transaction without committing it and reports compute use, logs, errors, and account changes. Snapshots preserve a chosen network state for later runs. A pre-transaction snapshot can also turn a realistic forked flow into a deterministic offline fixture for LiteSVM or Mollusk.
References: skills/…/cheatcodes.md• L49-65 skills/…/testing.md• L358-371 skills/…/testing.md• L472-477
Cheatcode controls
Surfpool can disable selected cheatcodes when a test environment must prevent state shortcuts. This makes the same local network useful for both setup-heavy development and more constrained checks that should allow only approved controls.
References: skills/…/testing.md• L472-479
Solana Kit integration
The Surfpool Kit plugin connects the standard @solana/kit client to an embedded or existing surfnet. It keeps test code close to production client code while adding a pre-funded payer, normal RPC access, transaction helpers, and typed cheatcodes through the same client.
Embedded Kit client
The default TypeScript integration path is surfpool() with no RPC URL. The plugin starts an isolated surfnet on dynamic ports and returns an asynchronous client. The client provides a payer, RPC and subscription access, transaction helpers, a surfnet handle, and client.cheatcodes; the test must stop the surfnet in its teardown hook unless it uses scoped disposal.
flowchart LR
A[createClient] --> B[use surfpool plugin]
B --> C[Embedded surfnet]
C --> D[Pre-funded payer]
C --> E[Kit RPC and subscriptions]
C --> F[Typed cheatcodes]
D --> G[Test transactions]
E --> G
F --> H[Test state and time]
References: skills/…/testing.md• L243-276 skills/…/kit-plugin.md• L6-20 skills/…/kit-plugin.md• L46-60 skills/…/kit-plugin.md• L82-108
Attached Kit client
Passing rpcUrl makes the plugin connect to a surfnet that is already running. This mode is synchronous and does not load the embedded native runtime. The caller must provide its own payer, and it uses typed cheatcodes because the in-process surfnet handle is not available.
References: skills/…/testing.md• L238-243 skills/…/testing.md• L339-345 skills/…/kit-plugin.md• L229-256
Client composition
The plugin follows the same client contracts as a local RPC plugin, so Kit program plugins can add token or other program instructions on top of it. This lets a test use the same instruction-building style as application code while the transport points to the local simulation. The plugin therefore changes the test environment without forcing a separate client style.
References: skills/…/kit-plugin.md• L202-227
Typed cheatcode access
The Kit layer removes the surfnet_ prefix from method names and unwraps RPC responses. For example, a test calls client.cheatcodes.timeTravel() rather than building a raw JSON-RPC request. Numeric responses use bigint where needed, which protects large Solana values from JavaScript precision loss. The typed surface also includes the confidential-balance methods added to the RPC contract.
References: skills/…/testing.md• L339-345 skills/…/kit-plugin.md• L104-133 skills/…/cheatcodes.md• L24-29
Versioned transaction configuration
The Kit client can pass transactionConfig to the local RPC layer. With a supported Kit RPC plugin, version: 1 makes the test send transaction v1 and places compute, loaded-account, heap, and fee settings in the message configuration. The client must keep resource estimation enabled or set both required limits because unset v1 limits are zero.
References: skills/…/transactions-v1.md• L30-68 skills/…/transactions-v1.md• L72-85 skills/…/transactions-v1.md• L305-321
CI and reproducibility
CI separates fast unit checks from Surfpool integration checks. Embedded Surfpool avoids service orchestration, while a CLI daemon remains an option when a shared RPC process is required. Surfpool-backed suites should run serially when they share a process or other external state.
Test stage separation
The unit stage provides fast feedback for program behavior. The integration stage runs the full RPC flow against an embedded or CLI-backed surfnet. A separate smoke stage can validate a shared cluster before release without making remote behavior part of the pull-request gate.
References: skills/…/testing.md• L413-468
State fixture lifecycle
Tests should seed only the state needed for the scenario and use snapshots for valuable forked states that must be replayed. A snapshot can preserve the network setup for another Surfpool run, while a pre-transaction snapshot can reduce a complex integration discovery step to a deterministic unit fixture.
References: skills/…/testing.md• L358-371 skills/…/testing.md• L472-477
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to the test boundary should keep unit tests independent of an RPC server and integration tests responsible for full RPC behavior.
- Changes to the Surfpool startup mode should keep client construction, async handling, payer ownership, WebSocket access, and teardown aligned.
- Changes to cheatcode names or response shapes should update the typed Kit access path and any raw JSON-RPC examples together.
- Changes to account fixture rules should keep mint existence, token-program selection, extension sizing, fork freshness, offline pinning, and snapshot reload behavior consistent.
- Changes to compute profiling should preserve the difference between dry-run profiles and committed transaction results.
- Changes to transaction-version support should keep local feature activation, Kit plugin versions, resource limits, and transaction-read settings aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
Embedded surfpool() client is created without awaiting the client chain | Test code receives a promise instead of a Kit client | Await the final client in embedded mode |
| Embedded surfnet is not stopped after the suite | Ports or sockets remain open and the test process can hang | Call client.surfnet.stop() in after or afterAll, or use scoped disposal |
setTokenAccount targets a mint that does not exist | Token setup fails before the program flow starts | Create, fork, or write the mint first |
| A token fixture uses a different token program from its mint | ATA derivation or token instructions target the wrong account surface | Read the mint owner and use that program for the token account and ATA |
An attached client expects client.surfnet or the embedded payer | The test uses handles or keys that attach mode does not provide | Supply a payer and use client.cheatcodes |
| A profiling result is treated as a committed transaction | Assertions inspect state that the profile did not change | Treat profiles as dry runs and send a separate transaction when state changes matter |
| A test depends on live fork state without pinning or a snapshot | Repeated runs can see different remote account data | Pin accounts or save a snapshot for the scenario |
| A v1 test leaves compute or loaded-account limits unset | Simulation or send fails with a zero resource budget | Enable resource estimation or set both limits explicitly |
A transaction reader omits maxSupportedTransactionVersion: 1 | Reads fail or block subscriptions stop when v1 data appears | Opt in with the numeric version value |
Key files
| File | Why to read it |
|---|---|
| skills/…/testing.md | Defines the testing pyramid, tool choice, Surfpool modes, fixture flow, and CI split |
| skills/…/kit-plugin.md | Describes embedded and attach modes for the Solana Kit client and their lifecycle rules |
| skills/…/overview.md | Explains the Surfpool network model, CLI lifecycle, fork behavior, and environment choices |
| skills/…/cheatcodes.md | Defines the cheatcode groups and the state, time, confidential-balance, profile, and snapshot controls |
| skills/…/tokens.md | Defines token-program ownership and account relationships that local token fixtures must preserve |
| skills/…/token-2022.md | Explains Token-2022 account sizing, ATA selection, and extension rules relevant to local fixtures |
| skills/…/transactions-v1.md | Explains local v1 transaction support, resource limits, and Kit client behavior |
| skills/…/compatibility-matrix.md | Maps testing tools, Surfpool, Anchor, Solana, and runtime versions |