Skip to content

Commit 702527f

Browse files
authored
Verify with Blockscout (#1413)
* example foundry contract * programmatic verification * docs * update regex in reload
1 parent 3f05a10 commit 702527f

File tree

21 files changed

+585
-9
lines changed

21 files changed

+585
-9
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [Creating your own components](./developing/developing_components.md)
1414
- [Fork Testing](./framework/fork.md)
1515
- [Quick Contracts Deployment](./framework/quick_deployment.md)
16+
- [Verifying Contracts](./framework/verify.md)
1617
- [NodeSet with External Blockchain]()
1718
- [CLI](./framework/cli.md)
1819
- [Configuration](./framework/configuration.md)

book/src/framework/observability/blockscout.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,4 @@ ctf bs -r http://host.docker.internal:8555 d
2525
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.
2626

2727
Otherwise, use `ctf bs r` each time you restart your test with a fresh docker environment.
28-
</div>
29-
30-
<div class="warning">
31-
32-
Blockscout integration is still WIP, for now Blockscout reads only one node that is on `:8545`, all our blockchain implementation expose this port by default.
33-
</div>
28+
</div>

book/src/framework/verify.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Verifying Contracts
2+
3+
Check out our [example](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/verify_test.go) of programmatically verifying contracts using `Blockscout` and `Foundry`. You'll need to provide:
4+
5+
- The path to your Foundry directory
6+
- The path to the contract
7+
- The contract name
8+
9+
```golang
10+
err := blockchain.VerifyContract(blockchainComponentOutput, c.Addresses[0].String(),
11+
"example_components/onchain",
12+
"src/Counter.sol",
13+
"Counter",
14+
)
15+
require.NoError(t, err)
16+
```

framework/.changeset/v0.3.1.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
- Use docker cmd instead of testcontainers
1+
- Use docker cmd for building instead of testcontainers-go
22
- Add "CHAINLINK_IMAGE" flag to override NodeSet image
3+
- Add Go wrapper for Blockscout verification (foundry)

framework/cmd/observability/blockscout/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ services:
3030
ETHEREUM_JSONRPC_VARIANT: 'geth'
3131
ETHEREUM_JSONRPC_HTTP_URL: ${BLOCKSCOUT_RPC_URL}
3232
ETHEREUM_JSONRPC_TRACE_URL: ${BLOCKSCOUT_RPC_URL}
33+
CHAIN_ID: ${BLOCKSCOUT_CHAIN_ID:-1337}
3334

3435
visualizer:
3536
extends:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package blockchain
2+
3+
import (
4+
"fmt"
5+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
6+
)
7+
8+
// VerifyContract wraps the forge verify-contract command.
9+
func VerifyContract(out *Output, address, foundryDir, contractFile, contractName string) error {
10+
args := []string{
11+
"verify-contract",
12+
"--rpc-url", out.Nodes[0].HostHTTPUrl,
13+
"--chain-id",
14+
out.ChainID,
15+
"--compiler-version=0.8.24",
16+
address,
17+
fmt.Sprintf("%s:%s", contractFile, contractName),
18+
"--verifier", "blockscout",
19+
"--verifier-url", "http://localhost/api/",
20+
}
21+
return framework.RunCommandDir(foundryDir, "forge", args...)
22+
}

framework/components/simple_node_set/reload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// UpgradeNodeSet updates nodes configuration TOML files
1010
// this API is discouraged, however, you can use it if nodes require restart or configuration updates, temporarily!
1111
func UpgradeNodeSet(in *Input, bc *blockchain.Output, wait time.Duration) (*Output, error) {
12-
_, err := chaos.ExecPumba("rm --volumes=false re2:node.*|ns-postgresql.*", wait)
12+
_, err := chaos.ExecPumba("rm --volumes=false re2:^node.*|ns-postgresql.*", wait)
1313
if err != nil {
1414
return nil, err
1515
}

framework/docker.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ func runCommand(name string, args ...string) error {
7777
return cmd.Run()
7878
}
7979

80+
// RunCommandDir executes a command in some directory and prints the output
81+
func RunCommandDir(dir, name string, args ...string) error {
82+
cmd := exec.Command(name, args...)
83+
cmd.Stdout = os.Stdout
84+
cmd.Stderr = os.Stderr
85+
if dir != "" {
86+
cmd.Dir = dir
87+
}
88+
return cmd.Run()
89+
}
90+
8091
// DockerClient wraps a Docker API client and provides convenience methods
8192
type DockerClient struct {
8293
cli *client.Client
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: test
2+
3+
on: workflow_dispatch
4+
5+
env:
6+
FOUNDRY_PROFILE: ci
7+
8+
jobs:
9+
check:
10+
strategy:
11+
fail-fast: true
12+
13+
name: Foundry project
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Install Foundry
21+
uses: foundry-rs/foundry-toolchain@v1
22+
with:
23+
version: nightly
24+
25+
- name: Run Forge build
26+
run: |
27+
forge --version
28+
forge build --sizes
29+
id: build
30+
31+
- name: Run Forge tests
32+
run: |
33+
forge test -vvv
34+
id: test
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env

0 commit comments

Comments
 (0)