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(x/auth): internal error on AccountInfo when PubKey is nil (backport #17209) #17211

Merged
merged 2 commits into from
Jul 31, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions x/auth/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
14 changes: 14 additions & 0 deletions x/auth/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}