Skip to content

Feature request: Add example for testing contracts that interact with external APIs (DeDust, STON.fi) #147

@spendollars

Description

@spendollars

Feature Request

When building TON smart contracts or agents that interact with DeFi protocols (DeDust, STON.fi), there is no clear guide on how to:

  1. Mock external API calls in sandbox tests
  2. Test price oracle interactions
  3. Simulate DEX swap flows in a local environment

Use Case

Many real-world TON contracts query external APIs for price data or trigger swaps. Currently developers have to either:

  • Skip testing these integrations entirely
  • Run tests against real mainnet/testnet (slow, costs gas)

Proposed Addition

An example in the examples/ directory showing:

// Example: Testing a price monitor contract with mocked DeDust prices
import { Blockchain, SandboxContract } from '@ton/sandbox';
import { PriceMonitorContract } from '../build/PriceMonitor';

describe('PriceMonitor', () => {
  let blockchain: Blockchain;
  let contract: SandboxContract<PriceMonitorContract>;

  beforeEach(async () => {
    blockchain = await Blockchain.create();
    // How to mock external price feeds?
    contract = blockchain.openContract(PriceMonitorContract.createFromConfig({
      targetPrice: toNano('6.0'), // 6 USDT per TON
    }));
  });

  it('should trigger alert when price exceeds target', async () => {
    // ...
  });
});

Context

Built TON Agent Platform which creates AI agents for TON DeFi — this was a real gap we encountered during development.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions