Skip to content

Commit

Permalink
simulators/ethereum/engine: fix versioning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Sep 28, 2023
1 parent a2f657c commit 01d1559
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 78 deletions.
12 changes: 7 additions & 5 deletions simulators/ethereum/engine/helper/customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ type TimestampDeltaPayloadAttributesCustomizer struct {
var _ PayloadAttributesCustomizer = (*TimestampDeltaPayloadAttributesCustomizer)(nil)

func (customData *TimestampDeltaPayloadAttributesCustomizer) GetPayloadAttributes(basePayloadAttributes *typ.PayloadAttributes) (*typ.PayloadAttributes, error) {
customPayloadAttributes, err := customData.PayloadAttributesCustomizer.GetPayloadAttributes(basePayloadAttributes)
if err != nil {
return nil, err
if customData.PayloadAttributesCustomizer != nil {
var err error
if basePayloadAttributes, err = customData.PayloadAttributesCustomizer.GetPayloadAttributes(basePayloadAttributes); err != nil {
return nil, err
}
}
customPayloadAttributes.Timestamp = uint64(int64(customPayloadAttributes.Timestamp) + customData.TimestampDelta)
return customPayloadAttributes, nil
basePayloadAttributes.Timestamp = uint64(int64(basePayloadAttributes.Timestamp) + customData.TimestampDelta)
return basePayloadAttributes, nil
}

// Customizer that makes no modifications to the forkchoice directive call.
Expand Down
33 changes: 16 additions & 17 deletions simulators/ethereum/engine/suites/engine/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,29 @@ func init() {
Tests = append(Tests,
ForkchoiceUpdatedOnPayloadRequestTest{
BaseSpec: test.BaseSpec{
Name: "Early upgrade",
ForkHeight: 2,
Name: "Early upgrade",
About: `
Early upgrade of ForkchoiceUpdated when requesting a payload.
The test sets the fork height to 1, and the block timestamp increments to 2
seconds each block.
CL Mock prepares the payload attributes for the first block, which should contain
the attributes of the next fork.
The test then reduces the timestamp by 1, but still uses the next forkchoice updated
version, which should result in UNSUPPORTED_FORK_ERROR error.
`,
ForkHeight: 1,
BlockTimestampIncrement: 2,
},
ForkchoiceUpdatedCustomizer: &helper.UpgradeForkchoiceUpdatedVersion{
ForkchoiceUpdatedCustomizer: &helper.BaseForkchoiceUpdatedCustomizer{
PayloadAttributesCustomizer: &helper.TimestampDeltaPayloadAttributesCustomizer{
PayloadAttributesCustomizer: &helper.BasePayloadAttributesCustomizer{},
TimestampDelta: -1,
},
ExpectedError: globals.UNSUPPORTED_FORK_ERROR,
},
},
},
/*
TODO: This test is failing because the upgraded version of the ForkchoiceUpdated does not contain the
expected fields of the following version.
ForkchoiceUpdatedOnHeadBlockUpdateTest{
BaseSpec: test.BaseSpec{
Name: "Early upgrade",
ForkHeight: 2,
},
ForkchoiceUpdatedCustomizer: &helper.UpgradeForkchoiceUpdatedVersion{
ForkchoiceUpdatedCustomizer: &helper.BaseForkchoiceUpdatedCustomizer{
ExpectedError: globals.UNSUPPORTED_FORK_ERROR,
},
},
},
*/
)

// Payload Execution Tests
Expand Down
56 changes: 0 additions & 56 deletions simulators/ethereum/engine/suites/engine/versioning.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package suite_engine

import (
api "github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/hive/simulators/ethereum/engine/clmock"
"github.com/ethereum/hive/simulators/ethereum/engine/config"
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
Expand Down Expand Up @@ -74,58 +73,3 @@ func (tc ForkchoiceUpdatedOnPayloadRequestTest) Execute(t *test.Env) {
},
})
}

// Test modifying the ForkchoiceUpdated version on HeadBlockHash update to the previous/upcoming
// version when the timestamp payload attribute does not match the upgraded/downgraded version.
type ForkchoiceUpdatedOnHeadBlockUpdateTest struct {
test.BaseSpec
helper.ForkchoiceUpdatedCustomizer
}

func (s ForkchoiceUpdatedOnHeadBlockUpdateTest) WithMainFork(fork config.Fork) test.Spec {
specCopy := s
specCopy.MainFork = fork
return specCopy
}

func (tc ForkchoiceUpdatedOnHeadBlockUpdateTest) GetName() string {
return "ForkchoiceUpdated Version on Head Set: " + tc.BaseSpec.GetName()
}

func (tc ForkchoiceUpdatedOnHeadBlockUpdateTest) Execute(t *test.Env) {
// Wait until TTD is reached by this client
t.CLMock.WaitForTTD()

t.CLMock.ProduceSingleBlock(clmock.BlockProcessCallbacks{
OnPayloadAttributesGenerated: func() {
var (
forkchoiceState *api.ForkchoiceStateV1 = &api.ForkchoiceStateV1{
HeadBlockHash: t.CLMock.LatestPayloadBuilt.BlockHash,
SafeBlockHash: t.CLMock.LatestForkchoice.SafeBlockHash,
FinalizedBlockHash: t.CLMock.LatestForkchoice.FinalizedBlockHash,
}
expectedError *int
expectedStatus test.PayloadStatus = test.Valid
err error
)
tc.SetEngineAPIVersionResolver(t.ForkConfig)
testEngine := t.TestEngine.WithEngineAPIVersionResolver(tc.ForkchoiceUpdatedCustomizer)
expectedError, err = tc.GetExpectedError()
if err != nil {
t.Fatalf("FAIL: Error getting custom expected error: %v", err)
}
if tc.GetExpectInvalidStatus() {
expectedStatus = test.Invalid
}

r := testEngine.TestEngineForkchoiceUpdated(forkchoiceState, nil, t.CLMock.LatestPayloadBuilt.Timestamp)
r.ExpectationDescription = tc.Expectation
if expectedError != nil {
r.ExpectErrorCode(*expectedError)
} else {
r.ExpectNoError()
r.ExpectPayloadStatus(expectedStatus)
}
},
})
}

0 comments on commit 01d1559

Please sign in to comment.