99 "path/filepath"
1010 "time"
1111
12+ networkTypes "github.com/docker/docker/api/types/network"
13+ "github.com/docker/docker/client"
1214 "github.com/docker/go-connections/nat"
1315 "github.com/testcontainers/testcontainers-go/modules/compose"
1416 "github.com/testcontainers/testcontainers-go/wait"
@@ -114,10 +116,41 @@ func newTon(in *Input) (*Output, error) {
114116 return nil , fmt .Errorf ("failed to start compose stack: %w" , err )
115117 }
116118
117- httpCtr , _ := stack .ServiceContainer (ctx , "genesis" )
118- httpHost , _ := httpCtr .Host (ctx )
119- httpPort , _ := httpCtr .MappedPort (ctx , nat .Port (fmt .Sprintf ("%s/tcp" , DefaultTonSimpleServerPort )))
119+ // node container is started, now we need to connect it to the network
120+ genesisCtr , _ := stack .ServiceContainer (ctx , "genesis" )
120121
122+ // grab and connect to the network
123+ cli , _ := client .NewClientWithOpts (
124+ client .FromEnv ,
125+ client .WithAPIVersionNegotiation (),
126+ )
127+ if err := cli .NetworkConnect (
128+ ctx ,
129+ framework .DefaultNetworkName ,
130+ genesisCtr .ID ,
131+ & networkTypes.EndpointSettings {
132+ Aliases : []string {containerName },
133+ },
134+ ); err != nil {
135+ return nil , fmt .Errorf ("failed to connect to network: %v" , err )
136+ }
137+
138+ httpHost , _ := genesisCtr .Host (ctx )
139+ httpPort , _ := genesisCtr .MappedPort (ctx , nat .Port (fmt .Sprintf ("%s/tcp" , DefaultTonSimpleServerPort )))
140+
141+ // verify that the container is connected to the network
142+ inspected , err := cli .ContainerInspect (ctx , genesisCtr .ID )
143+ if err != nil {
144+ return nil , fmt .Errorf ("inspect error: %w" , err )
145+ }
146+
147+ ns , ok := inspected .NetworkSettings .Networks [framework .DefaultNetworkName ]
148+ if ! ok {
149+ return nil , fmt .Errorf ("container %s is NOT on network %s" , genesisCtr .ID , framework .DefaultNetworkName )
150+ }
151+
152+ fmt .Printf ("✅ TON genesis '%s' is on network %s with IP %s and Aliases %v\n " ,
153+ genesisCtr .ID , framework .DefaultNetworkName , ns .IPAddress , ns .Aliases )
121154 return & Output {
122155 UseCache : true ,
123156 ChainID : in .ChainID ,
@@ -128,6 +161,7 @@ func newTon(in *Input) (*Output, error) {
128161 Nodes : []* Node {{
129162 // Note: define if we need more access other than the global config(tonutils-go only uses liteclients defined in the config)
130163 ExternalHTTPUrl : fmt .Sprintf ("%s:%s" , httpHost , httpPort .Port ()),
164+ InternalHTTPUrl : fmt .Sprintf ("%s:%s" , containerName , httpPort .Port ()),
131165 }},
132166 }, nil
133167}
0 commit comments