mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
beacon/engine, eth/catalyst: preserve nil blob list JSON
This commit is contained in:
parent
efe58eac00
commit
b2b38c62be
3 changed files with 64 additions and 0 deletions
|
|
@ -22,6 +22,9 @@ import (
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshaler.
|
// MarshalJSON implements json.Marshaler.
|
||||||
func (list BlobAndProofListV1) MarshalJSON() ([]byte, error) {
|
func (list BlobAndProofListV1) MarshalJSON() ([]byte, error) {
|
||||||
|
if list == nil {
|
||||||
|
return []byte("null"), nil
|
||||||
|
}
|
||||||
var b jsonw.Buffer
|
var b jsonw.Buffer
|
||||||
b.Array(func() {
|
b.Array(func() {
|
||||||
for _, item := range list {
|
for _, item := range list {
|
||||||
|
|
@ -46,6 +49,9 @@ func marshalBlobAndProofV1(b *jsonw.Buffer, item *BlobAndProofV1) {
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshaler.
|
// MarshalJSON implements json.Marshaler.
|
||||||
func (list BlobAndProofListV2) MarshalJSON() ([]byte, error) {
|
func (list BlobAndProofListV2) MarshalJSON() ([]byte, error) {
|
||||||
|
if list == nil {
|
||||||
|
return []byte("null"), nil
|
||||||
|
}
|
||||||
var b jsonw.Buffer
|
var b jsonw.Buffer
|
||||||
b.Array(func() {
|
b.Array(func() {
|
||||||
for _, item := range list {
|
for _, item := range list {
|
||||||
|
|
|
||||||
50
beacon/engine/bapl_encode_test.go
Normal file
50
beacon/engine/bapl_encode_test.go
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
// Copyright 2026 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package engine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBlobAndProofListMarshalJSONNil(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
list any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "should encode null if BlobAndProofListV1 is nil",
|
||||||
|
list: BlobAndProofListV1(nil),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "should encode null if BlobAndProofListV2 is nil",
|
||||||
|
list: BlobAndProofListV2(nil),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
enc, err := json.Marshal(test.list)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if string(enc) != "null" {
|
||||||
|
t.Fatalf("got %s, want null", enc)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -2105,6 +2106,13 @@ func runGetBlobs(t testing.TB, getBlobs getBlobsFn, start, limit int, fillRandom
|
||||||
} else {
|
} else {
|
||||||
// Nil is expected if getBlobs can not return a partial response
|
// Nil is expected if getBlobs can not return a partial response
|
||||||
expect = nil
|
expect = nil
|
||||||
|
enc, err := json.Marshal(result)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to encode result for case %s: %v", name, err)
|
||||||
|
}
|
||||||
|
if string(enc) != "null" {
|
||||||
|
t.Fatalf("Unexpected JSON result for case %s: got %s, want null", name, enc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(result, expect) {
|
if !reflect.DeepEqual(result, expect) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue