mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
Fix a few bugs in the API (#9099)
This commit is contained in:
parent
b114247836
commit
9eb3ff6bdf
@ -21,6 +21,7 @@ func (f *BeaconEndpointFactory) Paths() []string {
|
||||
"/eth/v1/beacon/states/{state_id}/fork",
|
||||
"/eth/v1/beacon/states/{state_id}/finality_checkpoints",
|
||||
"/eth/v1/beacon/states/{state_id}/validators",
|
||||
"/eth/v1/beacon/states/{state_id}/validators/{validator_id}",
|
||||
"/eth/v1/beacon/states/{state_id}/validator_balances",
|
||||
"/eth/v1/beacon/states/{state_id}/committees",
|
||||
"/eth/v1/beacon/headers",
|
||||
@ -74,6 +75,12 @@ func (f *BeaconEndpointFactory) Create(path string) (*gateway.Endpoint, error) {
|
||||
Err: &gateway.DefaultErrorJson{},
|
||||
}
|
||||
case "/eth/v1/beacon/states/{state_id}/validators":
|
||||
endpoint = gateway.Endpoint{
|
||||
GetRequestQueryParams: []gateway.QueryParam{{Name: "id", Hex: true}, {Name: "status", Enum: true}},
|
||||
GetResponse: &stateValidatorsResponseJson{},
|
||||
Err: &gateway.DefaultErrorJson{},
|
||||
}
|
||||
case "/eth/v1/beacon/states/{state_id}/validators/{validator_id}":
|
||||
endpoint = gateway.Endpoint{
|
||||
GetResponse: &stateValidatorResponseJson{},
|
||||
Err: &gateway.DefaultErrorJson{},
|
||||
@ -162,6 +169,7 @@ func (f *BeaconEndpointFactory) Create(path string) (*gateway.Endpoint, error) {
|
||||
}
|
||||
case "/eth/v1/node/peers":
|
||||
endpoint = gateway.Endpoint{
|
||||
GetRequestQueryParams: []gateway.QueryParam{{Name: "state", Enum: true}, {Name: "direction", Enum: true}},
|
||||
GetResponse: &peersResponseJson{},
|
||||
Err: &gateway.DefaultErrorJson{},
|
||||
}
|
||||
|
@ -41,6 +41,11 @@ type stateFinalityCheckpointResponse_StateFinalityCheckpointJson struct {
|
||||
Finalized *checkpointJson `json:"finalized"`
|
||||
}
|
||||
|
||||
// stateValidatorResponseJson is used in /beacon/states/{state_id}/validators API endpoint.
|
||||
type stateValidatorsResponseJson struct {
|
||||
Data []*validatorContainerJson `json:"data"`
|
||||
}
|
||||
|
||||
// stateValidatorResponseJson is used in /beacon/states/{state_id}/validators/{validator_id} API endpoint.
|
||||
type stateValidatorResponseJson struct {
|
||||
Data *validatorContainerJson `json:"data"`
|
||||
|
@ -224,9 +224,7 @@ func (ns *Server) ListPeers(ctx context.Context, req *ethpb.PeersRequest) (*ethp
|
||||
}
|
||||
filteredPeers = append(filteredPeers, p)
|
||||
}
|
||||
if len(filteredPeers) == 0 {
|
||||
return nil, status.Error(codes.NotFound, "Peers not found")
|
||||
}
|
||||
|
||||
return ðpb.PeersResponse{Data: filteredPeers}, nil
|
||||
}
|
||||
|
||||
|
@ -367,6 +367,19 @@ func TestListPeers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListPeers_NoPeersReturnsEmptyArray(t *testing.T) {
|
||||
peerFetcher := &mockp2p.MockPeersProvider{}
|
||||
peerFetcher.ClearPeers()
|
||||
s := Server{PeersFetcher: peerFetcher}
|
||||
|
||||
resp, err := s.ListPeers(context.Background(), ðpb.PeersRequest{
|
||||
State: []ethpb.ConnectionState{ethpb.ConnectionState_CONNECTED},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp.Data)
|
||||
assert.Equal(t, 0, len(resp.Data))
|
||||
}
|
||||
|
||||
func TestPeerCount(t *testing.T) {
|
||||
ids := libp2ptest.GeneratePeerIDs(10)
|
||||
peerFetcher := &mockp2p.MockPeersProvider{}
|
||||
|
Loading…
Reference in New Issue
Block a user