Skip to content

Commit 837eb71

Browse files
committed
Add test cases for engine api version methods
1 parent 692533a commit 837eb71

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

op-node/rollup/types_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,118 @@ func TestTimestampForBlock(t *testing.T) {
460460
}
461461

462462
}
463+
464+
func TestForkchoiceUpdatedVersion(t *testing.T) {
465+
config := randConfig()
466+
tests := []struct {
467+
name string
468+
canyonTime uint64
469+
ecotoneTime uint64
470+
attrs *eth.PayloadAttributes
471+
expectedMethod eth.EngineAPIMethod
472+
}{
473+
{
474+
name: "NoAttrs",
475+
canyonTime: 10,
476+
ecotoneTime: 20,
477+
attrs: nil,
478+
expectedMethod: eth.FCUV3,
479+
},
480+
{
481+
name: "BeforeCanyon",
482+
canyonTime: 10,
483+
ecotoneTime: 20,
484+
attrs: &eth.PayloadAttributes{Timestamp: 5},
485+
expectedMethod: eth.FCUV1,
486+
},
487+
{
488+
name: "Canyon",
489+
canyonTime: 10,
490+
ecotoneTime: 20,
491+
attrs: &eth.PayloadAttributes{Timestamp: 15},
492+
expectedMethod: eth.FCUV2,
493+
},
494+
{
495+
name: "Ecotone",
496+
canyonTime: 10,
497+
ecotoneTime: 20,
498+
attrs: &eth.PayloadAttributes{Timestamp: 25},
499+
expectedMethod: eth.FCUV3,
500+
},
501+
}
502+
503+
for _, test := range tests {
504+
test := test
505+
t.Run(fmt.Sprintf("TestForkchoiceUpdatedVersion_%s", test.name), func(t *testing.T) {
506+
config.CanyonTime = &test.canyonTime
507+
config.EcotoneTime = &test.ecotoneTime
508+
assert.Equal(t, config.ForkchoiceUpdatedVersion(test.attrs), test.expectedMethod)
509+
})
510+
}
511+
}
512+
513+
func TestNewPayloadVersion(t *testing.T) {
514+
config := randConfig()
515+
canyonTime := uint64(0)
516+
config.CanyonTime = &canyonTime
517+
tests := []struct {
518+
name string
519+
ecotoneTime uint64
520+
payloadTime uint64
521+
expectedMethod eth.EngineAPIMethod
522+
}{
523+
{
524+
name: "BeforeEcotone",
525+
ecotoneTime: 10,
526+
payloadTime: 5,
527+
expectedMethod: eth.NewPayloadV2,
528+
},
529+
{
530+
name: "Ecotone",
531+
ecotoneTime: 10,
532+
payloadTime: 15,
533+
expectedMethod: eth.NewPayloadV3,
534+
},
535+
}
536+
537+
for _, test := range tests {
538+
test := test
539+
t.Run(fmt.Sprintf("TestNewPayloadVersion_%s", test.name), func(t *testing.T) {
540+
config.EcotoneTime = &test.ecotoneTime
541+
assert.Equal(t, config.NewPayloadVersion(test.payloadTime), test.expectedMethod)
542+
})
543+
}
544+
}
545+
546+
func TestGetPayloadVersion(t *testing.T) {
547+
config := randConfig()
548+
canyonTime := uint64(0)
549+
config.CanyonTime = &canyonTime
550+
tests := []struct {
551+
name string
552+
ecotoneTime uint64
553+
payloadTime uint64
554+
expectedMethod eth.EngineAPIMethod
555+
}{
556+
{
557+
name: "BeforeEcotone",
558+
ecotoneTime: 10,
559+
payloadTime: 5,
560+
expectedMethod: eth.GetPayloadV2,
561+
},
562+
{
563+
name: "Ecotone",
564+
ecotoneTime: 10,
565+
payloadTime: 15,
566+
expectedMethod: eth.GetPayloadV3,
567+
},
568+
}
569+
570+
for _, test := range tests {
571+
test := test
572+
t.Run(fmt.Sprintf("TestGetPayloadVersion_%s", test.name), func(t *testing.T) {
573+
config.EcotoneTime = &test.ecotoneTime
574+
assert.Equal(t, config.GetPayloadVersion(test.payloadTime), test.expectedMethod)
575+
})
576+
}
577+
}

0 commit comments

Comments
 (0)