diff --git a/CHANGELOG.md b/CHANGELOG.md index d99901f0e169..83aba3f35139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * (cli) [#17188](https://github.com/cosmos/cosmos-sdk/pull/17188) Fix `--output-document` flag in `tx multi-sign`. +* (x/auth) [#17209](https://github.com/cosmos/cosmos-sdk/pull/17209) Internal error on AccountInfo when account's public key is not set. ## [v0.47.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.4) - 2023-07-17 diff --git a/x/auth/keeper/grpc_query.go b/x/auth/keeper/grpc_query.go index 983da9c5a3a8..7acb77134c68 100644 --- a/x/auth/keeper/grpc_query.go +++ b/x/auth/keeper/grpc_query.go @@ -231,9 +231,14 @@ func (ak AccountKeeper) AccountInfo(goCtx context.Context, req *types.QueryAccou return nil, status.Errorf(codes.NotFound, "account %s not found", req.Address) } - pkAny, err := codectypes.NewAnyWithValue(account.GetPubKey()) - if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + // if there is no public key, avoid serializing the nil value + pubKey := account.GetPubKey() + var pkAny *codectypes.Any + if pubKey != nil { + pkAny, err = codectypes.NewAnyWithValue(account.GetPubKey()) + if err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) + } } return &types.QueryAccountInfoResponse{ diff --git a/x/auth/keeper/grpc_query_test.go b/x/auth/keeper/grpc_query_test.go index 5a9ebbd2ea22..55b08ad20ad1 100644 --- a/x/auth/keeper/grpc_query_test.go +++ b/x/auth/keeper/grpc_query_test.go @@ -532,3 +532,17 @@ func (suite *KeeperTestSuite) TestQueryAccountInfo() { suite.Require().NoError(err) suite.Require().Equal(pkBz, res.Info.PubKey.Value) } + +func (suite *KeeperTestSuite) TestQueryAccountInfoWithoutPubKey() { + acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr) + suite.accountKeeper.SetAccount(suite.ctx, acc) + + res, err := suite.queryClient.AccountInfo(context.Background(), &types.QueryAccountInfoRequest{ + Address: addr.String(), + }) + + suite.Require().NoError(err) + suite.Require().NotNil(res.Info) + suite.Require().Equal(addr.String(), res.Info.Address) + suite.Require().Nil(res.Info.PubKey) +}