Skip to content

Commit 32308b8

Browse files
authored
Merge branch 'master' into feature/bank-init-genesis-optimize
2 parents c553b27 + da87ab0 commit 32308b8

File tree

5 files changed

+103
-79
lines changed

5 files changed

+103
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ if input key is empty, or input data contains empty key.
128128

129129
### Improvements
130130

131+
* (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.
131132
* (baseapp, types) [#\9390](https://github.com/cosmos/cosmos-sdk/pull/9390) Add current block header hash to `Context`
132133
* (x/bank) [\#8614](https://github.com/cosmos/cosmos-sdk/issues/8614) Add `Name` and `Symbol` fields to denom metadata
133134
* (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts

x/slashing/types/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func ValidateGenesis(data GenesisState) error {
5555

5656
downtimeJail := data.Params.DowntimeJailDuration
5757
if downtimeJail < 1*time.Minute {
58-
return fmt.Errorf("downtime unblond duration must be at least 1 minute, is %s", downtimeJail.String())
58+
return fmt.Errorf("downtime unjail duration must be at least 1 minute, is %s", downtimeJail.String())
5959
}
6060

6161
signedWindow := data.Params.SignedBlocksWindow

x/staking/client/rest/grpc_query_test.go

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ package rest_test
44

55
import (
66
"fmt"
7-
"io/ioutil"
8-
"net/http"
97
"testing"
108

119
"github.com/gogo/protobuf/proto"
@@ -414,39 +412,15 @@ func (s *IntegrationTestSuite) TestQueryUnbondingDelegationGRPC() {
414412
}
415413
}
416414

417-
func (s *IntegrationTestSuite) TestQueryDelegationsResponseCode() {
415+
func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() {
418416
val := s.network.Validators[0]
417+
baseURL := val.APIAddress
419418

420-
// Create new account in the keyring.
419+
// Create new account in the keyring for address without delegations.
421420
info, _, err := val.ClientCtx.Keyring.NewMnemonic("test", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
422421
s.Require().NoError(err)
423422
newAddr := sdk.AccAddress(info.GetPubKey().Address())
424423

425-
s.T().Log("expect 404 error for address without delegations")
426-
res, statusCode, err := getRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", val.APIAddress, newAddr.String()))
427-
s.Require().NoError(err)
428-
s.Require().Contains(string(res), "\"code\": 5")
429-
s.Require().Equal(404, statusCode)
430-
}
431-
432-
func getRequest(url string) ([]byte, int, error) {
433-
res, err := http.Get(url) // nolint:gosec
434-
body, err := ioutil.ReadAll(res.Body)
435-
if err != nil {
436-
return nil, res.StatusCode, err
437-
}
438-
439-
if err = res.Body.Close(); err != nil {
440-
return nil, res.StatusCode, err
441-
}
442-
443-
return body, res.StatusCode, nil
444-
}
445-
446-
func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() {
447-
val := s.network.Validators[0]
448-
baseURL := val.APIAddress
449-
450424
testCases := []struct {
451425
name string
452426
url string
@@ -486,6 +460,19 @@ func (s *IntegrationTestSuite) TestQueryDelegatorDelegationsGRPC() {
486460
Pagination: &query.PageResponse{Total: 1},
487461
},
488462
},
463+
{
464+
"address without delegations",
465+
fmt.Sprintf("%s/cosmos/staking/v1beta1/delegations/%s", baseURL, newAddr.String()),
466+
map[string]string{
467+
grpctypes.GRPCBlockHeightHeader: "1",
468+
},
469+
false,
470+
&types.QueryDelegatorDelegationsResponse{},
471+
&types.QueryDelegatorDelegationsResponse{
472+
DelegationResponses: types.DelegationResponses{},
473+
Pagination: &query.PageResponse{Total: 0},
474+
},
475+
},
489476
}
490477

491478
for _, tc := range testCases {

x/staking/keeper/grpc_query.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ func (k Querier) DelegatorDelegations(c context.Context, req *types.QueryDelegat
281281
return nil, status.Error(codes.Internal, err.Error())
282282
}
283283

284-
if delegations == nil {
285-
return nil, status.Errorf(
286-
codes.NotFound,
287-
"unable to find delegations for address %s", req.DelegatorAddr)
288-
}
289284
delegationResps, err := DelegationsToDelegationResponses(ctx, k.Keeper, delegations)
290285
if err != nil {
291286
return nil, status.Error(codes.Internal, err.Error())

0 commit comments

Comments
 (0)