mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-21 15:29:27 +00:00
beacon/engine: preserve nil blob list JSON (#35019)
Fixes a regression where nil results from getBlobs were encoded as an empty array instead of null. --------- Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
ef5041ef4d
commit
dc07433d87
2 changed files with 14 additions and 0 deletions
|
|
@ -22,6 +22,9 @@ import (
|
|||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (list BlobAndProofListV1) MarshalJSON() ([]byte, error) {
|
||||
if list == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
var b jsonw.Buffer
|
||||
b.Array(func() {
|
||||
for _, item := range list {
|
||||
|
|
@ -46,6 +49,9 @@ func marshalBlobAndProofV1(b *jsonw.Buffer, item *BlobAndProofV1) {
|
|||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (list BlobAndProofListV2) MarshalJSON() ([]byte, error) {
|
||||
if list == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
var b jsonw.Buffer
|
||||
b.Array(func() {
|
||||
for _, item := range list {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"crypto/ecdsa"
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
|
@ -2105,6 +2106,13 @@ func runGetBlobs(t testing.TB, getBlobs getBlobsFn, start, limit int, fillRandom
|
|||
} else {
|
||||
// Nil is expected if getBlobs can not return a partial response
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue