Skip to content

Commit a709592

Browse files
committed
simulators/ethereum/engine: fix versioning tests
1 parent 057bebf commit a709592

File tree

3 files changed

+23
-78
lines changed

3 files changed

+23
-78
lines changed

simulators/ethereum/engine/helper/customizer.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ type TimestampDeltaPayloadAttributesCustomizer struct {
137137
var _ PayloadAttributesCustomizer = (*TimestampDeltaPayloadAttributesCustomizer)(nil)
138138

139139
func (customData *TimestampDeltaPayloadAttributesCustomizer) GetPayloadAttributes(basePayloadAttributes *typ.PayloadAttributes) (*typ.PayloadAttributes, error) {
140-
customPayloadAttributes, err := customData.PayloadAttributesCustomizer.GetPayloadAttributes(basePayloadAttributes)
141-
if err != nil {
142-
return nil, err
140+
if customData.PayloadAttributesCustomizer != nil {
141+
var err error
142+
if basePayloadAttributes, err = customData.PayloadAttributesCustomizer.GetPayloadAttributes(basePayloadAttributes); err != nil {
143+
return nil, err
144+
}
143145
}
144-
customPayloadAttributes.Timestamp = uint64(int64(customPayloadAttributes.Timestamp) + customData.TimestampDelta)
145-
return customPayloadAttributes, nil
146+
basePayloadAttributes.Timestamp = uint64(int64(basePayloadAttributes.Timestamp) + customData.TimestampDelta)
147+
return basePayloadAttributes, nil
146148
}
147149

148150
// Customizer that makes no modifications to the forkchoice directive call.

simulators/ethereum/engine/suites/engine/tests.go

+16-17
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,29 @@ func init() {
115115
Tests = append(Tests,
116116
ForkchoiceUpdatedOnPayloadRequestTest{
117117
BaseSpec: test.BaseSpec{
118-
Name: "Early upgrade",
119-
ForkHeight: 2,
118+
Name: "Early upgrade",
119+
About: `
120+
Early upgrade of ForkchoiceUpdated when requesting a payload.
121+
The test sets the fork height to 1, and the block timestamp increments to 2
122+
seconds each block.
123+
CL Mock prepares the payload attributes for the first block, which should contain
124+
the attributes of the next fork.
125+
The test then reduces the timestamp by 1, but still uses the next forkchoice updated
126+
version, which should result in UNSUPPORTED_FORK_ERROR error.
127+
`,
128+
ForkHeight: 1,
129+
BlockTimestampIncrement: 2,
120130
},
121131
ForkchoiceUpdatedCustomizer: &helper.UpgradeForkchoiceUpdatedVersion{
122132
ForkchoiceUpdatedCustomizer: &helper.BaseForkchoiceUpdatedCustomizer{
133+
PayloadAttributesCustomizer: &helper.TimestampDeltaPayloadAttributesCustomizer{
134+
PayloadAttributesCustomizer: &helper.BasePayloadAttributesCustomizer{},
135+
TimestampDelta: -1,
136+
},
123137
ExpectedError: globals.UNSUPPORTED_FORK_ERROR,
124138
},
125139
},
126140
},
127-
/*
128-
TODO: This test is failing because the upgraded version of the ForkchoiceUpdated does not contain the
129-
expected fields of the following version.
130-
ForkchoiceUpdatedOnHeadBlockUpdateTest{
131-
BaseSpec: test.BaseSpec{
132-
Name: "Early upgrade",
133-
ForkHeight: 2,
134-
},
135-
ForkchoiceUpdatedCustomizer: &helper.UpgradeForkchoiceUpdatedVersion{
136-
ForkchoiceUpdatedCustomizer: &helper.BaseForkchoiceUpdatedCustomizer{
137-
ExpectedError: globals.UNSUPPORTED_FORK_ERROR,
138-
},
139-
},
140-
},
141-
*/
142141
)
143142

144143
// Payload Execution Tests

simulators/ethereum/engine/suites/engine/versioning.go

-56
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package suite_engine
22

33
import (
4-
api "github.com/ethereum/go-ethereum/beacon/engine"
54
"github.com/ethereum/hive/simulators/ethereum/engine/clmock"
65
"github.com/ethereum/hive/simulators/ethereum/engine/config"
76
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
@@ -74,58 +73,3 @@ func (tc ForkchoiceUpdatedOnPayloadRequestTest) Execute(t *test.Env) {
7473
},
7574
})
7675
}
77-
78-
// Test modifying the ForkchoiceUpdated version on HeadBlockHash update to the previous/upcoming
79-
// version when the timestamp payload attribute does not match the upgraded/downgraded version.
80-
type ForkchoiceUpdatedOnHeadBlockUpdateTest struct {
81-
test.BaseSpec
82-
helper.ForkchoiceUpdatedCustomizer
83-
}
84-
85-
func (s ForkchoiceUpdatedOnHeadBlockUpdateTest) WithMainFork(fork config.Fork) test.Spec {
86-
specCopy := s
87-
specCopy.MainFork = fork
88-
return specCopy
89-
}
90-
91-
func (tc ForkchoiceUpdatedOnHeadBlockUpdateTest) GetName() string {
92-
return "ForkchoiceUpdated Version on Head Set: " + tc.BaseSpec.GetName()
93-
}
94-
95-
func (tc ForkchoiceUpdatedOnHeadBlockUpdateTest) Execute(t *test.Env) {
96-
// Wait until TTD is reached by this client
97-
t.CLMock.WaitForTTD()
98-
99-
t.CLMock.ProduceSingleBlock(clmock.BlockProcessCallbacks{
100-
OnPayloadAttributesGenerated: func() {
101-
var (
102-
forkchoiceState *api.ForkchoiceStateV1 = &api.ForkchoiceStateV1{
103-
HeadBlockHash: t.CLMock.LatestPayloadBuilt.BlockHash,
104-
SafeBlockHash: t.CLMock.LatestForkchoice.SafeBlockHash,
105-
FinalizedBlockHash: t.CLMock.LatestForkchoice.FinalizedBlockHash,
106-
}
107-
expectedError *int
108-
expectedStatus test.PayloadStatus = test.Valid
109-
err error
110-
)
111-
tc.SetEngineAPIVersionResolver(t.ForkConfig)
112-
testEngine := t.TestEngine.WithEngineAPIVersionResolver(tc.ForkchoiceUpdatedCustomizer)
113-
expectedError, err = tc.GetExpectedError()
114-
if err != nil {
115-
t.Fatalf("FAIL: Error getting custom expected error: %v", err)
116-
}
117-
if tc.GetExpectInvalidStatus() {
118-
expectedStatus = test.Invalid
119-
}
120-
121-
r := testEngine.TestEngineForkchoiceUpdated(forkchoiceState, nil, t.CLMock.LatestPayloadBuilt.Timestamp)
122-
r.ExpectationDescription = tc.Expectation
123-
if expectedError != nil {
124-
r.ExpectErrorCode(*expectedError)
125-
} else {
126-
r.ExpectNoError()
127-
r.ExpectPayloadStatus(expectedStatus)
128-
}
129-
},
130-
})
131-
}

0 commit comments

Comments
 (0)