Skip to content

Commit 316b060

Browse files
authored
Merge branch 'main' into tt-1806-labelling-readme
2 parents b56ec5e + d2d8cf2 commit 316b060

File tree

21 files changed

+255
-192
lines changed

21 files changed

+255
-192
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Mocking Services](framework/components/mocking.md)
2424
- [Copying Files](framework/copying_files.md)
2525
- [External Environment](framework/components/external.md)
26+
- [Troubleshooting](framework/components/troubleshooting.md)
2627
- [Secrets]()
2728
- [Observability Stack](framework/observability/observability_stack.md)
2829
- [Metrics](framework/observability/metrics.md)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Troubleshooting
2+
3+
## Can't run `anvil`, issue with `Rosetta`
4+
```
5+
2024/11/27 15:20:27 ⏳ Waiting for container id 79f8a68c07cc image: f4hrenh9it/foundry:latest. Waiting for: &{Port:8546 timeout:0x14000901278 PollInterval:100ms skipInternalCheck:false}
6+
2024/11/27 15:20:27 container logs (all exposed ports, [8546/tcp], were not mapped in 5s: port 8546/tcp is not mapped yet
7+
wait until ready: check target: retries: 1, port: "", last err: container exited with code 133):
8+
rosetta error: Rosetta is only intended to run on Apple Silicon with a macOS host using Virtualization.framework with Rosetta mode enabled
9+
```
10+
#### Solution
11+
12+
Update your docker to `Docker version 27.3.1, build ce12230`

book/src/framework/getting_started.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
- `Docker` [OrbStack](https://orbstack.dev/) or [Docker Desktop](https://www.docker.com/products/docker-desktop/), we recommend OrbStack (faster, smaller memory footprint)
55
- [Golang](https://go.dev/doc/install)
66

7+
Tested with
8+
```
9+
Docker version 27.3.1
10+
OrbStack Version: 1.8.2 (1080200)
11+
```
12+
713
## Test setup
814

915
To start writing tests create a directory for your project with `go.mod` and add a package

book/src/framework/observability/blockscout.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ To remove it, we also clean up all Blockscout databases to prevent stale data wh
1212
ctf bs down
1313
```
1414

15+
## Selecting Blockchain Node
16+
17+
By default, we connect to the first `anvil` node, but you can select the node explicitly
18+
```
19+
ctf bs -r http://host.docker.internal:8545 d
20+
ctf bs -r http://host.docker.internal:8555 d
21+
```
22+
1523
<div class="warning">
1624

1725
Blockscout isn’t ideal for local, ephemeral environments, as it won’t re-index blocks and transactions on test reruns. The easiest approach is to set up Blockscout first, initialize the test environment, switch to the [cache](../components/caching.md) config, and run tests without restarting RPC nodes.

framework/.changeset/v0.2.12.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Omit all local tooling container logs
2+
- Allow to connect Blockscout to any node

framework/.changeset/v0.2.13.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Simplify local Chainlink build
2+
- Remove dependency on "local-registry"
3+
- Skip Promtail to accelerate CI 🚀

framework/cmd/blockscout.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package main
33
import (
44
"fmt"
55
"github.com/smartcontractkit/chainlink-testing-framework/framework"
6+
"os"
67
"path/filepath"
78
)
89

9-
func blockscoutUp() error {
10+
func blockscoutUp(url string) error {
1011
framework.L.Info().Msg("Creating local Blockscout stack")
1112
if err := extractAllFiles("observability"); err != nil {
1213
return err
1314
}
15+
os.Setenv("BLOCKSCOUT_RPC_URL", url)
1416
err := runCommand("bash", "-c", fmt.Sprintf(`
1517
cd %s && \
1618
docker compose up -d
@@ -23,8 +25,9 @@ func blockscoutUp() error {
2325
return nil
2426
}
2527

26-
func blockscoutDown() error {
28+
func blockscoutDown(url string) error {
2729
framework.L.Info().Msg("Removing local Blockscout stack")
30+
os.Setenv("BLOCKSCOUT_RPC_URL", url)
2831
err := runCommand("bash", "-c", fmt.Sprintf(`
2932
cd %s && \
3033
docker compose down -v

framework/cmd/docker.go

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import (
66
"github.com/smartcontractkit/chainlink-testing-framework/framework"
77
"os"
88
"os/exec"
9-
"strings"
109
)
1110

12-
func rmTestContainers() error {
11+
func removeTestContainers() error {
1312
framework.L.Info().Str("label", "framework=ctf").Msg("Cleaning up docker containers")
1413
// Bash command for removing Docker containers and networks with "framework=ctf" label
1514
cmd := exec.Command("bash", "-c", `
@@ -45,48 +44,6 @@ func cleanUpDockerResources() error {
4544
return nil
4645
}
4746

48-
// BuildDocker runs Docker commands to set up a local registry, build an image, and push it.
49-
func BuildDocker(dockerfile string, buildContext string, imageName string) error {
50-
registryRunning := isContainerRunning("local-registry")
51-
if registryRunning {
52-
fmt.Println("Local registry container is already running.")
53-
} else {
54-
framework.L.Info().Msg("Starting local registry container...")
55-
err := runCommand("docker", "run", "-d", "-p", "5050:5000", "--name", "local-registry", "registry:2")
56-
if err != nil {
57-
return fmt.Errorf("failed to start local registry: %w", err)
58-
}
59-
framework.L.Info().Msg("Local registry started")
60-
}
61-
62-
img := fmt.Sprintf("localhost:5050/%s:latest", imageName)
63-
framework.L.Info().Str("DockerFile", dockerfile).Str("Context", buildContext).Msg("Building Docker image")
64-
err := runCommand("docker", "build", "-t", fmt.Sprintf("localhost:5050/%s:latest", imageName), "-f", dockerfile, buildContext)
65-
if err != nil {
66-
return fmt.Errorf("failed to build Docker image: %w", err)
67-
}
68-
framework.L.Info().Msg("Docker image built successfully")
69-
70-
framework.L.Info().Str("Image", img).Msg("Pushing Docker image to local registry")
71-
fmt.Println("Pushing Docker image to local registry...")
72-
err = runCommand("docker", "push", img)
73-
if err != nil {
74-
return fmt.Errorf("failed to push Docker image: %w", err)
75-
}
76-
framework.L.Info().Msg("Docker image pushed successfully")
77-
return nil
78-
}
79-
80-
// isContainerRunning checks if a Docker container with the given name is running.
81-
func isContainerRunning(containerName string) bool {
82-
cmd := exec.Command("docker", "ps", "--filter", fmt.Sprintf("name=%s", containerName), "--format", "{{.Names}}")
83-
output, err := cmd.Output()
84-
if err != nil {
85-
return false
86-
}
87-
return strings.Contains(string(output), containerName)
88-
}
89-
9047
// runCommand executes a command and prints the output.
9148
func runCommand(name string, args ...string) error {
9249
cmd := exec.Command(name, args...)

framework/cmd/interactive.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import (
1616
)
1717

1818
type nodeSetForm struct {
19-
Network string
20-
CLVersion string
21-
Nodes int
22-
Observability bool
23-
Blockscout bool
19+
Network string
20+
CLVersion string
21+
Nodes int
22+
Observability bool
23+
Blockscout bool
24+
BlockscoutRPCURL string
2425
}
2526

2627
func createComponentsFromForm(form *nodeSetForm) error {
@@ -83,7 +84,7 @@ func createComponentsFromForm(form *nodeSetForm) error {
8384
}
8485
switch form.Blockscout {
8586
case true:
86-
if err := blockscoutUp(); err != nil {
87+
if err := blockscoutUp(form.BlockscoutRPCURL); err != nil {
8788
return err
8889
}
8990
}
@@ -93,7 +94,7 @@ func createComponentsFromForm(form *nodeSetForm) error {
9394
func cleanup(form *nodeSetForm) error {
9495
var err error
9596
f := func() {
96-
err = rmTestContainers()
97+
err = removeTestContainers()
9798
}
9899
err = spinner.New().
99100
Title("Removing docker resources..").
@@ -107,7 +108,7 @@ func cleanup(form *nodeSetForm) error {
107108
}
108109
switch form.Blockscout {
109110
case true:
110-
if err := blockscoutDown(); err != nil {
111+
if err := blockscoutDown(form.BlockscoutRPCURL); err != nil {
111112
return err
112113
}
113114
}
@@ -156,6 +157,13 @@ Docker Desktop (https://www.docker.com/products/docker-desktop/)
156157
huh.NewConfirm().
157158
Title("Do you need to spin up a Blockscout stack?").
158159
Value(&f.Blockscout),
160+
huh.NewSelect[string]().
161+
Title("To which blockchain node you want Blockscout to connect?").
162+
Options(
163+
huh.NewOption("Network 1", "http://host.docker.internal:8545"),
164+
huh.NewOption("Network 2", "http://host.docker.internal:8550"),
165+
).
166+
Value(&f.BlockscoutRPCURL),
159167
),
160168
)
161169

framework/cmd/main.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func main() {
8080
Aliases: []string{"rm"},
8181
Usage: "Remove Docker containers and networks with 'framework=ctf' label",
8282
Action: func(c *cli.Context) error {
83-
err := rmTestContainers()
83+
err := removeTestContainers()
8484
if err != nil {
8585
return fmt.Errorf("failed to clean Docker resources: %w", err)
8686
}
@@ -114,31 +114,44 @@ func main() {
114114
Name: "blockscout",
115115
Aliases: []string{"bs"},
116116
Usage: "Controls local Blockscout stack",
117+
Flags: []cli.Flag{
118+
&cli.StringFlag{
119+
Name: "rpc",
120+
Aliases: []string{"r"},
121+
Usage: "RPC URL for blockchain node to index",
122+
Value: "http://host.docker.internal:8545",
123+
},
124+
},
117125
Subcommands: []*cli.Command{
118126
{
119127
Name: "up",
120128
Usage: "ctf bs up",
121129
Aliases: []string{"u"},
122130
Description: "Spins up Blockscout stack",
123-
Action: func(c *cli.Context) error { return blockscoutUp() },
131+
Action: func(c *cli.Context) error {
132+
return blockscoutUp(c.String("rpc"))
133+
},
124134
},
125135
{
126136
Name: "down",
127137
Usage: "ctf bs down",
128138
Aliases: []string{"d"},
129139
Description: "Removes Blockscout stack, wipes all Blockscout databases data",
130-
Action: func(c *cli.Context) error { return blockscoutDown() },
140+
Action: func(c *cli.Context) error {
141+
return blockscoutDown(c.String("rpc"))
142+
},
131143
},
132144
{
133145
Name: "reboot",
134146
Usage: "ctf bs reboot or ctf bs r",
135147
Aliases: []string{"r"},
136148
Description: "Reboots Blockscout stack",
137149
Action: func(c *cli.Context) error {
138-
if err := blockscoutDown(); err != nil {
150+
rpc := c.String("rpc")
151+
if err := blockscoutDown(rpc); err != nil {
139152
return err
140153
}
141-
return blockscoutUp()
154+
return blockscoutUp(rpc)
142155
},
143156
},
144157
},

0 commit comments

Comments
 (0)