Skip to content

Commit 7068ab4

Browse files
authored
simulators/ethereum/engine: tests for getPayloadBodies*, exchangeCapabilities (#698)
Adds tests for engine_getPayloadBodiesByRangeV1, engine_getPayloadBodiesByHashV1 and engine_exchangeCapabilities.
1 parent fa8d62c commit 7068ab4

File tree

12 files changed

+741
-8
lines changed

12 files changed

+741
-8
lines changed

simulators/ethereum/engine/client/engine.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/ethereum/go-ethereum/core/types"
13+
14+
client_types "github.com/ethereum/hive/simulators/ethereum/engine/client/types"
1315
)
1416

1517
type Eth interface {
@@ -31,9 +33,13 @@ type Engine interface {
3133

3234
GetPayloadV1(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, error)
3335
GetPayloadV2(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, error)
36+
3437
NewPayloadV1(ctx context.Context, payload *api.ExecutableData) (api.PayloadStatusV1, error)
3538
NewPayloadV2(ctx context.Context, payload *api.ExecutableData) (api.PayloadStatusV1, error)
3639

40+
GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*client_types.ExecutionPayloadBodyV1, error)
41+
GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*client_types.ExecutionPayloadBodyV1, error)
42+
3743
LatestForkchoiceSent() (fcState *api.ForkchoiceStateV1, pAttributes *api.PayloadAttributes)
3844
LatestNewPayloadSent() (payload *api.ExecutableData)
3945

simulators/ethereum/engine/client/hive_rpc/hive_rpc.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/ethereum/go-ethereum/rpc"
2121
"github.com/ethereum/hive/hivesim"
2222
"github.com/ethereum/hive/simulators/ethereum/engine/client"
23+
client_types "github.com/ethereum/hive/simulators/ethereum/engine/client/types"
2324
"github.com/ethereum/hive/simulators/ethereum/engine/globals"
2425
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
2526
"github.com/golang-jwt/jwt/v4"
@@ -334,7 +335,7 @@ func (ec *HiveRPCEngineClient) GetPayload(ctx context.Context, version int, payl
334335
}
335336

336337
if version == 2 {
337-
var response api.ExecutableDataV2
338+
var response api.ExecutionPayloadEnvelope
338339
err = ec.c.CallContext(ctx, &response, rpcString, payloadId)
339340
if response.ExecutionPayload != nil {
340341
executableData = *response.ExecutionPayload
@@ -356,6 +357,32 @@ func (ec *HiveRPCEngineClient) GetPayloadV2(ctx context.Context, payloadId *api.
356357
return ec.GetPayload(ctx, 2, payloadId)
357358
}
358359

360+
func (ec *HiveRPCEngineClient) GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*client_types.ExecutionPayloadBodyV1, error) {
361+
var (
362+
result []*client_types.ExecutionPayloadBodyV1
363+
err error
364+
)
365+
if err = ec.PrepareDefaultAuthCallToken(); err != nil {
366+
return nil, err
367+
}
368+
369+
err = ec.c.CallContext(ctx, &result, "engine_getPayloadBodiesByRangeV1", start, count)
370+
return result, err
371+
}
372+
373+
func (ec *HiveRPCEngineClient) GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*client_types.ExecutionPayloadBodyV1, error) {
374+
var (
375+
result []*client_types.ExecutionPayloadBodyV1
376+
err error
377+
)
378+
if err = ec.PrepareDefaultAuthCallToken(); err != nil {
379+
return nil, err
380+
}
381+
382+
err = ec.c.CallContext(ctx, &result, "engine_getPayloadBodiesByHashV1", hashes)
383+
return result, err
384+
}
385+
359386
func (ec *HiveRPCEngineClient) NewPayload(ctx context.Context, version int, payload *api.ExecutableData) (api.PayloadStatusV1, error) {
360387
var result api.PayloadStatusV1
361388
if err := ec.PrepareDefaultAuthCallToken(); err != nil {
@@ -381,6 +408,15 @@ func (ec *HiveRPCEngineClient) ExchangeTransitionConfigurationV1(ctx context.Con
381408
return result, err
382409
}
383410

411+
func (ec *HiveRPCEngineClient) ExchangeCapabilities(ctx context.Context, clCapabilities []string) ([]string, error) {
412+
var result []string
413+
if err := ec.PrepareDefaultAuthCallToken(); err != nil {
414+
return result, err
415+
}
416+
err := ec.c.CallContext(ctx, &result, "engine_exchangeCapabilities", clCapabilities)
417+
return result, err
418+
}
419+
384420
func (ec *HiveRPCEngineClient) GetNextAccountNonce(testCtx context.Context, account common.Address) (uint64, error) {
385421
// First get the current head of the client where we will send the tx
386422
ctx, cancel := context.WithTimeout(testCtx, globals.RPCTimeout)

simulators/ethereum/engine/client/node/node.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/rpc"
3737
"github.com/ethereum/hive/hivesim"
3838
"github.com/ethereum/hive/simulators/ethereum/engine/client"
39+
client_types "github.com/ethereum/hive/simulators/ethereum/engine/client/types"
3940
"github.com/ethereum/hive/simulators/ethereum/engine/globals"
4041
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
4142
)
@@ -734,6 +735,14 @@ func (n *GethNode) GetPayloadV2(ctx context.Context, payloadId *beacon.PayloadID
734735
return *p.ExecutionPayload, p.BlockValue, err
735736
}
736737

738+
func (n *GethNode) GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*client_types.ExecutionPayloadBodyV1, error) {
739+
return nil, fmt.Errorf("not implemented")
740+
}
741+
742+
func (n *GethNode) GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*client_types.ExecutionPayloadBodyV1, error) {
743+
return nil, fmt.Errorf("not implemented")
744+
}
745+
737746
// Eth JSON RPC
738747
const (
739748
SafeBlockNumber = rpc.BlockNumber(-4) // This is not yet true

simulators/ethereum/engine/client/types/gen_epbv1.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package types
2+
3+
import (
4+
"github.com/ethereum/go-ethereum/common/hexutil"
5+
"github.com/ethereum/go-ethereum/core/types"
6+
)
7+
8+
//go:generate go run github.com/fjl/gencodec -type ExecutionPayloadBodyV1 -field-override executionPayloadBodyV1Marshaling -out gen_epbv1.go
9+
type ExecutionPayloadBodyV1 struct {
10+
Transactions [][]byte `json:"transactions" gencodec:"required"`
11+
Withdrawals []*types.Withdrawal `json:"withdrawals"`
12+
}
13+
14+
// JSON type overrides for executableData.
15+
type executionPayloadBodyV1Marshaling struct {
16+
Transactions []hexutil.Bytes
17+
}

simulators/ethereum/engine/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/ethereum/go-ethereum v1.10.26
77
github.com/ethereum/hive v0.0.0-20230124094404-5b561920e19b
88
github.com/golang-jwt/jwt/v4 v4.4.3
9+
golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e
910
)
1011

1112
require (
@@ -69,4 +70,4 @@ require (
6970
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
7071
)
7172

72-
replace github.com/ethereum/go-ethereum v1.10.26 => github.com/lightclient/go-ethereum v1.10.10-0.20230116085521-6ab6d738866f
73+
replace github.com/ethereum/go-ethereum v1.10.26 => github.com/ethereum/go-ethereum v1.10.24-0.20230127123926-a63875bf4d7f

simulators/ethereum/engine/go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ=
7676
github.com/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
7777
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
7878
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
79+
github.com/ethereum/go-ethereum v1.10.24-0.20230127123926-a63875bf4d7f h1:4zLYUPuCDwBfQSCY1QWJfVn9fmOFmX1D4GCnMC8UlU8=
80+
github.com/ethereum/go-ethereum v1.10.24-0.20230127123926-a63875bf4d7f/go.mod h1:C5Xij/C5W1rXkm7pCvr7p2HWUiVk6RmTF3EUvp8LXMY=
7981
github.com/ethereum/hive v0.0.0-20230124094404-5b561920e19b h1:TW8iKjNf7tZZkleHIGNG2wkawQC8BzGce++cxRw10lU=
8082
github.com/ethereum/hive v0.0.0-20230124094404-5b561920e19b/go.mod h1:pqToex2uV+Tg7bhBla/uvB3APKZ6FogJMMpow33nUIA=
8183
github.com/fjl/memsize v0.0.1 h1:+zhkb+dhUgx0/e+M8sF0QqiouvMQUiKR+QYvdxIOKcQ=
@@ -216,8 +218,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
216218
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
217219
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
218220
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
219-
github.com/lightclient/go-ethereum v1.10.10-0.20230116085521-6ab6d738866f h1:Pox2oxBYKWVEw2JUCyiEybqEIurSkq8VHjRp6s9jdf8=
220-
github.com/lightclient/go-ethereum v1.10.10-0.20230116085521-6ab6d738866f/go.mod h1:n7VlOgCwYheLB/mi+V8ni2yf8K2qM3N9WAmalxkhk+c=
221221
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
222222
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
223223
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
@@ -363,6 +363,8 @@ golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm0
363363
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
364364
golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
365365
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
366+
golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e h1:nEzRHNOazEST44vMvEwxGxnYGrzXEmxJmnti5mKSWTk=
367+
golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
366368
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
367369
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
368370
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

simulators/ethereum/engine/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
suite_auth "github.com/ethereum/hive/simulators/ethereum/engine/suites/auth"
1414
suite_engine "github.com/ethereum/hive/simulators/ethereum/engine/suites/engine"
15+
suite_ex_cap "github.com/ethereum/hive/simulators/ethereum/engine/suites/exchange_capabilities"
1516
suite_transition "github.com/ethereum/hive/simulators/ethereum/engine/suites/transition"
1617
suite_withdrawals "github.com/ethereum/hive/simulators/ethereum/engine/suites/withdrawals"
1718
)
@@ -34,6 +35,11 @@ func main() {
3435
Name: "engine-auth",
3536
Description: `
3637
Test Engine API authentication features.`[1:],
38+
}
39+
excap = hivesim.Suite{
40+
Name: "engine-exchange-capabilities",
41+
Description: `
42+
Test Engine API exchange capabilities.`[1:],
3743
}
3844
sync = hivesim.Suite{
3945
Name: "engine-sync",
@@ -52,13 +58,15 @@ func main() {
5258
addTestsToSuite(simulator, &engine, specToInterface(suite_engine.Tests), "full")
5359
addTestsToSuite(simulator, &transition, specToInterface(suite_transition.Tests), "full")
5460
addTestsToSuite(simulator, &auth, specToInterface(suite_auth.Tests), "full")
61+
addTestsToSuite(simulator, &excap, specToInterface(suite_ex_cap.Tests), "full")
5562
//suite_sync.AddSyncTestsToSuite(simulator, &sync, suite_sync.Tests)
5663
addTestsToSuite(simulator, &withdrawals, suite_withdrawals.Tests, "full")
5764

5865
// Mark suites for execution
5966
hivesim.MustRunSuite(simulator, engine)
6067
hivesim.MustRunSuite(simulator, transition)
6168
hivesim.MustRunSuite(simulator, auth)
69+
hivesim.MustRunSuite(simulator, excap)
6270
hivesim.MustRunSuite(simulator, sync)
6371
hivesim.MustRunSuite(simulator, withdrawals)
6472
}
@@ -118,6 +126,7 @@ func addTestsToSuite(sim *hivesim.Simulation, suite *hivesim.Suite, tests []test
118126
delete(newParams, "HIVE_CLIQUE_PRIVATEKEY")
119127
delete(newParams, "HIVE_CLIQUE_PERIOD")
120128
delete(newParams, "HIVE_MINER")
129+
newParams = newParams.Set("HIVE_POST_MERGE_GENESIS", "true")
121130
}
122131

123132
if clientTypes, err := sim.ClientTypes(); err == nil {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package suite_exchange_capabilities
2+
3+
import (
4+
"github.com/ethereum/hive/simulators/ethereum/engine/test"
5+
"golang.org/x/exp/slices"
6+
)
7+
8+
var Tests = []test.Spec{
9+
{
10+
Name: "Exchange Capabilities",
11+
Run: exCapTests,
12+
},
13+
}
14+
15+
var minimalSetExpectedSupportedELCapabilities = []string{
16+
"engine_newPayloadV1",
17+
"engine_newPayloadV2",
18+
"engine_forkchoiceUpdatedV1",
19+
"engine_forkchoiceUpdatedV2",
20+
"engine_getPayloadV1",
21+
"engine_getPayloadV2",
22+
// "engine_getPayloadBodiesByRangeV1",
23+
}
24+
25+
func exCapTests(t *test.Env) {
26+
if returnedCapabilities, err := t.HiveEngine.ExchangeCapabilities(t.TestContext, minimalSetExpectedSupportedELCapabilities); err != nil {
27+
t.Fatalf("FAIL (%s): Unable request capabilities: %v", t.TestName, err)
28+
} else {
29+
for _, cap := range minimalSetExpectedSupportedELCapabilities {
30+
if !slices.Contains(returnedCapabilities, cap) {
31+
t.Fatalf("FAIL (%s): Expected capability (%s) not found", t.TestName, cap)
32+
}
33+
}
34+
}
35+
}

simulators/ethereum/engine/suites/withdrawals/README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,28 @@ This test suite verifies behavior of the Engine API on each client after the Sha
151151
- Verify that `TxB` returns error on `eth_sendRawTransaction` and also should be absent from the transaction pool of the client
152152
- Request a new payload from the client and verify that the payload built only includes `TxA`, and `TxB` is not included, nor the contract it could create is present in the `stateRoot`.
153153
- Create a modified payload where `TxA` is replaced by `TxB` and send using `engine_newPayloadV2`
154-
- Verify that `engine_newPayloadV2` returns `INVALID` nad `latestValidHash` points to the latest valid payload in the canonical chain.
154+
- Verify that `engine_newPayloadV2` returns `INVALID` nad `latestValidHash` points to the latest valid payload in the canonical chain.
155+
156+
## GetPayloadBodies Tests
157+
158+
- Payload Bodies By Range - Shanghai Fork on Block 16 - 16 Withdrawal Blocks
159+
- Launch client `A` and create a canonical chain consisting of 32 blocks, where the first shanghai block is number 17
160+
- Payloads produced of the following characteristics
161+
- [x] 16 Transactions, 16 Withdrawals
162+
- [x] 0 Transactions, 0 Withdrawals
163+
- Make multiple requests to obtain the payload bodies from the canonical chain (see `./tests.go` for full list).
164+
- Verify that:
165+
- Payload bodies of blocks before the Shanghai fork contain `withdrawals==null`
166+
- All transactions and withdrawals are in the correct format and order.
167+
- Requested payload bodies past the highest known block are ignored and absent from the returned list
168+
169+
- Payload Bodies By Hash - Shanghai Fork on Block 16 - 16 Withdrawal Blocks
170+
- Launch client `A` and create a canonical chain consisting of 32 blocks, where the first shanghai block is number 17
171+
- Payloads produced of the following characteristics
172+
- [x] 16 Transactions, 16 Withdrawals
173+
- [x] 0 Transactions, 0 Withdrawals
174+
- Make multiple requests to obtain the payload bodies from the canonical chain (see `./tests.go` for full list).
175+
- Verify that:
176+
- Payload bodies of blocks before the Shanghai fork contain `withdrawals==null`
177+
- All transactions and withdrawals are in the correct format and order.
178+
- Requested payload bodies of unknown hashes are returned as null in the returned list

0 commit comments

Comments
 (0)