fix(x/auth): internal error on AccountInfo when PubKey is nil (#17209)
This commit is contained in:
@@ -226,9 +226,14 @@ func (s queryServer) AccountInfo(ctx context.Context, req *types.QueryAccountInf
|
||||
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{
|
||||
|
||||
@@ -521,3 +521,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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user