Skip to content

Commit

Permalink
adding ssz response for get blobs beacon api endpoint (#12611)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-prysm authored and terencechain committed Aug 4, 2023
1 parent 3dd915b commit 50f5e09
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions network/writer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package network

import (
"fmt"
"net/http/httptest"
"strings"
"testing"

"github.com/ethereum/go-ethereum/common/hexutil"
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/testing/require"
)

func TestWriteSsz(t *testing.T) {
name := "test.ssz"
sidecar := &eth.BlobSidecar{
BlockRoot: make([]byte, fieldparams.RootLength),
Index: 0,
Slot: 0,
BlockParentRoot: make([]byte, fieldparams.RootLength),
ProposerIndex: 123,
Blob: make([]byte, fieldparams.BlobLength),
KzgCommitment: make([]byte, fieldparams.BLSPubkeyLength),
KzgProof: make([]byte, fieldparams.BLSPubkeyLength),
}
respSsz, err := sidecar.MarshalSSZ()
require.NoError(t, err)
writer := httptest.NewRecorder()
WriteSsz(writer, respSsz, name)
require.Equal(t, writer.Header().Get("Content-Type"), "application/octet-stream")
require.Equal(t, true, strings.Contains(writer.Header().Get("Content-Disposition"), name))
require.Equal(t, writer.Header().Get("Content-Length"), fmt.Sprintf("%v", len(respSsz)))
require.Equal(t, hexutil.Encode(writer.Body.Bytes()), hexutil.Encode(respSsz))
}

0 comments on commit 50f5e09

Please sign in to comment.