Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(x/auth): internal error on AccountInfo when PubKey is nil (#17209)
Browse files Browse the repository at this point in the history
(cherry picked from commit bf1803b)

# Conflicts:
#	CHANGELOG.md
facundomedica authored and mergify[bot] committed Jul 31, 2023
1 parent 1a2ad4f commit 99bf713
Showing 3 changed files with 365 additions and 3 deletions.
343 changes: 343 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

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

0 comments on commit 99bf713

Please sign in to comment.