Skip to content

Commit

Permalink
Fix DeepSource errors in the Validator's REST API (#11726)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatriceVignola committed Dec 6, 2022
1 parent 19af1d2 commit 05148db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
13 changes: 6 additions & 7 deletions validator/client/beacon-api/beacon_api_validator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ type beaconApiValidatorClient struct {
fallbackClient iface.ValidatorClient
}

func NewBeaconApiValidatorClient(host string, timeout time.Duration) *beaconApiValidatorClient {
func NewBeaconApiValidatorClient(host string, timeout time.Duration) iface.ValidatorClient {
return NewBeaconApiValidatorClientWithFallback(host, timeout, nil)
}

func NewBeaconApiValidatorClientWithFallback(host string, timeout time.Duration, fallbackClient iface.ValidatorClient) iface.ValidatorClient {
jsonRestHandler := beaconApiJsonRestHandler{
httpClient: http.Client{Timeout: timeout},
host: host,
Expand All @@ -31,15 +35,10 @@ func NewBeaconApiValidatorClient(host string, timeout time.Duration) *beaconApiV
return &beaconApiValidatorClient{
genesisProvider: beaconApiGenesisProvider{jsonRestHandler: jsonRestHandler},
jsonRestHandler: jsonRestHandler,
fallbackClient: fallbackClient,
}
}

func NewBeaconApiValidatorClientWithFallback(url string, timeout time.Duration, fallbackClient iface.ValidatorClient) *beaconApiValidatorClient {
beaconApiValidatorClient := NewBeaconApiValidatorClient(url, timeout)
beaconApiValidatorClient.fallbackClient = fallbackClient
return beaconApiValidatorClient
}

func (c *beaconApiValidatorClient) GetDuties(ctx context.Context, in *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) {
if c.fallbackClient != nil {
return c.fallbackClient.GetDuties(ctx, in)
Expand Down
10 changes: 5 additions & 5 deletions validator/client/beacon-api/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

const stringPubKey = "0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13"

func getPubKeyAndURL(t *testing.T, stringPubkey string) ([]byte, string) {
func getPubKeyAndURL(t *testing.T) ([]byte, string) {
baseUrl := "/eth/v1/beacon/states/head/validators"
url := fmt.Sprintf("%s?id=%s", baseUrl, stringPubKey)

Expand All @@ -35,7 +35,7 @@ func TestIndex_Nominal(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

pubKey, url := getPubKeyAndURL(t, stringPubKey)
pubKey, url := getPubKeyAndURL(t)

stateValidatorsResponseJson := rpcmiddleware.StateValidatorsResponseJson{}
jsonRestHandler := mock.NewMockjsonRestHandler(ctrl)
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestIndex_UnexistingValidator(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

pubKey, url := getPubKeyAndURL(t, stringPubKey)
pubKey, url := getPubKeyAndURL(t)

stateValidatorsResponseJson := rpcmiddleware.StateValidatorsResponseJson{}
jsonRestHandler := mock.NewMockjsonRestHandler(ctrl)
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestIndex_BadIndexError(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

pubKey, url := getPubKeyAndURL(t, stringPubKey)
pubKey, url := getPubKeyAndURL(t)

stateValidatorsResponseJson := rpcmiddleware.StateValidatorsResponseJson{}
jsonRestHandler := mock.NewMockjsonRestHandler(ctrl)
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestIndex_JsonResponseError(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

pubKey, url := getPubKeyAndURL(t, stringPubKey)
pubKey, url := getPubKeyAndURL(t)

stateValidatorsResponseJson := rpcmiddleware.StateValidatorsResponseJson{}
jsonRestHandler := mock.NewMockjsonRestHandler(ctrl)
Expand Down
6 changes: 3 additions & 3 deletions validator/client/beacon-api/json_rest_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestGetRestJsonResponse_Error(t *testing.T) {
}

func httpErrorJsonHandler(statusCode int, errorMessage string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, _ *http.Request) {
errorJson := &apimiddleware.DefaultErrorJson{
Code: statusCode,
Message: errorMessage,
Expand All @@ -176,15 +176,15 @@ func httpErrorJsonHandler(statusCode int, errorMessage string) func(w http.Respo
}
}

func invalidJsonErrHandler(w http.ResponseWriter, r *http.Request) {
func invalidJsonErrHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNotFound)
_, err := w.Write([]byte("foo"))
if err != nil {
panic(err)
}
}

func invalidJsonResponseHandler(w http.ResponseWriter, r *http.Request) {
func invalidJsonResponseHandler(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("foo"))
if err != nil {
panic(err)
Expand Down

0 comments on commit 05148db

Please sign in to comment.