Skip to content

Commit

Permalink
simulators/ethereum/engine: Engine API Test Fixes (ethereum#891)
Browse files Browse the repository at this point in the history
* simulators/ethereum/engine: fix non-zero pre-merge fork test

* simulators/ethereum/engine: fix invalid versioned hashes tests
  • Loading branch information
marioevz authored and Eikix committed Mar 1, 2024
1 parent 4940de8 commit aea0139
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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

0 comments on commit aea0139

Please sign in to comment.