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
Thefullstack-test.sh script automatically detects the cluster from Anchor.toml:
- Localnet
- Devnet
For
cluster = "localnet", the script:- Starts
mb-test-validatoron port 8899 - Starts
ephemeral-validatoron port 7799 - Airdrops SOL to the upgrade authority
- Builds and deploys programs
- Runs tests with:
Running Tests
Basic Commands
Using fullstack-test.sh
The fullstack test script provides automated testing with progress indicators:- 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
Test-Locally Script
For project-specific testing:- Checks for
ephemeral-validatorinstallation - Handles the
--skip-local-validatorflag - Manages validator lifecycle
- Airdrops SOL for testing
- Builds, deploys, and tests programs
Test Configuration
Package.json Scripts
package.json
TypeScript Configuration
Tests usets-mocha with extended timeouts:
Testing Different Networks
Localnet Testing
- Set cluster in
Anchor.toml:
- Run tests:
Devnet Testing
- Set cluster in
Anchor.toml:
- 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
Debugging Tests
Enable Verbose Logging
Check RPC Endpoints
View Transaction Details
Next Steps
- Learn about Troubleshooting Common Issues
- Explore Example Programs
- Read the TypeScript SDK Reference or Rust SDK Reference