Skip to content

Commit c6a826f

Browse files
committed
chore: doc
1 parent ee4bb23 commit c6a826f

File tree

1 file changed

+137
-1
lines changed
  • book/src/framework/components/blockchains

1 file changed

+137
-1
lines changed
Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,137 @@
1-
<!-- todo: add ton blockchain doc -->
1+
# TON Blockchain Client
2+
3+
TON (The Open Network) support in the framework utilizes MyLocalTon Docker Compose environment to provide a local TON blockchain for testing purposes.
4+
5+
## Configuration
6+
7+
```toml
8+
[blockchain_a]
9+
type = "ton"
10+
# By default uses MyLocalTon Docker Compose file
11+
image = "https://raw.githubusercontent.com/neodix42/mylocalton-docker/main/docker-compose.yaml"
12+
# Optional: Specify only core services needed for testing (useful in CI environments)
13+
ton_core_services = [
14+
"genesis",
15+
"tonhttpapi",
16+
"event-cache",
17+
"index-postgres",
18+
"index-worker",
19+
"index-api"
20+
]
21+
```
22+
23+
## Default Ports
24+
25+
The TON implementation exposes several services:
26+
27+
- TON Lite Server: Port 40004
28+
- TON HTTP API: Port 8081
29+
- TON Simple HTTP Server: Port 8000
30+
- TON Explorer: Port 8080
31+
32+
## Usage
33+
34+
```go
35+
package examples
36+
37+
import (
38+
"strings"
39+
"testing"
40+
41+
"github.com/stretchr/testify/require"
42+
"github.com/xssnick/tonutils-go/liteclient"
43+
"github.com/xssnick/tonutils-go/ton"
44+
"github.com/xssnick/tonutils-go/ton/wallet"
45+
46+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
47+
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
48+
)
49+
50+
type CfgTon struct {
51+
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
52+
}
53+
54+
func TestTonSmoke(t *testing.T) {
55+
in, err := framework.Load[CfgTon](t)
56+
require.NoError(t, err)
57+
58+
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
59+
require.NoError(t, err)
60+
61+
var client ton.APIClientWrapped
62+
63+
t.Run("setup:connect", func(t *testing.T) {
64+
// Create a connection pool
65+
connectionPool := liteclient.NewConnectionPool()
66+
67+
// Get the network configuration from the global config URL
68+
cfg, cferr := liteclient.GetConfigFromUrl(t.Context(), bc.NetworkSpecificData.TonGlobalConfigURL)
69+
require.NoError(t, cferr, "Failed to get config from URL")
70+
71+
// Add connections from the config
72+
caerr := connectionPool.AddConnectionsFromConfig(t.Context(), cfg)
73+
require.NoError(t, caerr, "Failed to add connections from config")
74+
75+
// Create an API client with retry functionality
76+
client = ton.NewAPIClient(connectionPool).WithRetry()
77+
78+
t.Run("setup:faucet", func(t *testing.T) {
79+
// Create a wallet from the pre-funded high-load wallet seed
80+
rawHlWallet, err := wallet.FromSeed(client, strings.Fields(blockchain.DefaultTonHlWalletMnemonic), wallet.HighloadV2Verified)
81+
require.NoError(t, err, "failed to create highload wallet")
82+
83+
// Create a workchain -1 (masterchain) wallet
84+
mcFunderWallet, err := wallet.FromPrivateKeyWithOptions(client, rawHlWallet.PrivateKey(), wallet.HighloadV2Verified, wallet.WithWorkchain(-1))
85+
require.NoError(t, err, "failed to create highload wallet")
86+
87+
// Get subwallet with ID 42
88+
funder, err := mcFunderWallet.GetSubwallet(uint32(42))
89+
require.NoError(t, err, "failed to get highload subwallet")
90+
91+
// Verify the funder address matches the expected default
92+
require.Equal(t, funder.Address().StringRaw(), blockchain.DefaultTonHlWalletAddress, "funder address mismatch")
93+
94+
// Check the funder balance
95+
master, err := client.GetMasterchainInfo(t.Context())
96+
require.NoError(t, err, "failed to get masterchain info for funder balance check")
97+
funderBalance, err := funder.GetBalance(t.Context(), master)
98+
require.NoError(t, err, "failed to get funder balance")
99+
require.Equal(t, funderBalance.Nano().String(), "1000000000000000", "funder balance mismatch")
100+
})
101+
})
102+
}
103+
```
104+
105+
## Test Private Keys
106+
107+
The framework includes a pre-funded high-load wallet for testing purposes. This wallet type can send up to 254 messages per 1 external message, making it efficient for test scenarios.
108+
109+
Default High-Load Wallet:
110+
```
111+
Address: -1:5ee77ced0b7ae6ef88ab3f4350d8872c64667ffbe76073455215d3cdfab3294b
112+
Mnemonic: twenty unfair stay entry during please water april fabric morning length lumber style tomorrow melody similar forum width ride render void rather custom coin
113+
```
114+
115+
## Available Pre-funded Wallets
116+
117+
MyLocalTon Docker environment comes with several pre-funded wallets that can be used for testing:
118+
119+
1. Genesis Wallet (V3R2, WalletId: 42)
120+
2. Validator Wallets (1-5) (V3R2, WalletId: 42)
121+
3. Faucet Wallet (V3R2, WalletId: 42, Balance: 1 million TON)
122+
4. Faucet Highload Wallet (Highload V2, QueryId: 0, Balance: 1 million TON)
123+
5. Basechain Faucet Wallet (V3R2, WalletId: 42, Balance: 1 million TON)
124+
6. Basechain Faucet Highload Wallet (Highload V2, QueryId: 0, Balance: 1 million TON)
125+
126+
For the complete list of addresses and mnemonics, refer to the [MyLocalTon Docker documentation](https://github.com/neodix42/mylocalton-docker).
127+
128+
## Features of the TON Test Environment
129+
130+
- Flexible blockchain startup parametrization
131+
- Automated validator participation in elections
132+
- Support for 1-6 validators
133+
- 20-minute validation cycle (configurable)
134+
- Predefined lite-server for client connectivity
135+
- Integrated blockchain explorer
136+
- TON Index API v2 and v3 engines
137+
- Cross-platform support (arm64/amd64)

0 commit comments

Comments
 (0)