Skip to content

Commit

Permalink
simulators/ethereum/rpc-compat: send forkchoiceUpdated to client (eth…
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl authored and Eikix committed Mar 1, 2024
1 parent 6a3b174 commit a9adf04
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
9 changes: 7 additions & 2 deletions simulators/ethereum/rpc-compat/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/ethereum/hive/simulators/ethereum/rpc-compat
go 1.18

require (
github.com/ethereum/hive v0.0.0-20231031133732-dcd7ddb75960
github.com/ethereum/go-ethereum v1.13.5-0.20231031113925-bc42e88415d3
github.com/ethereum/hive v0.0.0-20240131232337-d38a51d4e475
github.com/yudai/gojsondiff v1.0.0
)

Expand All @@ -12,12 +13,15 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/ethereum/go-ethereum v1.13.5-0.20231031113925-bc42e88415d3 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/lithammer/dedent v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
Expand All @@ -31,4 +35,5 @@ require (
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/inconshreveable/log15.v2 v2.0.0-20200109203555-b30bc20e4fd1 // indirect
)
13 changes: 11 additions & 2 deletions simulators/ethereum/rpc-compat/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc=
github.com/ethereum/go-ethereum v1.13.5-0.20231031113925-bc42e88415d3 h1:i4TE0DmzMYcr2IiCdlTGGk+7Q/EzXvBKbbG4uRxMjJ0=
github.com/ethereum/go-ethereum v1.13.5-0.20231031113925-bc42e88415d3/go.mod h1:yMTu38GSuyxaYzQMViqNmQ1s3cE84abZexQmTgenWk0=
github.com/ethereum/hive v0.0.0-20231031133732-dcd7ddb75960 h1:7H9z2o/KImWQ/1PACU3ewsSFNxT/lzwYRnwit2YFqMg=
github.com/ethereum/hive v0.0.0-20231031133732-dcd7ddb75960/go.mod h1:sV7LrFBlEii71kI9udVbUVj7SXIifZ2VzFjQ8S6rZns=
github.com/ethereum/hive v0.0.0-20240131232337-d38a51d4e475 h1:IlQwBa8MmXq/pfdDbzCwYYqf3PVEXIvI6xkf3ZB8p4E=
github.com/ethereum/hive v0.0.0-20240131232337-d38a51d4e475/go.mod h1:D0RJuJaAolOejqq/n0YoX7VbPzkooLHwCSoaQn2z6xY=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
Expand All @@ -27,6 +27,8 @@ github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiU
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
Expand Down Expand Up @@ -54,8 +56,13 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lithammer/dedent v1.1.0 h1:VNzHMVCBNG1j0fh3OrsFRkVUwStdDArbgBWoPAffktY=
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down Expand Up @@ -136,6 +143,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
Expand Down Expand Up @@ -169,6 +177,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20200109203555-b30bc20e4fd1 h1:iiHuQZCNgYPmFQxd3BBN/Nc5+dAwzZuq5y40s20oQw0=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20200109203555-b30bc20e4fd1/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
74 changes: 45 additions & 29 deletions simulators/ethereum/rpc-compat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func main() {
panic(err)
}

// Run the test suite.
suite := hivesim.Suite{
Name: "rpc-compat",
Description: `
Expand All @@ -53,6 +54,7 @@ conformance with the execution API specification.`[1:],
Parameters: clientEnv,
Files: files,
Run: func(t *hivesim.T, c *hivesim.Client) {
sendForkchoiceUpdated(t, c)
runAllTests(t, c, c.Type)
},
AlwaysRun: true,
Expand Down Expand Up @@ -156,6 +158,49 @@ func postHttp(c *http.Client, url string, d []byte) ([]byte, error) {
return io.ReadAll(resp.Body)
}

// loadTests walks the given directory looking for *.io files to load.
func loadTests(t *hivesim.T, root string, re *regexp.Regexp) []test {
tests := make([]test, 0)
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
t.Logf("unable to walk path: %s", err)
return err
}
if info.IsDir() {
return nil
}
if fname := info.Name(); !strings.HasSuffix(fname, ".io") {
return nil
}
pathname := strings.TrimSuffix(strings.TrimPrefix(path, root), ".io")
if !re.MatchString(pathname) {
fmt.Println("skip", pathname)
return nil // skip
}
data, err := os.ReadFile(path)
if err != nil {
return err
}
tests = append(tests, test{strings.TrimLeft(pathname, "/"), data})
return nil
})
return tests
}

func sendForkchoiceUpdated(t *hivesim.T, client *hivesim.Client) {
var request struct {
Method string
Params []any
}
if err := common.LoadJSON("tests/headfcu.json", &request); err != nil {
t.Fatal("error loading forkchoiceUpdated:", err)
}
err := client.EngineAPI().Call(nil, request.Method, request.Params...)
if err != nil {
t.Fatal("client rejected forkchoiceUpdated:", err)
}
}

// loggingRoundTrip writes requests and responses to the test log.
type loggingRoundTrip struct {
t *hivesim.T
Expand Down Expand Up @@ -190,32 +235,3 @@ func (rt *loggingRoundTrip) RoundTrip(req *http.Request) (*http.Response, error)
rt.t.Logf("<< %s", bytes.TrimSpace(respBytes))
return &respCopy, nil
}

// loadTests walks the given directory looking for *.io files to load.
func loadTests(t *hivesim.T, root string, re *regexp.Regexp) []test {
tests := make([]test, 0)
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
t.Logf("unable to walk path: %s", err)
return err
}
if info.IsDir() {
return nil
}
if fname := info.Name(); !strings.HasSuffix(fname, ".io") {
return nil
}
pathname := strings.TrimSuffix(strings.TrimPrefix(path, root), ".io")
if !re.MatchString(pathname) {
fmt.Println("skip", pathname)
return nil // skip
}
data, err := os.ReadFile(path)
if err != nil {
return err
}
tests = append(tests, test{strings.TrimLeft(pathname, "/"), data})
return nil
})
return tests
}

0 comments on commit a9adf04

Please sign in to comment.