Testing & Debugging

Short guide on how to test and debug Tetra smart contracts using @ton/sandbox with a custom executor and on‑chain network config.

1. Prerequisites

Install required dev dependencies:

npm install -D @ton-api/client @tychosdk/emulator

You should also have a standard Blueprint/Sandbox setup (e.g. @ton/sandbox, @ton/core, @ton/test-utils) already in your project.

2. Initializing Blockchain with Tycho

import { TonApiClient } from '@ton-api/client';
import { TychoExecutor } from '@tychosdk/emulator';

beforeEach(async () => {
  const tonapi = new TonApiClient({ baseUrl: 'https://tetra.tonapi.io/' });

  // Get real blockchain config from system contract
  const configAccount = await tonapi.blockchain.getBlockchainRawAccount(
    Address.parse('-1:5555555555555555555555555555555555555555555555555555555555555555'),
  );

  const config = configAccount.data!.asSlice().loadRef();

  // Create local tycho executor with tetra config
  blockchain = await Blockchain.create({
    executor: await TychoExecutor.create(),
    config,
  });
});

Key points:

  1. config is loaded from the on‑chain config contract account so tests match real network parameters.

  2. TychoExecutor replaces the default executor, but Blockchain usage stays the same (you still use openContract, treasury, etc.).

3. Simple contract and test

4. Running tests and debugging

  • Run tests (Blueprint):

  • For debugging:

    • Log res.transactions to inspect messages and status.

    • Check TVM exit codes (exitCode, actionResultCode) when you expect failures.

    • Keep each test isolated by creating a fresh Blockchain in beforeEach.

5. Full testing documentation

For all details about testing, Sandbox and Blueprint, please use the link below

Last updated