Skip to main content
Blueprint provides comprehensive testing capabilities for TON smart contracts through the TON Sandbox emulator and test utilities. This guide covers everything you need to know about writing, running, and debugging tests for your smart contracts.

Quick navigation

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
Built-in Test Utilities
  • Pre-funded treasury wallets for testing
  • Transaction matchers for Jest/Chai/
  • Coverage analysis and reporting
  • Step-by-step execution debugging

Sandbox vs real network

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 fresh Blockchain instance to ensure: Test isolation
  • No state leakage between tests
  • Predictable initial conditions
  • Independent contract deployments
Clean environment
  • Fresh treasury wallets
  • Reset logical time and configuration
  • Clear transaction history

Understanding transaction results

When you send a message to a contract, you receive a SendMessageResult containing:

Transaction matchers

Blueprint provides powerful matchers for validating transactions:

Running tests

Common pitfalls

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 Advanced Topics Debugging Resources Sandbox testing framework provides everything you need to thoroughly test your TON smart contracts. Start with basic deployment tests, then expand to cover all your contract’s functionality with comprehensive positive and negative test cases.