mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
Return 404 from eth/v1/beacon/headers
when there are no blocks (#13185)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
0946b5853f
commit
9b97f3fd92
@ -1747,6 +1747,11 @@ func (s *Server) GetBlockHeaders(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(blks) == 0 {
|
||||
http2.HandleError(w, "No blocks found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
isOptimistic := false
|
||||
isFinalized := true
|
||||
blkHdrs := make([]*shared.SignedBeaconBlockHeaderContainer, len(blks))
|
||||
|
@ -2670,6 +2670,7 @@ func TestGetBlockHeaders(t *testing.T) {
|
||||
writer.Body = &bytes.Buffer{}
|
||||
|
||||
bs.GetBlockHeaders(writer, request)
|
||||
require.Equal(t, http.StatusOK, writer.Code)
|
||||
resp := &GetBlockHeadersResponse{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||
|
||||
@ -2721,6 +2722,7 @@ func TestGetBlockHeaders(t *testing.T) {
|
||||
writer.Body = &bytes.Buffer{}
|
||||
|
||||
bs.GetBlockHeaders(writer, request)
|
||||
require.Equal(t, http.StatusOK, writer.Code)
|
||||
resp := &GetBlockHeadersResponse{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||
assert.Equal(t, true, resp.ExecutionOptimistic)
|
||||
@ -2764,6 +2766,7 @@ func TestGetBlockHeaders(t *testing.T) {
|
||||
writer.Body = &bytes.Buffer{}
|
||||
|
||||
bs.GetBlockHeaders(writer, request)
|
||||
require.Equal(t, http.StatusOK, writer.Code)
|
||||
resp := &GetBlockHeadersResponse{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||
assert.Equal(t, true, resp.Finalized)
|
||||
@ -2777,6 +2780,7 @@ func TestGetBlockHeaders(t *testing.T) {
|
||||
writer.Body = &bytes.Buffer{}
|
||||
|
||||
bs.GetBlockHeaders(writer, request)
|
||||
require.Equal(t, http.StatusOK, writer.Code)
|
||||
resp := &GetBlockHeadersResponse{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||
assert.Equal(t, false, resp.Finalized)
|
||||
@ -2789,10 +2793,25 @@ func TestGetBlockHeaders(t *testing.T) {
|
||||
writer.Body = &bytes.Buffer{}
|
||||
|
||||
bs.GetBlockHeaders(writer, request)
|
||||
require.Equal(t, http.StatusOK, writer.Code)
|
||||
resp := &GetBlockHeadersResponse{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||
assert.Equal(t, false, resp.Finalized)
|
||||
})
|
||||
t.Run("no blocks found", func(t *testing.T) {
|
||||
urlWithParams := fmt.Sprintf("%s?parent_root=%s", url, hexutil.Encode(bytes.Repeat([]byte{1}, 32)))
|
||||
request := httptest.NewRequest(http.MethodGet, urlWithParams, nil)
|
||||
writer := httptest.NewRecorder()
|
||||
|
||||
writer.Body = &bytes.Buffer{}
|
||||
|
||||
bs.GetBlockHeaders(writer, request)
|
||||
require.Equal(t, http.StatusNotFound, writer.Code)
|
||||
e := &http2.DefaultErrorJson{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), e))
|
||||
assert.Equal(t, http.StatusNotFound, e.Code)
|
||||
assert.StringContains(t, "No blocks found", e.Message)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user