From 1e3f7a9dad2ab6c338d14b9d675038516ffef845 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 29 May 2021 18:15:12 +0530 Subject: [PATCH 01/13] return empty list instead of rpc error when no records found for staking delegations --- x/staking/keeper/grpc_query.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/staking/keeper/grpc_query.go b/x/staking/keeper/grpc_query.go index 4852848255c0..8fa16354d48e 100644 --- a/x/staking/keeper/grpc_query.go +++ b/x/staking/keeper/grpc_query.go @@ -281,11 +281,6 @@ func (k Querier) DelegatorDelegations(c context.Context, req *types.QueryDelegat return nil, status.Error(codes.Internal, err.Error()) } - if delegations == nil { - return nil, status.Errorf( - codes.NotFound, - "unable to find delegations for address %s", req.DelegatorAddr) - } delegationResps, err := DelegationsToDelegationResponses(ctx, k.Keeper, delegations) if err != nil { return nil, status.Error(codes.Internal, err.Error()) From 846eeab6c471de08df0feabfa0c56c618c03a403 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 29 May 2021 19:12:29 +0530 Subject: [PATCH 02/13] fix grpc query DelegatorDelegations tests --- x/staking/keeper/grpc_query_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index dc47dc34c17a..c8fc367c7b74 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -288,17 +288,20 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { msg string malleate func() expPass bool + expErr bool }{ {"empty request", func() { req = &types.QueryDelegatorDelegationsRequest{} }, false, + true, }, {"invalid request", func() { req = &types.QueryDelegatorDelegationsRequest{DelegatorAddr: addrs[4].String()} }, false, + false, }, {"valid request", func() { @@ -306,6 +309,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { Pagination: &query.PageRequest{Limit: 1, CountTotal: true}} }, true, + false, }, } @@ -313,11 +317,16 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { tc.malleate() res, err := queryClient.DelegatorDelegations(gocontext.Background(), req) - if tc.expPass { + if tc.expPass && !tc.expErr { + suite.NoError(err) + suite.NotNil(res.Pagination.NextKey) suite.Equal(uint64(2), res.Pagination.Total) suite.Len(res.DelegationResponses, 1) suite.Equal(1, len(res.DelegationResponses)) suite.Equal(sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), res.DelegationResponses[0].Balance) + } else if !tc.expPass && !tc.expErr { + suite.NoError(err) + suite.Nil(res.DelegationResponses) } else { suite.Error(err) suite.Nil(res) From 67762fe8bf0070c06cf33322f2d468cc14ecf811 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 29 May 2021 19:37:39 +0530 Subject: [PATCH 03/13] remove response code tests for staking delegations --- x/staking/client/rest/grpc_query_test.go | 33 ------------------------ 1 file changed, 33 deletions(-) diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 651931d8d559..904222f2dcf4 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -4,16 +4,12 @@ package rest_test import ( "fmt" - "io/ioutil" - "net/http" "testing" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -414,35 +410,6 @@ func (s *IntegrationTestSuite) TestQueryUnbondingDelegationGRPC() { } } -func (s *IntegrationTestSuite) TestQueryDelegationsResponseCode() { - val := s.network.Validators[0] - - // Create new account in the keyring. - info, _, err := val.ClientCtx.Keyring.NewMnemonic("test", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) - s.Require().NoError(err) - newAddr := sdk.AccAddress(info.GetPubKey().Address()) - - s.T().Log("expect 404 error for address without delegations") - res, statusCode, err := getRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", val.APIAddress, newAddr.String())) - s.Require().NoError(err) - s.Require().Contains(string(res), "\"code\": 5") - s.Require().Equal(404, statusCode) -} - -func getRequest(url string) ([]byte, int, error) { - res, err := http.Get(url) // nolint:gosec - body, err := ioutil.ReadAll(res.Body) - if err != nil { - return nil, res.StatusCode, err - } - - if err = res.Body.Close(); err != nil { - return nil, res.StatusCode, err - } - - return body, res.StatusCode, nil -} - func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress From fb16c8886addc7f4f698f58382f462d69736b46d Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 29 May 2021 20:02:19 +0530 Subject: [PATCH 04/13] fix failing tests --- x/staking/client/rest/grpc_query_test.go | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 904222f2dcf4..6c7c37683cfc 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -4,12 +4,16 @@ package rest_test import ( "fmt" + "io/ioutil" + "net/http" "testing" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -410,6 +414,33 @@ func (s *IntegrationTestSuite) TestQueryUnbondingDelegationGRPC() { } } +func (s *IntegrationTestSuite) TestQueryDelegationsResponseCode() { + val := s.network.Validators[0] + + // Create new account in the keyring. + info, _, err := val.ClientCtx.Keyring.NewMnemonic("test", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + s.Require().NoError(err) + newAddr := sdk.AccAddress(info.GetPubKey().Address()) + + _, statusCode, err := getRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", val.APIAddress, newAddr.String())) + s.Require().NoError(err) + s.Require().Equal(404, statusCode) +} + +func getRequest(url string) ([]byte, int, error) { + res, err := http.Get(url) // nolint:gosec + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return nil, res.StatusCode, err + } + + if err = res.Body.Close(); err != nil { + return nil, res.StatusCode, err + } + + return body, res.StatusCode, nil +} + func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress From 098e5e3da0d5cee8cb261f8bc9504b92d7214b7d Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 29 May 2021 20:15:39 +0530 Subject: [PATCH 05/13] change staking delegations response code to 200 in grpc test --- x/staking/client/rest/grpc_query_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 6c7c37683cfc..5c2472cf93b6 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -424,7 +424,7 @@ func (s *IntegrationTestSuite) TestQueryDelegationsResponseCode() { _, statusCode, err := getRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", val.APIAddress, newAddr.String())) s.Require().NoError(err) - s.Require().Equal(404, statusCode) + s.Require().Equal(200, statusCode) } func getRequest(url string) ([]byte, int, error) { From c30a5796fb5a9d9fb9a1c65865809b0de8ec6e60 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 31 May 2021 15:43:36 +0530 Subject: [PATCH 06/13] add staking delegations response code tests to TestQueryDelegatorDelegationsGRPC --- x/staking/client/rest/grpc_query_test.go | 36 +++++++++++------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 5c2472cf93b6..9ca0001c80f4 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -414,8 +414,9 @@ func (s *IntegrationTestSuite) TestQueryUnbondingDelegationGRPC() { } } -func (s *IntegrationTestSuite) TestQueryDelegationsResponseCode() { +func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { val := s.network.Validators[0] + baseURL := val.APIAddress // Create new account in the keyring. info, _, err := val.ClientCtx.Keyring.NewMnemonic("test", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) @@ -425,25 +426,6 @@ func (s *IntegrationTestSuite) TestQueryDelegationsResponseCode() { _, statusCode, err := getRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", val.APIAddress, newAddr.String())) s.Require().NoError(err) s.Require().Equal(200, statusCode) -} - -func getRequest(url string) ([]byte, int, error) { - res, err := http.Get(url) // nolint:gosec - body, err := ioutil.ReadAll(res.Body) - if err != nil { - return nil, res.StatusCode, err - } - - if err = res.Body.Close(); err != nil { - return nil, res.StatusCode, err - } - - return body, res.StatusCode, nil -} - -func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { - val := s.network.Validators[0] - baseURL := val.APIAddress testCases := []struct { name string @@ -504,6 +486,20 @@ func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { } } +func getRequest(url string) ([]byte, int, error) { + res, err := http.Get(url) // nolint:gosec + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return nil, res.StatusCode, err + } + + if err = res.Body.Close(); err != nil { + return nil, res.StatusCode, err + } + + return body, res.StatusCode, nil +} + func (s *IntegrationTestSuite) TestQueryDelegatorUnbondingDelegationsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress From 3f66dc57889de7d5ce061dec0d169b8d782401e1 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 31 May 2021 16:25:56 +0530 Subject: [PATCH 07/13] add address without delegations testcase --- x/staking/client/rest/grpc_query_test.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 9ca0001c80f4..44530a29bb2c 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -418,15 +418,11 @@ func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress - // Create new account in the keyring. + // Create new account in the keyring for address without delegations. info, _, err := val.ClientCtx.Keyring.NewMnemonic("test", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) s.Require().NoError(err) newAddr := sdk.AccAddress(info.GetPubKey().Address()) - _, statusCode, err := getRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", val.APIAddress, newAddr.String())) - s.Require().NoError(err) - s.Require().Equal(200, statusCode) - testCases := []struct { name string url string @@ -466,6 +462,19 @@ func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { Pagination: &query.PageResponse{Total: 1}, }, }, + { + "address without delegations", + fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", baseURL, newAddr.String()), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "1", + }, + false, + &types.QueryDelegatorDelegationsResponse{}, + &types.QueryDelegatorDelegationsResponse{ + DelegationResponses: types.DelegationResponses{}, + Pagination: &query.PageResponse{Total: 0}, + }, + }, } for _, tc := range testCases { From 391a384f70c1c1d86138f0e706599b8cb5c3546b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 31 May 2021 19:06:44 +0530 Subject: [PATCH 08/13] add changes to grpc query tests of delegatorDelegations --- x/staking/keeper/grpc_query_test.go | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index c8fc367c7b74..1b6b30d54949 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -285,22 +285,23 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { var req *types.QueryDelegatorDelegationsRequest testCases := []struct { - msg string - malleate func() - expPass bool - expErr bool + msg string + malleate func() + onSuccess func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) + expErr bool }{ {"empty request", func() { req = &types.QueryDelegatorDelegationsRequest{} }, - false, + func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) {}, true, - }, {"invalid request", + }, + {"invalid request", func() { req = &types.QueryDelegatorDelegationsRequest{DelegatorAddr: addrs[4].String()} }, - false, + func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) {}, false, }, {"valid request", @@ -308,7 +309,12 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { req = &types.QueryDelegatorDelegationsRequest{DelegatorAddr: addrAcc.String(), Pagination: &query.PageRequest{Limit: 1, CountTotal: true}} }, - true, + func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) { + suite.Equal(uint64(2), response.Pagination.Total) + suite.Len(response.DelegationResponses, 1) + suite.Equal(1, len(response.DelegationResponses)) + suite.Equal(sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), response.DelegationResponses[0].Balance) + }, false, }, } @@ -317,19 +323,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { tc.malleate() res, err := queryClient.DelegatorDelegations(gocontext.Background(), req) - if tc.expPass && !tc.expErr { - suite.NoError(err) - suite.NotNil(res.Pagination.NextKey) - suite.Equal(uint64(2), res.Pagination.Total) - suite.Len(res.DelegationResponses, 1) - suite.Equal(1, len(res.DelegationResponses)) - suite.Equal(sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), res.DelegationResponses[0].Balance) - } else if !tc.expPass && !tc.expErr { - suite.NoError(err) - suite.Nil(res.DelegationResponses) - } else { + if tc.expErr { suite.Error(err) - suite.Nil(res) + } else { + suite.NoError(err) + tc.onSuccess(suite, res) } }) } From a6e19ff3b584d99a7820ea8f27f14fec56037c53 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 31 May 2021 19:10:00 +0530 Subject: [PATCH 09/13] remove getRequest unused function from x/staking/client/rest/grpc_query_test.go --- x/staking/client/rest/grpc_query_test.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 44530a29bb2c..7ead75b8df73 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -4,8 +4,6 @@ package rest_test import ( "fmt" - "io/ioutil" - "net/http" "testing" "github.com/gogo/protobuf/proto" @@ -495,20 +493,6 @@ func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() { } } -func getRequest(url string) ([]byte, int, error) { - res, err := http.Get(url) // nolint:gosec - body, err := ioutil.ReadAll(res.Body) - if err != nil { - return nil, res.StatusCode, err - } - - if err = res.Body.Close(); err != nil { - return nil, res.StatusCode, err - } - - return body, res.StatusCode, nil -} - func (s *IntegrationTestSuite) TestQueryDelegatorUnbondingDelegationsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress From 9e1279efeed39ec23d9ab368410757bd5e9b2fc7 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 1 Jun 2021 13:22:48 +0530 Subject: [PATCH 10/13] minor fixes --- x/staking/keeper/grpc_query_test.go | 96 +++++++++++++++++++---------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index 1b6b30d54949..2bfa1d55755d 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -35,7 +35,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() { len(vals), false, }, - {"empty status returns all the validators", + { + "empty status returns all the validators", func() { req = &types.QueryValidatorsRequest{Status: ""} }, @@ -52,7 +53,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() { 0, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryValidatorsRequest{Status: types.Bonded.String(), Pagination: &query.PageRequest{Limit: 1, CountTotal: true}} @@ -101,7 +103,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidator() { }, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryValidatorRequest{ValidatorAddr: vals[0].OperatorAddress} }, @@ -141,7 +144,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorValidators() { }, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryDelegatorValidatorsRequest{ DelegatorAddr: addrs[0].String(), @@ -185,7 +189,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorValidator() { }, false, }, - {"invalid delegator, validator pair", + { + "invalid delegator, validator pair", func() { req = &types.QueryDelegatorValidatorRequest{ DelegatorAddr: addr.String(), @@ -194,7 +199,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorValidator() { }, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryDelegatorValidatorRequest{ DelegatorAddr: addr.String(), @@ -235,13 +241,15 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegation() { malleate func() expPass bool }{ - {"empty request", + { + "empty request", func() { req = &types.QueryDelegationRequest{} }, false, }, - {"invalid validator, delegator pair", + { + "invalid validator, delegator pair", func() { req = &types.QueryDelegationRequest{ DelegatorAddr: addrAcc1.String(), @@ -250,7 +258,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegation() { }, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryDelegationRequest{DelegatorAddr: addrAcc.String(), ValidatorAddr: addrVal} }, @@ -290,21 +299,24 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { onSuccess func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) expErr bool }{ - {"empty request", + { + "empty request", func() { req = &types.QueryDelegatorDelegationsRequest{} }, func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) {}, true, }, - {"invalid request", + { + "valid request with no delegations", func() { req = &types.QueryDelegatorDelegationsRequest{DelegatorAddr: addrs[4].String()} }, func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) {}, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryDelegatorDelegationsRequest{DelegatorAddr: addrAcc.String(), Pagination: &query.PageRequest{Limit: 1, CountTotal: true}} @@ -351,21 +363,24 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidatorDelegations() { expPass bool expErr bool }{ - {"empty request", + { + "empty request", func() { req = &types.QueryValidatorDelegationsRequest{} }, false, true, }, - {"invalid validator delegator pair", + { + "invalid validator delegator pair", func() { req = &types.QueryValidatorDelegationsRequest{ValidatorAddr: addrVal2.String()} }, false, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryValidatorDelegationsRequest{ValidatorAddr: addrVal1, Pagination: &query.PageRequest{Limit: 1, CountTotal: true}} @@ -416,19 +431,22 @@ func (suite *KeeperTestSuite) TestGRPCQueryUnbondingDelegation() { malleate func() expPass bool }{ - {"empty request", + { + "empty request", func() { req = &types.QueryUnbondingDelegationRequest{} }, false, }, - {"invalid request", + { + "invalid request", func() { req = &types.QueryUnbondingDelegationRequest{} }, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryUnbondingDelegationRequest{ DelegatorAddr: addrAcc2.String(), ValidatorAddr: addrVal2} @@ -476,21 +494,24 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorUnbondingDelegations() { expPass bool expErr bool }{ - {"empty request", + { + "empty request", func() { req = &types.QueryDelegatorUnbondingDelegationsRequest{} }, false, true, }, - {"invalid request", + { + "invalid request", func() { req = &types.QueryDelegatorUnbondingDelegationsRequest{DelegatorAddr: addrAcc1.String()} }, false, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryDelegatorUnbondingDelegationsRequest{DelegatorAddr: addrAcc.String(), Pagination: &query.PageRequest{Limit: 1, CountTotal: true}} @@ -551,25 +572,29 @@ func (suite *KeeperTestSuite) TestGRPCQueryHistoricalInfo() { malleate func() expPass bool }{ - {"empty request", + { + "empty request", func() { req = &types.QueryHistoricalInfoRequest{} }, false, }, - {"invalid request with negative height", + { + "invalid request with negative height", func() { req = &types.QueryHistoricalInfoRequest{Height: -1} }, false, }, - {"valid request with old height", + { + "valid request with old height", func() { req = &types.QueryHistoricalInfoRequest{Height: 4} }, false, }, - {"valid request with current height", + { + "valid request with current height", func() { req = &types.QueryHistoricalInfoRequest{Height: 5} }, @@ -619,14 +644,16 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() { expPass bool expErr bool }{ - {"request redelegations for non existent addr", + { + "request redelegations for non existent addr", func() { req = &types.QueryRedelegationsRequest{DelegatorAddr: addrAcc.String()} }, false, false, }, - {"request redelegations with non existent pairs", + { + "request redelegations with non existent pairs", func() { req = &types.QueryRedelegationsRequest{DelegatorAddr: addrAcc.String(), SrcValidatorAddr: val3.String(), DstValidatorAddr: val4.String()} @@ -634,7 +661,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() { false, true, }, - {"request redelegations with delegatoraddr, sourceValAddr, destValAddr", + { + "request redelegations with delegatoraddr, sourceValAddr, destValAddr", func() { req = &types.QueryRedelegationsRequest{ DelegatorAddr: addrAcc1.String(), SrcValidatorAddr: val1.OperatorAddress, @@ -643,7 +671,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() { true, false, }, - {"request redelegations with delegatoraddr and sourceValAddr", + { + "request redelegations with delegatoraddr and sourceValAddr", func() { req = &types.QueryRedelegationsRequest{ DelegatorAddr: addrAcc1.String(), SrcValidatorAddr: val1.OperatorAddress, @@ -652,7 +681,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() { true, false, }, - {"query redelegations with sourceValAddr only", + { + "query redelegations with sourceValAddr only", func() { req = &types.QueryRedelegationsRequest{ SrcValidatorAddr: val1.GetOperator().String(), @@ -702,13 +732,15 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidatorUnbondingDelegations() { malleate func() expPass bool }{ - {"empty request", + { + "empty request", func() { req = &types.QueryValidatorUnbondingDelegationsRequest{} }, false, }, - {"valid request", + { + "valid request", func() { req = &types.QueryValidatorUnbondingDelegationsRequest{ ValidatorAddr: val1.GetOperator().String(), From cc0744fcda2f6d3612f39756012f53c16a9693a8 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 1 Jun 2021 15:16:11 +0530 Subject: [PATCH 11/13] add testcases for request with no delegations --- x/staking/keeper/grpc_query_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index 2bfa1d55755d..744bcbb35673 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -312,7 +312,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { func() { req = &types.QueryDelegatorDelegationsRequest{DelegatorAddr: addrs[4].String()} }, - func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) {}, + func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) { + suite.Equal(uint64(0), response.Pagination.Total) + suite.Len(response.DelegationResponses, 0) + suite.Equal(0, len(response.DelegationResponses)) + }, false, }, { From 04f1a8935024c477d15581659300c233a79279e3 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 1 Jun 2021 15:47:39 +0530 Subject: [PATCH 12/13] address review comments --- x/staking/keeper/grpc_query_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index 744bcbb35673..ba43269e2e32 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -315,7 +315,6 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) { suite.Equal(uint64(0), response.Pagination.Total) suite.Len(response.DelegationResponses, 0) - suite.Equal(0, len(response.DelegationResponses)) }, false, }, @@ -328,7 +327,6 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() { func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) { suite.Equal(uint64(2), response.Pagination.Total) suite.Len(response.DelegationResponses, 1) - suite.Equal(1, len(response.DelegationResponses)) suite.Equal(sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), response.DelegationResponses[0].Balance) }, false, From 7e4662480b5a9a17d08f9c8d402e3b28f47ba39d Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 1 Jun 2021 16:00:44 +0530 Subject: [PATCH 13/13] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0249a1d31d4e..1e5e1843296a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -127,6 +127,7 @@ if input key is empty, or input data contains empty key. ### Improvements +* (x/staking) [\#9423](https://github.com/cosmos/cosmos-sdk/pull/9423) Staking delegations now returns empty list instead of rpc error when no records found. * (baseapp, types) [#\9390](https://github.com/cosmos/cosmos-sdk/pull/9390) Add current block header hash to `Context` * (x/bank) [\#8614](https://github.com/cosmos/cosmos-sdk/issues/8614) Add `Name` and `Symbol` fields to denom metadata * (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts