Skip to content

simulators/ethereum/engine: Engine API Test Fixes #891

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 2 commits into from
Sep 27, 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
10 changes: 9 additions & 1 deletion simulators/ethereum/engine/suites/cancun/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1844,13 +1844,21 @@ func init() {
invalidDetectedOnSync := (invalidField == helper.InvalidBlobGasUsed ||
invalidField == helper.InvalidBlobCountGasUsed ||
invalidField == helper.InvalidVersionedHashes ||
invalidField == helper.InvalidVersionedHashesVersion)
invalidField == helper.InvalidVersionedHashesVersion ||
invalidField == helper.IncompleteVersionedHashes ||
invalidField == helper.ExtraVersionedHashes)

nilLatestValidHash := (invalidField == helper.InvalidVersionedHashes ||
invalidField == helper.InvalidVersionedHashesVersion ||
invalidField == helper.IncompleteVersionedHashes ||
invalidField == helper.ExtraVersionedHashes)

Tests = append(Tests, suite_engine.InvalidPayloadTestCase{
BaseSpec: onlyBlobTxsSpec,
InvalidField: invalidField,
Syncing: syncing,
InvalidDetectedOnSync: invalidDetectedOnSync,
NilLatestValidHash: nilLatestValidHash,
})
}
}
Expand Down
19 changes: 16 additions & 3 deletions simulators/ethereum/engine/suites/engine/invalid_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type InvalidPayloadTestCase struct {
EmptyTransactions bool
// If true, the payload can be detected to be invalid even when syncing
InvalidDetectedOnSync bool
// If true, latest valid hash can be nil for this test.
NilLatestValidHash bool
}

func (s InvalidPayloadTestCase) WithMainFork(fork config.Fork) test.Spec {
Expand Down Expand Up @@ -155,7 +157,9 @@ func (tc InvalidPayloadTestCase) Execute(t *test.Env) {
}
} else {
r.ExpectStatus(test.Invalid)
r.ExpectLatestValidHash(&alteredPayload.ParentHash)
if !(tc.NilLatestValidHash && r.Status.LatestValidHash == nil) {
r.ExpectLatestValidHash(&alteredPayload.ParentHash)
}
}

// Send the forkchoiceUpdated with a reference to the invalid payload.
Expand Down Expand Up @@ -218,7 +222,9 @@ func (tc InvalidPayloadTestCase) Execute(t *test.Env) {
} else {
// Otherwise the response should be INVALID.
q.ExpectStatus(test.Invalid)
q.ExpectLatestValidHash(&t.CLMock.LatestExecutedPayload.BlockHash)
if !(tc.NilLatestValidHash && r.Status.LatestValidHash == nil) {
q.ExpectLatestValidHash(&t.CLMock.LatestExecutedPayload.BlockHash)
}
}

// Try sending the fcU again, this time we should get the proper invalid response.
Expand Down Expand Up @@ -254,6 +260,11 @@ func (tc InvalidPayloadTestCase) Execute(t *test.Env) {
t.CLMock.ProduceSingleBlock(clmock.BlockProcessCallbacks{
// Run test after the new payload has been obtained
OnGetPayload: func() {
if t.CLMock.LatestPayloadBuilt.ParentHash == alteredPayload.BlockHash {
// In some instances the payload is indiscernible from the altered one because the
// difference lies in the new payload parameters, in this case skip this check.
return
}
followUpAlteredPayload, err := (&helper.CustomPayloadData{
ParentHash: &alteredPayload.BlockHash,
}).CustomizePayload(&t.CLMock.LatestPayloadBuilt)
Expand All @@ -271,7 +282,9 @@ func (tc InvalidPayloadTestCase) Execute(t *test.Env) {
if r.Status.Status == test.Accepted || r.Status.Status == test.Syncing {
r.ExpectLatestValidHash(nil)
} else if r.Status.Status == test.Invalid {
r.ExpectLatestValidHash(&alteredPayload.ParentHash)
if !(tc.NilLatestValidHash && r.Status.LatestValidHash == nil) {
r.ExpectLatestValidHash(&alteredPayload.ParentHash)
}
}
},
})
Expand Down
7 changes: 7 additions & 0 deletions simulators/ethereum/engine/suites/engine/misc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package suite_engine

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/hive/simulators/ethereum/engine/clmock"
"github.com/ethereum/hive/simulators/ethereum/engine/config"
Expand Down Expand Up @@ -28,6 +30,11 @@ func (s NonZeroPreMergeFork) GetForkConfig() *config.ForkConfig {
return nil
}
forkConfig.LondonNumber = common.Big1
// All post merge forks must happen at the same time as the latest fork
mainFork := s.GetMainFork()
if mainFork == config.Cancun {
forkConfig.ShanghaiTimestamp = new(big.Int).Set(forkConfig.CancunTimestamp)
}
return forkConfig
}

Expand Down