Deterministic Toncenter API v2 emulator for ICP integration testing
Project description
ton-devtools-rpc-mock
Deterministic Toncenter API v2 emulator for ICP integration testing.
Part of the ton-devtools monorepo.
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
getWalletInformationandrunGetMethod(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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ton_devtools_rpc_mock-0.1.0.tar.gz.
File metadata
- Download URL: ton_devtools_rpc_mock-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a26a89693edc3e2a11f3c8279fdaad92943e980b20a3ec8ab0bb03f8151b98e6
|
|
| MD5 |
4805a4b2863e201e88a5a84d6fa7f617
|
|
| BLAKE2b-256 |
27caaf7f76f740b66623b542c9a0c284b91d3c5fc1ceb82f781452d18b9129d9
|
File details
Details for the file ton_devtools_rpc_mock-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ton_devtools_rpc_mock-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d2ad37235b745c3dcf033b0a889bc5f3353b93373e141878801df01d0f4e899
|
|
| MD5 |
a31d98d00e62f85d4ab84376d143fcc8
|
|
| BLAKE2b-256 |
f648df24e328fa0a28b9d4aef56f826c3119bd08b3acca2f4a3c67578b2853f2
|