Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DeepSource errors in the Validator's REST API #11726

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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