Ghost Testing
Test your contracts in a sandboxed environment without deploying to any network.
What is Ghost Testing?
Ghost testing lets you execute your smart contract in a simulated environment. No deployment, no ALGO spent, instant results.
Benefits
- Free - No gas fees or deployment costs
- Fast - Instant execution without network delays
- Safe - Test failure scenarios without risk
- Detailed - See exactly what happens at each step
The ghost testing concept was pioneered by d13. Check out the original Ghost of AVM repository for more background on the approach.
Creating a Test
- Build your contract successfully
- Click the Ghost tab in the right sidebar
- Click New Test
- Configure initial state (optional)
- Add method calls to the test sequence
- Click Run Test
Configuring Initial State
Before running tests, you can set up the initial contract state:
Global State
Pre-populate global state values:
- Click Initial State in the test config
- Add key-value pairs for global state
- Values are set before any method calls execute
Box Storage
Create boxes with initial data:
- Click Boxes in the test config
- Add box names and initial contents
- Boxes are created before test execution
Account Balances
Configure account ALGO and asset balances:
- Set the test sender's ALGO balance
- Add ASA balances for asset operations
Building Test Sequences
Add method calls to execute in order:
Adding Calls
- Click Add Call
- Select the method from the dropdown
- Fill in argument values
- Configure sender address (optional)
Reordering Calls
Drag and drop calls to reorder the sequence.
Removing Calls
Click the X button on a call to remove it.
Understanding Results
Success/Failure
Each call shows whether it succeeded or failed. Failed calls show the error message.
Return Values
Methods that return values show the decoded result according to the ABI type.
State Diff
See exactly what state changed:
- Green - New state added
- Yellow - Existing state modified
- Red - State removed
Cost Breakdown
View opcode usage for each call. Helps identify expensive operations and optimize your contract.
Execution Trace
Expand for a detailed step-by-step trace showing every opcode executed, stack values, and scratch space.
Saving Tests
Save your test sequences for later:
- Configure your test
- Click Save Test
- Enter a name for the test
- Test is saved to your project
Loading Saved Tests
- Click Saved Tests
- Select a test to load
- Modify if needed and run
Testing Failure Cases
It's important to test that your contract fails correctly:
- Invalid inputs - Test with edge cases and invalid data
- Access control - Call admin methods from non-admin accounts
- Insufficient funds - Try to withdraw more than available
- State constraints - Violate business rules