@@ -11,26 +11,48 @@ import (
1111 "time"
1212
1313 "github.com/avast/retry-go/v4"
14- chainsel "github.com/smartcontractkit/chain-selectors"
15- "github.com/smartcontractkit/chainlink-testing-framework/framework"
16- "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
17- "github.com/smartcontractkit/freeport"
1814 "github.com/stretchr/testify/require"
1915 "github.com/testcontainers/testcontainers-go"
2016 "github.com/xssnick/tonutils-go/address"
2117 "github.com/xssnick/tonutils-go/tlb"
2218 "github.com/xssnick/tonutils-go/ton"
2319 "github.com/xssnick/tonutils-go/ton/wallet"
2420
21+ chainsel "github.com/smartcontractkit/chain-selectors"
22+ "github.com/smartcontractkit/chainlink-testing-framework/framework"
23+ "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
24+ "github.com/smartcontractkit/freeport"
25+
2526 "github.com/smartcontractkit/chainlink-deployments-framework/chain"
2627 cldf_ton "github.com/smartcontractkit/chainlink-deployments-framework/chain/ton"
2728)
2829
30+ const (
31+ // defaultTONImage is the default Docker image used for TON localnet.
32+ // Only images from this repository are supported.
33+ defaultTONImage = "ghcr.io/neodix42/mylocalton-docker:v3.7"
34+
35+ // supportedTONImageRepository is the only supported Docker image repository for TON localnet.
36+ supportedTONImageRepository = "ghcr.io/neodix42/mylocalton-docker"
37+ )
38+
2939// CTFChainProviderConfig holds the configuration to initialize the CTFChainProvider.
3040type CTFChainProviderConfig struct {
3141 // Required: A sync.Once instance to ensure that the CTF framework only sets up the new
3242 // DefaultNetwork once
3343 Once * sync.Once
44+
45+ // Optional: Docker image to use for the TON localnet. If empty, defaults to defaultTONImage.
46+ // Note: Only images from supportedTONImageRepository are supported.
47+ Image string
48+
49+ // Optional: Retry count for APIClient. Default is 0 (unlimited retries).
50+ // Set to positive value for specific retry count.
51+ RetryCount int
52+
53+ // Optional: Custom environment variables to pass to the TON container.
54+ // Example: map[string]string{"NEXT_BLOCK_GENERATION_DELAY": "0.5"}
55+ CustomEnv map [string ]string
3456}
3557
3658// validate checks if the CTFChainProviderConfig is valid.
@@ -39,6 +61,10 @@ func (c CTFChainProviderConfig) validate() error {
3961 return errors .New ("sync.Once instance is required" )
4062 }
4163
64+ if c .Image != "" && ! strings .Contains (c .Image , supportedTONImageRepository ) {
65+ return fmt .Errorf ("unsupported image %q: must be from %s" , c .Image , supportedTONImageRepository )
66+ }
67+
4268 return nil
4369}
4470
@@ -103,7 +129,7 @@ func (p *CTFChainProvider) Initialize(_ context.Context) (chain.BlockChain, erro
103129 return * p .chain , nil
104130}
105131
106- func (p * CTFChainProvider ) startContainer (chainID string ) (string , * ton.APIClient ) {
132+ func (p * CTFChainProvider ) startContainer (chainID string ) (string , ton.APIClientWrapped ) {
107133 var (
108134 attempts = uint (10 )
109135 url string
@@ -119,10 +145,11 @@ func (p *CTFChainProvider) startContainer(chainID string) (string, *ton.APIClien
119145
120146 // spin up mylocalton with CTFv2
121147 output , rerr := blockchain .NewBlockchainNetwork (& blockchain.Input {
122- Type : blockchain .TypeTon ,
123- ChainID : chainID ,
124- Port : strconv .Itoa (port ),
125- Image : "ghcr.io/neodix42/mylocalton-docker:v3.7" ,
148+ Type : blockchain .TypeTon ,
149+ ChainID : chainID ,
150+ Port : strconv .Itoa (port ),
151+ Image : p .getImage (),
152+ CustomEnv : p .config .CustomEnv ,
126153 })
127154 if rerr != nil {
128155 // Return the ports to freeport to avoid leaking them during retries
@@ -155,7 +182,9 @@ func (p *CTFChainProvider) startContainer(chainID string) (string, *ton.APIClien
155182 // set starting point to verify master block proofs chain
156183 client .SetTrustedBlock (mb )
157184
158- return url , client
185+ retryCount := p .getRetryCount ()
186+
187+ return url , client .WithRetry (retryCount )
159188}
160189
161190// Note: this utility functions can be replaced once we have in the chainlink-ton utils package
@@ -236,3 +265,16 @@ func (p *CTFChainProvider) ChainSelector() uint64 {
236265func (p * CTFChainProvider ) BlockChain () chain.BlockChain {
237266 return * p .chain
238267}
268+
269+ func (p * CTFChainProvider ) getRetryCount () int {
270+ return p .config .RetryCount
271+ }
272+
273+ // getImage returns the configured Docker image, or the default if not specified.
274+ func (p * CTFChainProvider ) getImage () string {
275+ if p .config .Image != "" {
276+ return p .config .Image
277+ }
278+
279+ return defaultTONImage
280+ }
0 commit comments