Skip to content

Commit 579fd64

Browse files
committed
simulators/ethereum/engine: Test NewPayload Versions
1 parent 6874e3b commit 579fd64

File tree

2 files changed

+115
-10
lines changed

2 files changed

+115
-10
lines changed

simulators/ethereum/engine/suites/blobs/steps.go

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ type NewPayloads struct {
128128
VersionedHashes *VersionedHashes
129129
// Extra modifications on NewPayload to potentially generate an invalid payload
130130
PayloadCustomizer helper.PayloadCustomizer
131+
// Version to use to call NewPayload
132+
Version uint64
133+
// Expected responses on the NewPayload call
134+
ExpectedError *int
135+
ExpectedStatus test.PayloadStatus
131136
}
132137

133138
type VersionedHashes struct {
@@ -374,13 +379,22 @@ func (step NewPayloads) Execute(t *BlobTestContext) error {
374379
t.CLMock.ProduceSingleBlock(clmock.BlockProcessCallbacks{
375380
OnGetPayload: func() {
376381
// Get the latest blob bundle
377-
blobBundle := t.CLMock.LatestBlobBundle
382+
var (
383+
blobBundle = t.CLMock.LatestBlobBundle
384+
payload = &t.CLMock.LatestPayloadBuilt
385+
)
386+
387+
if t.Env.Genesis.Config.CancunTime == nil {
388+
panic("CancunTime is nil")
389+
}
390+
if payload.Timestamp < *t.Env.Genesis.Config.CancunTime {
391+
// Nothing to do
392+
return
393+
}
378394
if blobBundle == nil {
379395
t.Fatalf("FAIL: Error getting blobs bundle (payload %d/%d): %v", p+1, payloadCount, blobBundle)
380396
}
381397

382-
payload := &t.CLMock.LatestPayloadBuilt
383-
384398
_, blobDataInPayload, err := GetBlobDataInPayload(t.TestBlobTxPool, payload)
385399
if err != nil {
386400
t.Fatalf("FAIL: Error retrieving blob bundle (payload %d/%d): %v", p+1, payloadCount, err)
@@ -391,25 +405,57 @@ func (step NewPayloads) Execute(t *BlobTestContext) error {
391405
}
392406
},
393407
OnNewPayloadBroadcast: func() {
408+
// Send a test NewPayload directive with either a modified payload or modifed versioned hashes
409+
var (
410+
payload *engine.ExecutableData
411+
versionedHashes []common.Hash
412+
err error
413+
)
394414
if step.VersionedHashes != nil {
395415
// Send a new payload with the modified versioned hashes
396-
versionedHashes, err := step.VersionedHashes.VersionedHashes()
416+
versionedHashes, err = step.VersionedHashes.VersionedHashes()
397417
if err != nil {
398418
t.Fatalf("FAIL: Error getting modified versioned hashes (payload %d/%d): %v", p+1, payloadCount, err)
399419
}
400420
r := t.TestEngine.TestEngineNewPayloadV3(&t.CLMock.LatestPayloadBuilt, versionedHashes)
401421
// All tests that modify the versioned hashes expect an
402422
// `INVALID` response, even if the client is out of sync
403423
r.ExpectStatus(test.Invalid)
424+
} else {
425+
if t.CLMock.LatestBlobBundle != nil {
426+
versionedHashes, err = t.CLMock.LatestBlobBundle.VersionedHashes(BLOB_COMMITMENT_VERSION_KZG)
427+
if err != nil {
428+
t.Fatalf("FAIL: Error getting versioned hashes (payload %d/%d): %v", p+1, payloadCount, err)
429+
}
430+
}
404431
}
432+
405433
if step.PayloadCustomizer != nil {
406434
// Send a custom new payload
407-
customPayload, err := step.PayloadCustomizer.CustomizePayload(&t.CLMock.LatestPayloadBuilt)
435+
payload, err = step.PayloadCustomizer.CustomizePayload(&t.CLMock.LatestPayloadBuilt)
408436
if err != nil {
409437
t.Fatalf("FAIL: Error customizing payload (payload %d/%d): %v", p+1, payloadCount, err)
410438
}
411-
r := t.TestEngine.TestEngineNewPayloadV3(customPayload, nil)
412-
r.ExpectStatus(test.Invalid)
439+
} else {
440+
payload = &t.CLMock.LatestPayloadBuilt
441+
}
442+
443+
var r *test.NewPayloadResponseExpectObject
444+
445+
if step.Version == 0 || step.Version == 3 {
446+
r = t.TestEngine.TestEngineNewPayloadV3(payload, versionedHashes)
447+
} else if step.Version == 2 {
448+
r = t.TestEngine.TestEngineNewPayloadV2(payload)
449+
} else {
450+
t.Fatalf("FAIL: Unknown version %d", step.Version)
451+
}
452+
if step.ExpectedError != nil {
453+
r.ExpectErrorCode(*step.ExpectedError)
454+
} else {
455+
r.ExpectNoError()
456+
if step.ExpectedStatus != "" {
457+
r.ExpectStatus(step.ExpectedStatus)
458+
}
413459
}
414460
},
415461
OnForkchoiceBroadcast: func() {

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

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func pUint64(v uint64) *uint64 {
3838
return &v
3939
}
4040

41+
func pInt(v int) *int {
42+
return &v
43+
}
44+
4145
// Execution specification reference:
4246
// https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md
4347

@@ -506,6 +510,52 @@ var Tests = []test.SpecInterface{
506510
},
507511
},
508512
},
513+
// NewPayload Version Negative Tests
514+
&BlobsBaseSpec{
515+
516+
Spec: test.Spec{
517+
Name: "NewPayloadV2 After Cancun",
518+
About: `
519+
Test sending NewPayloadV2 after cancun fork, which
520+
should result in error.
521+
`,
522+
},
523+
524+
// We fork on genesis
525+
CancunForkHeight: 0,
526+
527+
TestSequence: TestSequence{
528+
// Send multiple blob transactions with the same nonce.
529+
NewPayloads{
530+
ExpectedIncludedBlobCount: 0,
531+
Version: 2,
532+
ExpectedError: pInt(-38005),
533+
},
534+
},
535+
},
536+
&BlobsBaseSpec{
537+
538+
Spec: test.Spec{
539+
Name: "NewPayloadV3 Before Cancun",
540+
About: `
541+
Test sending NewPayloadV3 before cancun fork, which
542+
should result in error.
543+
`,
544+
},
545+
546+
// We fork on genesis
547+
CancunForkHeight: 2,
548+
549+
TestSequence: TestSequence{
550+
// Send multiple blob transactions with the same nonce.
551+
NewPayloads{
552+
ExpectedIncludedBlobCount: 0,
553+
Version: 3,
554+
ExpectedError: pInt(-38005),
555+
},
556+
},
557+
},
558+
509559
// Test versioned hashes in Engine API NewPayloadV3
510560
&BlobsBaseSpec{
511561

@@ -527,6 +577,7 @@ var Tests = []test.SpecInterface{
527577
VersionedHashes: &VersionedHashes{
528578
Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK-1),
529579
},
580+
ExpectedStatus: test.Invalid,
530581
},
531582
},
532583
},
@@ -552,6 +603,7 @@ var Tests = []test.SpecInterface{
552603
VersionedHashes: &VersionedHashes{
553604
Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK+1),
554605
},
606+
ExpectedStatus: test.Invalid,
555607
},
556608
},
557609
},
@@ -575,6 +627,7 @@ var Tests = []test.SpecInterface{
575627
VersionedHashes: &VersionedHashes{
576628
Blobs: helper.GetBlobListByIndex(helper.BlobID(TARGET_BLOBS_PER_BLOCK-1), 0),
577629
},
630+
ExpectedStatus: test.Invalid,
578631
},
579632
},
580633
},
@@ -598,6 +651,7 @@ var Tests = []test.SpecInterface{
598651
VersionedHashes: &VersionedHashes{
599652
Blobs: append(helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), helper.BlobID(TARGET_BLOBS_PER_BLOCK-1)),
600653
},
654+
ExpectedStatus: test.Invalid,
601655
},
602656
},
603657
},
@@ -621,6 +675,7 @@ var Tests = []test.SpecInterface{
621675
VersionedHashes: &VersionedHashes{
622676
Blobs: append(helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK-1), helper.BlobID(TARGET_BLOBS_PER_BLOCK)),
623677
},
678+
ExpectedStatus: test.Invalid,
624679
},
625680
},
626681
},
@@ -644,6 +699,7 @@ var Tests = []test.SpecInterface{
644699
Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK),
645700
HashVersions: []byte{BLOB_COMMITMENT_VERSION_KZG, BLOB_COMMITMENT_VERSION_KZG + 1},
646701
},
702+
ExpectedStatus: test.Invalid,
647703
},
648704
},
649705
},
@@ -667,6 +723,7 @@ var Tests = []test.SpecInterface{
667723
VersionedHashes: &VersionedHashes{
668724
Blobs: nil,
669725
},
726+
ExpectedStatus: test.Invalid,
670727
},
671728
},
672729
},
@@ -690,6 +747,7 @@ var Tests = []test.SpecInterface{
690747
VersionedHashes: &VersionedHashes{
691748
Blobs: []helper.BlobID{},
692749
},
750+
ExpectedStatus: test.Invalid,
693751
},
694752
},
695753
},
@@ -709,6 +767,7 @@ var Tests = []test.SpecInterface{
709767
VersionedHashes: &VersionedHashes{
710768
Blobs: []helper.BlobID{0},
711769
},
770+
ExpectedStatus: test.Invalid,
712771
},
713772
},
714773
},
@@ -719,9 +778,9 @@ var Tests = []test.SpecInterface{
719778
Spec: test.Spec{
720779
Name: "NewPayloadV3 Versioned Hashes, Missing Hash (Syncing)",
721780
About: `
722-
Tests VersionedHashes in Engine API NewPayloadV3 where the array
723-
is missing one of the hashes.
724-
`,
781+
Tests VersionedHashes in Engine API NewPayloadV3 where the array
782+
is missing one of the hashes.
783+
`,
725784
},
726785
TestSequence: TestSequence{
727786
NewPayloads{}, // Send new payload so the parent is unknown to the secondary client

0 commit comments

Comments
 (0)