Quick navigation
- What is TON Sandbox — understanding the testing environment
- Writing tests — creating test suites for your contracts
- Running tests — executing and configuring tests
- Common pitfalls — troubleshooting and best practices
What is TON Sandbox
TON Sandbox is a local blockchain emulator that allows you to test smart contracts without deploying them to the real TON network. It provides a complete testing environment that closely mimics the behavior of the actual TON blockchain.Key features
Complete Transaction Emulation- Emulates all transaction phases
- Accurate fee calculation and gas consumption
- Full message routing and processing
- Account state management
- Pre-funded treasury wallets for testing
- Transaction matchers for Jest/Chai/
- Coverage analysis and reporting
- Step-by-step execution debugging
Sandbox vs real network
Feature | Sandbox | Real Network |
---|---|---|
Speed | Instant execution | ~5-15 second finality |
Cost | Free | Requires real TON |
Deterministic | Fully predictable | Network conditions vary |
Debugging | Full introspection | Limited visibility |
State Control | Complete control | Immutable history |
Sandbox limitations
While Sandbox closely emulates the real network, there are some differences to be aware of:- Time-dependent contracts: Sandbox time is controlled, not real-time
- External dependencies: Cannot interact with real external contracts, but can get their state and emulate them
- Blockchain imitation: Because there is no concept of blocks in Sandbox, things like sharding do not work.
Writing tests
Blueprint uses Jest as the default testing framework, providing powerful assertion capabilities and excellent TypeScript support.Basic test setup
Every Blueprint project includes a test template. Here’s the standard structure:tests/MyContract.spec.ts
Test isolation
Each test should include a freshBlockchain
instance to ensure:
Test isolation
- No state leakage between tests
- Predictable initial conditions
- Independent contract deployments
- Fresh treasury wallets
- Reset logical time and configuration
- Clear transaction history
Understanding transaction results
When you send a message to a contract, you receive aSendMessageResult
containing:
Transaction matchers
Blueprint provides powerful matchers for validating transactions:Running tests
Common pitfalls
Avoid These Common Mistakes
- Shared State: Don’t reuse blockchain instances between tests
- Async Issues: Always await blockchain operations
- Time Dependencies: Use
blockchain.now
for time-sensitive tests - Gas Limits: Be aware of computation and action phase limits
- Message Ordering: Remember that message processing is sequential
- Treasury Reuse: Use unique seeds for different test scenarios
Debugging checklist
When tests fail, check these common issues:- ✅ Contract is properly deployed before testing
- ✅ Treasury has sufficient balance for operations
- ✅ Transaction matchers use correct field names
- ✅ Exit codes match expected error conditions
- ✅ Message bodies are correctly formatted
- ✅ Time-sensitive operations account for blockchain time
Next steps
Comprehensive Testing- Testing Reference — Complete API documentation
- Testing Guidelines — Best practices and patterns
- Testing Coverage — Testing coverage
- Blueprint Benchmarks — Performance testing and optimization
- Debug Guide — Advanced debugging techniques
- TON Dev Wallet — Visual debugging tools