|
1 | 1 | package blockchain |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "fmt" |
6 | 5 | "os" |
7 | | - "time" |
8 | 6 |
|
9 | 7 | "github.com/docker/docker/api/types/container" |
10 | 8 | "github.com/docker/docker/api/types/mount" |
11 | 9 |
|
12 | 10 | "github.com/smartcontractkit/chainlink-testing-framework/framework" |
13 | 11 |
|
14 | | - "github.com/docker/go-connections/nat" |
15 | 12 | "github.com/testcontainers/testcontainers-go" |
16 | | - "github.com/testcontainers/testcontainers-go/wait" |
17 | 13 | ) |
18 | 14 |
|
19 | 15 | const ( |
@@ -82,7 +78,7 @@ func defaultGeth(in *Input) { |
82 | 78 |
|
83 | 79 | func newGeth(in *Input) (*Output, error) { |
84 | 80 | defaultGeth(in) |
85 | | - ctx := context.Background() |
| 81 | + req := baseRequest(in, false) |
86 | 82 | defaultCmd := []string{ |
87 | 83 | "--http.corsdomain=*", |
88 | 84 | "--http.vhosts=*", |
@@ -112,8 +108,7 @@ func newGeth(in *Input) (*Output, error) { |
112 | 108 | } |
113 | 109 | entryPoint := append(defaultCmd, in.DockerCmdParamsOverrides...) |
114 | 110 |
|
115 | | - containerName := framework.DefaultTCName("blockchain-node") |
116 | | - bindPort := fmt.Sprintf("%s/tcp", in.Port) |
| 111 | + bindPort := req.ExposedPorts[0] |
117 | 112 |
|
118 | 113 | initScriptFile, err := os.CreateTemp("", "init_script") |
119 | 114 | if err != nil { |
@@ -152,79 +147,41 @@ func newGeth(in *Input) (*Output, error) { |
152 | 147 | return nil, err |
153 | 148 | } |
154 | 149 |
|
155 | | - req := testcontainers.ContainerRequest{ |
156 | | - AlwaysPullImage: in.PullImage, |
157 | | - Image: in.Image, |
158 | | - Labels: framework.DefaultTCLabels(), |
159 | | - Networks: []string{framework.DefaultNetworkName}, |
160 | | - NetworkAliases: map[string][]string{ |
161 | | - framework.DefaultNetworkName: {containerName}, |
| 150 | + req.AlwaysPullImage = in.PullImage |
| 151 | + req.Image = in.Image |
| 152 | + req.Entrypoint = []string{ |
| 153 | + "sh", "./root/init.sh", |
| 154 | + "--datadir", "/root/.ethereum/devchain", |
| 155 | + "--password", "/root/config/password.txt", |
| 156 | + } |
| 157 | + req.HostConfigModifier = func(h *container.HostConfig) { |
| 158 | + h.PortBindings = framework.MapTheSamePort(bindPort) |
| 159 | + framework.ResourceLimitsFunc(h, in.ContainerResources) |
| 160 | + h.Mounts = append(h.Mounts, mount.Mount{ |
| 161 | + Type: mount.TypeBind, |
| 162 | + Source: keystoreDir, |
| 163 | + Target: "/root/.ethereum/devchain/keystore/", |
| 164 | + ReadOnly: false, |
| 165 | + }, mount.Mount{ |
| 166 | + Type: mount.TypeBind, |
| 167 | + Source: configDir, |
| 168 | + Target: "/root/config/", |
| 169 | + ReadOnly: false, |
| 170 | + }) |
| 171 | + } |
| 172 | + req.Files = []testcontainers.ContainerFile{ |
| 173 | + { |
| 174 | + HostFilePath: initScriptFile.Name(), |
| 175 | + ContainerFilePath: "/root/init.sh", |
| 176 | + FileMode: 0644, |
162 | 177 | }, |
163 | | - Entrypoint: []string{ |
164 | | - "sh", "./root/init.sh", |
165 | | - "--datadir", "/root/.ethereum/devchain", |
166 | | - "--password", "/root/config/password.txt", |
| 178 | + { |
| 179 | + HostFilePath: genesisFile.Name(), |
| 180 | + ContainerFilePath: "/root/genesis.json", |
| 181 | + FileMode: 0644, |
167 | 182 | }, |
168 | | - Name: containerName, |
169 | | - ExposedPorts: []string{bindPort}, |
170 | | - HostConfigModifier: func(h *container.HostConfig) { |
171 | | - h.PortBindings = framework.MapTheSamePort(bindPort) |
172 | | - framework.ResourceLimitsFunc(h, in.ContainerResources) |
173 | | - h.Mounts = append(h.Mounts, mount.Mount{ |
174 | | - Type: mount.TypeBind, |
175 | | - Source: keystoreDir, |
176 | | - Target: "/root/.ethereum/devchain/keystore/", |
177 | | - ReadOnly: false, |
178 | | - }, mount.Mount{ |
179 | | - Type: mount.TypeBind, |
180 | | - Source: configDir, |
181 | | - Target: "/root/config/", |
182 | | - ReadOnly: false, |
183 | | - }) |
184 | | - }, |
185 | | - Files: []testcontainers.ContainerFile{ |
186 | | - { |
187 | | - HostFilePath: initScriptFile.Name(), |
188 | | - ContainerFilePath: "/root/init.sh", |
189 | | - FileMode: 0644, |
190 | | - }, |
191 | | - { |
192 | | - HostFilePath: genesisFile.Name(), |
193 | | - ContainerFilePath: "/root/genesis.json", |
194 | | - FileMode: 0644, |
195 | | - }, |
196 | | - }, |
197 | | - WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond), |
198 | | - Cmd: entryPoint, |
199 | 183 | } |
200 | | - c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ |
201 | | - ContainerRequest: req, |
202 | | - Started: true, |
203 | | - }) |
204 | | - if err != nil { |
205 | | - return nil, err |
206 | | - } |
207 | | - host, err := c.Host(ctx) |
208 | | - if err != nil { |
209 | | - return nil, err |
210 | | - } |
211 | | - mp, err := c.MappedPort(ctx, nat.Port(bindPort)) |
212 | | - if err != nil { |
213 | | - return nil, err |
214 | | - } |
215 | | - return &Output{ |
216 | | - UseCache: true, |
217 | | - Family: "evm", |
218 | | - ChainID: in.ChainID, |
219 | | - ContainerName: containerName, |
220 | | - Container: c, |
221 | | - Nodes: []*Node{ |
222 | | - { |
223 | | - HostHTTPUrl: fmt.Sprintf("http://%s:%s", host, mp.Port()), |
224 | | - HostWSUrl: fmt.Sprintf("ws://%s:%s", host, mp.Port()), |
225 | | - DockerInternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, in.Port), |
226 | | - DockerInternalWSUrl: fmt.Sprintf("ws://%s:%s", containerName, in.Port), |
227 | | - }, |
228 | | - }, |
229 | | - }, nil |
| 184 | + req.Cmd = entryPoint |
| 185 | + |
| 186 | + return createGenericEvmContainer(in, req, false) |
230 | 187 | } |
0 commit comments