mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
Add REST implementation of node version endpoint (#12809)
This commit is contained in:
parent
30eaddf48f
commit
4ef29a24e4
@ -75,13 +75,19 @@ func (c *beaconApiNodeClient) GetGenesis(ctx context.Context, _ *empty.Empty) (*
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *beaconApiNodeClient) GetVersion(ctx context.Context, in *empty.Empty) (*ethpb.Version, error) {
|
||||
if c.fallbackClient != nil {
|
||||
return c.fallbackClient.GetVersion(ctx, in)
|
||||
func (c *beaconApiNodeClient) GetVersion(ctx context.Context, _ *empty.Empty) (*ethpb.Version, error) {
|
||||
var versionResponse apimiddleware.VersionResponseJson
|
||||
if _, err := c.jsonRestHandler.GetRestJsonResponse(ctx, "/eth/v1/node/version", &versionResponse); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to query node version")
|
||||
}
|
||||
|
||||
// TODO: Implement me
|
||||
panic("beaconApiNodeClient.GetVersion is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.")
|
||||
if versionResponse.Data == nil || versionResponse.Data.Version == "" {
|
||||
return nil, errors.New("empty version response")
|
||||
}
|
||||
|
||||
return ðpb.Version{
|
||||
Version: versionResponse.Data.Version,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *beaconApiNodeClient) ListPeers(ctx context.Context, in *empty.Empty) (*ethpb.Peers, error) {
|
||||
|
@ -228,3 +228,68 @@ func TestGetSyncStatus(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetVersion(t *testing.T) {
|
||||
const versionEndpoint = "/eth/v1/node/version"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
restEndpointResponse apimiddleware.VersionResponseJson
|
||||
restEndpointError error
|
||||
expectedResponse *ethpb.Version
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "fails to query REST endpoint",
|
||||
restEndpointError: errors.New("foo error"),
|
||||
expectedError: "failed to query node version",
|
||||
},
|
||||
{
|
||||
name: "returns nil version data",
|
||||
restEndpointResponse: apimiddleware.VersionResponseJson{Data: nil},
|
||||
expectedError: "empty version response",
|
||||
},
|
||||
{
|
||||
name: "returns proper version response",
|
||||
restEndpointResponse: apimiddleware.VersionResponseJson{
|
||||
Data: &apimiddleware.VersionJson{
|
||||
Version: "prysm/local",
|
||||
},
|
||||
},
|
||||
expectedResponse: ðpb.Version{
|
||||
Version: "prysm/local",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
var versionResponse apimiddleware.VersionResponseJson
|
||||
jsonRestHandler := mock.NewMockjsonRestHandler(ctrl)
|
||||
jsonRestHandler.EXPECT().GetRestJsonResponse(
|
||||
ctx,
|
||||
versionEndpoint,
|
||||
&versionResponse,
|
||||
).Return(
|
||||
nil,
|
||||
testCase.restEndpointError,
|
||||
).SetArg(
|
||||
2,
|
||||
testCase.restEndpointResponse,
|
||||
)
|
||||
|
||||
nodeClient := &beaconApiNodeClient{jsonRestHandler: jsonRestHandler}
|
||||
version, err := nodeClient.GetVersion(ctx, &emptypb.Empty{})
|
||||
|
||||
if testCase.expectedResponse == nil {
|
||||
assert.ErrorContains(t, testCase.expectedError, err)
|
||||
} else {
|
||||
assert.DeepEqual(t, testCase.expectedResponse, version)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user