Skip to main content

Overview

Testing programs with Ephemeral Rollups requires connecting to both the base layer (Solana) and the Ephemeral Rollup. This guide covers test patterns, environment detection, and running tests across different networks.

Test Architecture

Dual Provider Pattern

All examples use a dual provider pattern to interact with both layers:
The base layer provider handles initialization, delegation, and undelegation. The Ephemeral Rollup provider handles high-speed transactions.

Test Workflow

A typical test suite follows this pattern:
1

Initialize on Base Layer

Create and initialize accounts on Solana:
2

Delegate to Ephemeral Rollup

Delegate accounts to the Ephemeral Rollup:
Always wait 2-3 seconds after delegation for the account to be available in the Ephemeral Rollup.
3

Execute on Ephemeral Rollup

Run high-speed transactions on the Ephemeral Rollup:
4

Commit State

Commit Ephemeral Rollup state back to Solana:
5

Undelegate

Return accounts to Solana:

Environment Detection

The fullstack-test.sh script automatically detects the cluster from Anchor.toml:
For cluster = "localnet", the script:
  1. Starts mb-test-validator on port 8899
  2. Starts ephemeral-validator on port 7799
  3. Airdrops SOL to the upgrade authority
  4. Builds and deploys programs
  5. Runs tests with:

Running Tests

Basic Commands

Using fullstack-test.sh

The fullstack test script provides automated testing with progress indicators:
Features:
  • Auto-detects cluster from Anchor.toml
  • Starts validators automatically for localnet
  • Shows progress with spinners and timings
  • Runs multiple examples in sequence
  • Cleans up validators on completion
The script will kill existing validators on ports 8899 and 7799 if running when cluster is localnet.

Test-Locally Script

For project-specific testing:
This script:
  • Checks for ephemeral-validator installation
  • Handles the --skip-local-validator flag
  • Manages validator lifecycle
  • Airdrops SOL for testing
  • Builds, deploys, and tests programs

Test Configuration

Package.json Scripts

package.json

TypeScript Configuration

Tests use ts-mocha with extended timeouts:

Testing Different Networks

Localnet Testing

  1. Set cluster in Anchor.toml:
  1. Run tests:

Devnet Testing

  1. Set cluster in Anchor.toml:
  1. Use devnet Ephemeral Rollup:

Local ER with Devnet

Test against devnet but use a local Ephemeral Rollup:

Test Utilities

Checking Balances

Timing Transactions

Environment Detection in Tests

Best Practices

Always wait after delegation: Wait 2-3 seconds after delegating accounts before executing transactions on the Ephemeral Rollup.
Use skipPreflight for commits: When committing state, use skipPreflight: true to avoid simulation failures.
Set proper timeouts: Use extended timeouts (-t 1000000) for mocha tests to accommodate network delays.
Track both layers: Always log transaction signatures and timings for both base layer and Ephemeral Rollup operations.

Debugging Tests

Enable Verbose Logging

Check RPC Endpoints

View Transaction Details

Next Steps