Skip to content

Commit 51a21de

Browse files
authored
TON: minimal localnet service (#1937)
fix: leaving only genesis
1 parent d12aaf9 commit 51a21de

File tree

5 files changed

+120
-545
lines changed

5 files changed

+120
-545
lines changed

book/src/framework/components/blockchains/ton.md

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,95 @@
11
# TON Blockchain Client
22

3-
TON (The Open Network) support in the framework utilizes MyLocalTon Docker Compose environment to provide a local TON blockchain for testing purposes.
3+
TON (The Open Network) support in the framework utilizes MyLocalTon Docker environment to provide a minimal local TON blockchain for testing purposes.
44

55
## Configuration
66

77
```toml
88
[blockchain_a]
9-
type = "ton"
10-
image = "ghcr.io/neodix42/mylocalton-docker:latest"
9+
type = "ton"
10+
image = "ghcr.io/neodix42/mylocalton-docker:latest"
11+
port = "8000"
1112
```
1213

1314
## Default Ports
1415

15-
The TON implementation exposes several services:
16+
The TON implementation exposes essential services:
1617

17-
- TON Lite Server: Port 40004
18-
- TON HTTP API: Port 8081
19-
- TON Simple HTTP Server: Port 8000
20-
- TON Explorer: Port 8080
18+
* TON Simple HTTP Server: Port 8000
19+
* TON Lite Server: Port derived from base port + 100
2120

22-
> **Note**: By default, only the lite client service is exposed externally. Other services may need additional configuration to be accessible outside the Docker network.
23-
24-
## Validator Configuration
25-
26-
By default, the MyLocalTon environment starts with only one validator enabled. If multiple validators are needed (up to 6 are supported), the Docker Compose file must be provided with modified version with corresponding service definition in toml file before starting the environment.
21+
> Note: `tonutils-go` library is used for TON blockchain interactions, which requires a TON Lite Server connection. `tonutils-go` queries config file to determine the Lite Server connection details, which are provided by the MyLocalTon Docker environment.
2722
2823
## Usage
2924

3025
```go
3126
package examples
3227

3328
import (
34-
"strings"
35-
"testing"
29+
"strings"
30+
"testing"
3631

37-
"github.com/stretchr/testify/require"
38-
"github.com/xssnick/tonutils-go/liteclient"
39-
"github.com/xssnick/tonutils-go/ton"
40-
"github.com/xssnick/tonutils-go/ton/wallet"
32+
"github.com/stretchr/testify/require"
33+
"github.com/xssnick/tonutils-go/liteclient"
34+
"github.com/xssnick/tonutils-go/ton"
35+
"github.com/xssnick/tonutils-go/ton/wallet"
4136

42-
"github.com/smartcontractkit/chainlink-testing-framework/framework"
43-
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
37+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
38+
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
4439
)
4540

4641
type CfgTon struct {
47-
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
42+
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
4843
}
4944

5045
func TestTonSmoke(t *testing.T) {
51-
in, err := framework.Load[CfgTon](t)
52-
require.NoError(t, err)
53-
54-
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
55-
require.NoError(t, err)
56-
57-
var client ton.APIClientWrapped
58-
59-
t.Run("setup:connect", func(t *testing.T) {
60-
// Create a connection pool
61-
connectionPool := liteclient.NewConnectionPool()
62-
63-
// Get the network configuration from the global config URL
64-
cfg, cferr := liteclient.GetConfigFromUrl(t.Context(), fmt.Sprintf("http://%s/localhost.global.config.json", bc.Nodes[0].ExternalHTTPUrl))
65-
require.NoError(t, cferr, "Failed to get config from URL")
66-
67-
// Add connections from the config
68-
caerr := connectionPool.AddConnectionsFromConfig(t.Context(), cfg)
69-
require.NoError(t, caerr, "Failed to add connections from config")
70-
71-
// Create an API client with retry functionality
72-
client = ton.NewAPIClient(connectionPool).WithRetry()
73-
74-
t.Run("setup:faucet", func(t *testing.T) {
75-
// Create a wallet from the pre-funded high-load wallet seed
76-
rawHlWallet, err := wallet.FromSeed(client, strings.Fields(blockchain.DefaultTonHlWalletMnemonic), wallet.HighloadV2Verified)
77-
require.NoError(t, err, "failed to create highload wallet")
78-
79-
// Create a workchain -1 (masterchain) wallet
80-
mcFunderWallet, err := wallet.FromPrivateKeyWithOptions(client, rawHlWallet.PrivateKey(), wallet.HighloadV2Verified, wallet.WithWorkchain(-1))
81-
require.NoError(t, err, "failed to create highload wallet")
82-
83-
// Get subwallet with ID 42
84-
funder, err := mcFunderWallet.GetSubwallet(uint32(42))
85-
require.NoError(t, err, "failed to get highload subwallet")
86-
87-
// Verify the funder address matches the expected default
88-
require.Equal(t, funder.Address().StringRaw(), blockchain.DefaultTonHlWalletAddress, "funder address mismatch")
89-
90-
// Check the funder balance
91-
master, err := client.GetMasterchainInfo(t.Context())
92-
require.NoError(t, err, "failed to get masterchain info for funder balance check")
93-
funderBalance, err := funder.GetBalance(t.Context(), master)
94-
require.NoError(t, err, "failed to get funder balance")
95-
require.Equal(t, funderBalance.Nano().String(), "1000000000000000", "funder balance mismatch")
96-
})
97-
})
46+
in, err := framework.Load[CfgTon](t)
47+
require.NoError(t, err)
48+
49+
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
50+
require.NoError(t, err)
51+
52+
var client ton.APIClientWrapped
53+
54+
t.Run("setup:connect", func(t *testing.T) {
55+
// Create a connection pool
56+
connectionPool := liteclient.NewConnectionPool()
57+
58+
// Get the network configuration from the global config URL
59+
cfg, cferr := liteclient.GetConfigFromUrl(t.Context(), fmt.Sprintf("http://%s/localhost.global.config.json", bc.Nodes[0].ExternalHTTPUrl))
60+
require.NoError(t, cferr, "Failed to get config from URL")
61+
62+
// Add connections from the config
63+
caerr := connectionPool.AddConnectionsFromConfig(t.Context(), cfg)
64+
require.NoError(t, caerr, "Failed to add connections from config")
65+
66+
// Create an API client with retry functionality
67+
client = ton.NewAPIClient(connectionPool).WithRetry()
68+
69+
t.Run("setup:faucet", func(t *testing.T) {
70+
// Create a wallet from the pre-funded high-load wallet seed
71+
rawHlWallet, err := wallet.FromSeed(client, strings.Fields(blockchain.DefaultTonHlWalletMnemonic), wallet.HighloadV2Verified)
72+
require.NoError(t, err, "failed to create highload wallet")
73+
74+
// Create a workchain -1 (masterchain) wallet
75+
mcFunderWallet, err := wallet.FromPrivateKeyWithOptions(client, rawHlWallet.PrivateKey(), wallet.HighloadV2Verified, wallet.WithWorkchain(-1))
76+
require.NoError(t, err, "failed to create highload wallet")
77+
78+
// Get subwallet with ID 42
79+
funder, err := mcFunderWallet.GetSubwallet(uint32(42))
80+
require.NoError(t, err, "failed to get highload subwallet")
81+
82+
// Verify the funder address matches the expected default
83+
require.Equal(t, funder.Address().StringRaw(), blockchain.DefaultTonHlWalletAddress, "funder address mismatch")
84+
85+
// Check the funder balance
86+
master, err := client.GetMasterchainInfo(t.Context())
87+
require.NoError(t, err, "failed to get masterchain info for funder balance check")
88+
funderBalance, err := funder.GetBalance(t.Context(), master)
89+
require.NoError(t, err, "failed to get funder balance")
90+
require.Equal(t, funderBalance.Nano().String(), "1000000000000000", "funder balance mismatch")
91+
})
92+
})
9893
}
9994
```
10095

@@ -103,7 +98,8 @@ func TestTonSmoke(t *testing.T) {
10398
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.
10499

105100
Default High-Load Wallet:
106-
```
101+
102+
```shell
107103
Address: -1:5ee77ced0b7ae6ef88ab3f4350d8872c64667ffbe76073455215d3cdfab3294b
108104
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
109105
```

framework/.changeset/v0.9.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Simplify TON components

0 commit comments

Comments
 (0)