Skip to main content

ton-devtools-rpc-mock

Deterministic Toncenter API v2 emulator for ICP integration testing.

Part of the ton-devtools monorepo.

PyPI Python License: MIT

What it does

Replaces the live Toncenter API v2 node in tests with an in-process server that:

  • Returns deterministic responses for pre-configured wallet addresses
  • Supports getWalletInformation and runGetMethod (get_public_key)
  • Provides runtime state mutation and fault injection via /_mock/* endpoints
  • Eliminates flaky tests caused by mainnet/testnet availability

Installation

pip install ton-devtools-rpc-mock

Quick Start

As a pytest ASGI fixture (recommended)

import os
import pytest_asyncio
import httpx
from asgi_lifespan import LifespanManager
from ton_devtools_rpc_mock import app, DEPLOYED_WALLET

@pytest_asyncio.fixture
async def trms():
    os.environ["MOCK_CONTROL"] = "1"
    async with LifespanManager(app):
        async with httpx.AsyncClient(
            transport=httpx.ASGITransport(app=app),
            base_url="http://test",
        ) as client:
            await client.post("/_mock/reset")
            yield client

async def test_deployed_wallet(trms):
    resp = await trms.post("/jsonRPC", json={
        "method": "runGetMethod",
        "params": {"address": DEPLOYED_WALLET, "method": "get_public_key", "stack": []},
    })
    assert resp.json()["result"]["exit_code"] == 0

As a standalone server

# Start with control endpoints enabled
ton-devtools-rpc-mock --port 8080 --control

# Point your ICP core service at it
export TON_API_BASE_URL=http://localhost:8080

As a Docker container

docker run -p 8080:8080 -e MOCK_CONTROL=1 ghcr.io/ismaildalgatov/ton-devtools-rpc-mock:latest

Pre-configured fixtures

Constant Address prefix Behaviour
DEPLOYED_WALLET 0:aaaa... Active v4r2 wallet, exit_code: 0, returns real pubkey
UNDEPLOYED_WALLET 0:bbbb... Uninitialized, exit_code: -11, empty stack
FAULT_WALLET 0:cccc... Always returns HTTP 500

Control endpoints

Enabled when MOCK_CONTROL=1:

Endpoint Description
POST /_mock/set_wallet_state Mutate balance, seqno, pubkey, status
POST /_mock/inject_fault Inject http_error, timeout, or corrupt_json
POST /_mock/reset Restore all fixtures, clear global fault

Fault injection

# Inject HTTP 503 on a specific address
await client.post("/_mock/inject_fault", json={
    "address": DEPLOYED_WALLET,
    "fault": {"type": "http_error", "status_code": 503},
})

# Global outage
await client.post("/_mock/inject_fault", json={
    "address": None,
    "fault": {"type": "http_error", "status_code": 502},
})

# Corrupt JSON response
await client.post("/_mock/inject_fault", json={
    "address": DEPLOYED_WALLET,
    "fault": {"type": "corrupt_json"},
})

License

MIT

Metadata

Release files for ton-devtools-rpc-mock 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ton-devtools-rpc-mock 0.1.0
File Size Uploaded
ton_devtools_rpc_mock-0.1.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ton-devtools-rpc-mock 0.1.0
File Interpreter ABI Platform
ton_devtools_rpc_mock-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / ton_devtools_rpc_mock-0.1.0.tar.gz

Download URL ton_devtools_rpc_mock-0.1.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a26a89693edc3e2a11f3c8279fdaad92943e980b20a3ec8ab0bb03f8151b98e6
BLAKE2b-256 checksum
How to use checksums
27caaf7f76f740b66623b542c9a0c284b91d3c5fc1ceb82f781452d18b9129d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release files / ton_devtools_rpc_mock-0.1.0-py3-none-any.whl

Download URL ton_devtools_rpc_mock-0.1.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d2ad37235b745c3dcf033b0a889bc5f3353b93373e141878801df01d0f4e899
BLAKE2b-256 checksum
How to use checksums
f648df24e328fa0a28b9d4aef56f826c3119bd08b3acca2f4a3c67578b2853f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page