@@ -2,14 +2,13 @@ package blockchain
22
33import (
44 "context"
5- "crypto/rand"
6- "encoding/hex"
75 "fmt"
86 "os"
97 "strconv"
108 "time"
119
1210 "github.com/testcontainers/testcontainers-go"
11+ "github.com/testcontainers/testcontainers-go/network"
1312 "github.com/testcontainers/testcontainers-go/wait"
1413
1514 "github.com/smartcontractkit/chainlink-testing-framework/framework"
@@ -97,14 +96,6 @@ func commonContainer(
9796 })
9897}
9998
100- func randomID () string {
101- b := make ([]byte , 4 )
102- if _ , err := rand .Read (b ); err != nil {
103- return fmt .Sprintf ("%d" , time .Now ().UnixNano ()) // fallback
104- }
105- return hex .EncodeToString (b )
106- }
107-
10899func generateUniquePortsFromBase (basePort string ) (* hostPortMapping , error ) {
109100 base , err := strconv .Atoi (basePort )
110101 if err != nil {
@@ -145,22 +136,20 @@ func newTon(in *Input) (*Output, error) {
145136
146137 ctx := context .Background ()
147138
148- instanceID := randomID ()
149- networkName := fmt .Sprintf ("ton-%s" , instanceID )
139+ network , err := network .New (ctx ,
140+ network .WithAttachable (),
141+ network .WithLabels (framework .DefaultTCLabels ()),
142+ )
143+ if err != nil {
144+ return nil , fmt .Errorf ("failed to create network: %w" , err )
145+ }
150146
151- _ , err = testcontainers .GenericNetwork (ctx , testcontainers.GenericNetworkRequest {
152- NetworkRequest : testcontainers.NetworkRequest {
153- Name : networkName ,
154- CheckDuplicate : true ,
155- Attachable : true ,
156- Labels : framework .DefaultTCLabels (),
157- },
158- })
147+ networkName := network .Name
159148 framework .L .Info ().Str ("output" , string (networkName )).Msg ("TON Docker network created" )
160149
161150 tonServices := []containerTemplate {
162151 {
163- Name : fmt .Sprintf ("TON-genesis-%s" , instanceID ),
152+ Name : fmt .Sprintf ("TON-genesis-%s" , networkName ),
164153 Image : "ghcr.io/neodix42/mylocalton-docker:latest" ,
165154 Ports : []string {
166155 fmt .Sprintf ("%s:%s/tcp" , hostPorts .SimpleServer , DefaultTonSimpleServerPort ),
@@ -196,13 +185,13 @@ func newTon(in *Input) (*Output, error) {
196185 },
197186 {
198187 Image : "redis:latest" ,
199- Name : fmt .Sprintf ("TON-redis-%s" , instanceID ),
188+ Name : fmt .Sprintf ("TON-redis-%s" , networkName ),
200189 Network : networkName ,
201190 Alias : "redis" ,
202191 },
203192 {
204193 Image : "postgres:17" ,
205- Name : fmt .Sprintf ("TON-index-postgres-%s" , instanceID ),
194+ Name : fmt .Sprintf ("TON-index-postgres-%s" , networkName ),
206195 Network : networkName ,
207196 Alias : "index-postgres" ,
208197 Env : commonDBVars ,
@@ -214,7 +203,7 @@ func newTon(in *Input) (*Output, error) {
214203 },
215204 },
216205 {
217- Name : fmt .Sprintf ("TON-tonhttpapi-%s" , instanceID ),
206+ Name : fmt .Sprintf ("TON-tonhttpapi-%s" , networkName ),
218207 Image : "ghcr.io/neodix42/ton-http-api:latest" ,
219208 Env : map [string ]string {
220209 "TON_API_LOGS_JSONIFY" : "0" ,
@@ -246,7 +235,7 @@ func newTon(in *Input) (*Output, error) {
246235 Alias : "tonhttpapi" ,
247236 },
248237 {
249- Name : fmt .Sprintf ("TON-faucet-%s" , instanceID ),
238+ Name : fmt .Sprintf ("TON-faucet-%s" , networkName ),
250239 Image : "ghcr.io/neodix42/mylocalton-docker-faucet:latest" ,
251240 Env : map [string ]string {
252241 "FAUCET_USE_RECAPTCHA" : "false" ,
@@ -269,7 +258,7 @@ func newTon(in *Input) (*Output, error) {
269258
270259 tonIndexingAndObservability := []containerTemplate {
271260 {
272- Name : fmt .Sprintf ("TON-explorer-%s" , instanceID ),
261+ Name : fmt .Sprintf ("TON-explorer-%s" , networkName ),
273262 Image : "ghcr.io/neodix42/mylocalton-docker-explorer:latest" ,
274263 Env : map [string ]string {
275264 "SERVER_PORT" : "8080" ,
@@ -285,7 +274,7 @@ func newTon(in *Input) (*Output, error) {
285274 Alias : "explorer" ,
286275 },
287276 {
288- Name : fmt .Sprintf ("TON-index-worker-%s" , instanceID ),
277+ Name : fmt .Sprintf ("TON-index-worker-%s" , networkName ),
289278 Image : "toncenter/ton-indexer-worker:v1.2.0-test" ,
290279 Env : commonDBVars ,
291280 Mounts : testcontainers.ContainerMounts {
@@ -304,7 +293,7 @@ func newTon(in *Input) (*Output, error) {
304293 Alias : "index-worker" ,
305294 },
306295 {
307- Name : fmt .Sprintf ("TON-index-api-%s" , instanceID ),
296+ Name : fmt .Sprintf ("TON-index-api-%s" , networkName ),
308297 Image : "toncenter/ton-indexer-api:v1.2.0-test" ,
309298 Env : commonDBVars ,
310299 Ports : []string {fmt .Sprintf ("%s:8082/tcp" , hostPorts .IndexAPIPort )},
@@ -315,7 +304,7 @@ func newTon(in *Input) (*Output, error) {
315304 Alias : "index-api" ,
316305 },
317306 {
318- Name : fmt .Sprintf ("TON-event-classifier-%s" , instanceID ),
307+ Name : fmt .Sprintf ("TON-event-classifier-%s" , networkName ),
319308 Image : "toncenter/ton-indexer-classifier:v1.2.0-test" ,
320309 Env : commonDBVars ,
321310 WaitFor : wait .ForLog ("Reading finished tasks" ).
0 commit comments