Skip to content

simulators/devp2p: add support for new eth tests #942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions simulators/devp2p/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# This simulator runs devp2p protocol tests.

FROM golang:1-alpine as builder
RUN apk add --update git gcc musl-dev linux-headers

# Build devp2p tool.
FROM golang:1-alpine as geth-builder
RUN apk add --update git gcc musl-dev linux-headers
RUN git clone --depth 1 https://github.com/ethereum/go-ethereum.git /go-ethereum
WORKDIR /go-ethereum
RUN go build -v ./cmd/devp2p

# Build the simulator executable.
ADD . /source
FROM golang:1-alpine as sim-builder
RUN apk add --update git gcc musl-dev linux-headers
WORKDIR /source
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -v -o devp2p-simulator

# Build the simulation run container.
FROM alpine:latest
ADD . /source
WORKDIR /source
COPY --from=builder /go-ethereum/devp2p .
COPY --from=builder /source/devp2p-simulator .
COPY --from=geth-builder /go-ethereum/devp2p ./devp2p
COPY --from=geth-builder /go-ethereum/cmd/devp2p/internal/ethtest/testdata /testchain
COPY --from=sim-builder /source/devp2p-simulator .
ENTRYPOINT ["./devp2p-simulator"]
75 changes: 47 additions & 28 deletions simulators/devp2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/shogo82148/go-tap"
)

// Location of the test chain files. They are copied from
// go-ethereum/cmd/devp2p/internal/ethtest/testdata by the simulator dockerfile.
const testChainDir = "/testchain"

func main() {
discv4 := hivesim.Suite{
Name: "discv4",
Expand Down Expand Up @@ -72,6 +76,7 @@ func main() {
},
}

forkenv := loadTestChainConfig()
eth := hivesim.Suite{
Name: "eth",
Description: "This suite tests a client's ability to accurately respond to basic eth protocol messages.",
Expand All @@ -81,18 +86,10 @@ func main() {
Name: "client launch",
Description: `This test launches the client and runs the test tool.
Results from the test tool are reported as individual sub-tests.`,
Parameters: hivesim.Params{
"HIVE_NETWORK_ID": "19763",
"HIVE_CHAIN_ID": "19763",
"HIVE_FORK_HOMESTEAD": "0",
"HIVE_FORK_TANGERINE": "0",
"HIVE_FORK_SPURIOUS": "0",
"HIVE_FORK_BYZANTIUM": "0",
"HIVE_LOGLEVEL": "4",
},
Parameters: forkenv,
Files: map[string]string{
"genesis.json": "./init/genesis.json",
"chain.rlp": "./init/halfchain.rlp",
"genesis.json": testChainDir + "/genesis.json",
"chain.rlp": testChainDir + "/chain.rlp",
},
AlwaysRun: true,
Run: runEthTest,
Expand All @@ -109,18 +106,10 @@ Results from the test tool are reported as individual sub-tests.`,
Name: "client launch",
Description: `This test launches the client and runs the test tool.
Results from the test tool are reported as individual sub-tests.`,
Parameters: hivesim.Params{
"HIVE_NETWORK_ID": "19763",
"HIVE_CHAIN_ID": "19763",
"HIVE_FORK_HOMESTEAD": "0",
"HIVE_FORK_TANGERINE": "0",
"HIVE_FORK_SPURIOUS": "0",
"HIVE_FORK_BYZANTIUM": "0",
"HIVE_LOGLEVEL": "4",
},
Parameters: forkenv,
Files: map[string]string{
"genesis.json": "./init/genesis.json",
"chain.rlp": "./init/halfchain.rlp",
"genesis.json": testChainDir + "/genesis.json",
"chain.rlp": testChainDir + "/chain.rlp",
},
AlwaysRun: true,
Run: runSnapTest,
Expand All @@ -131,13 +120,33 @@ Results from the test tool are reported as individual sub-tests.`,
hivesim.MustRun(hivesim.New(), discv4, discv5, eth, snap)
}

func loadTestChainConfig() hivesim.Params {
content, err := os.ReadFile(testChainDir + "/forkenv.json")
if err != nil {
panic(err)
}
var p hivesim.Params
if err := json.Unmarshal(content, &p); err != nil {
panic(err)
}
return p
}

func runEthTest(t *hivesim.T, c *hivesim.Client) {
enode, err := c.EnodeURL()
if err != nil {
t.Fatal(err)
}

_, pattern := t.Sim.TestPattern()
cmd := exec.Command("./devp2p", "rlpx", "eth-test", "--run", pattern, "--tap", enode, "./init/fullchain.rlp", "./init/genesis.json")
cmd := exec.Command("./devp2p", "rlpx", "eth-test",
"--tap",
"--run", pattern,
"--node", enode,
"--chain", testChainDir,
"--engineapi", fmt.Sprintf("http://%s:8551", c.IP),
"--jwtsecret", "0x7365637265747365637265747365637265747365637265747365637265747365",
)
if err := runTAP(t, c.Type, cmd); err != nil {
t.Fatal(err)
}
Expand All @@ -148,8 +157,16 @@ func runSnapTest(t *hivesim.T, c *hivesim.Client) {
if err != nil {
t.Fatal(err)
}

_, pattern := t.Sim.TestPattern()
cmd := exec.Command("./devp2p", "rlpx", "snap-test", "--run", pattern, "--tap", enode, "./init/fullchain.rlp", "./init/genesis.json")
cmd := exec.Command("./devp2p", "rlpx", "snap-test",
"--tap",
"--run", pattern,
"--node", enode,
"--chain", testChainDir,
"--engineapi", fmt.Sprintf("http://%s:8551", c.IP),
"--jwtsecret", "0x7365637265747365637265747365637265747365637265747365637265747365",
)
if err := runTAP(t, c.Type, cmd); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -256,14 +273,15 @@ func reportTAP(t *hivesim.T, clientName string, output io.Reader) error {
if err != nil {
return fmt.Errorf("error parsing TAP: %v", err)
}
// Forward results to hive.
for {
test, err := parser.Next()
if err == io.EOF {
return nil
} else if err != nil {
if test == nil {
if err == io.EOF {
return nil
}
return err
}
// Forward result to hive.
name := fmt.Sprintf("%s (%s)", test.Description, clientName)
testID, err := t.Sim.StartTest(t.SuiteID, name, "")
if err != nil {
Expand All @@ -272,6 +290,7 @@ func reportTAP(t *hivesim.T, clientName string, output io.Reader) error {
result := hivesim.TestResult{Pass: test.Ok, Details: test.Diagnostic}
t.Sim.EndTest(t.SuiteID, testID, result)
}
return nil
}

func getBeaconENR(c *hivesim.Client) (string, error) {
Expand Down