From f6d4b2e83846d821b5cd71790451be5b8c40f1a3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 3 Nov 2023 09:56:42 +0000 Subject: [PATCH] refactor(x/group): check the new admin address when updating the group policy admin (backport #18350) (#18352) Co-authored-by: Luke Ma --- x/group/keeper/msg_server.go | 4 ++++ x/group/keeper/msg_server_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index 048b82a356..b36215a75e 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -429,6 +429,10 @@ func (k Keeper) UpdateGroupPolicyAdmin(goCtx context.Context, msg *group.MsgUpda return nil, errorsmod.Wrap(errors.ErrInvalid, "new and old admin are same") } + if _, err := k.accKeeper.AddressCodec().StringToBytes(msg.NewAdmin); err != nil { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "new admin address") + } + ctx := sdk.UnwrapSDKContext(goCtx) action := func(groupPolicy *group.GroupPolicyInfo) error { groupPolicy.Admin = msg.NewAdmin diff --git a/x/group/keeper/msg_server_test.go b/x/group/keeper/msg_server_test.go index 493b8167e8..32b0585237 100644 --- a/x/group/keeper/msg_server_test.go +++ b/x/group/keeper/msg_server_test.go @@ -661,6 +661,15 @@ func (s *TestSuite) TestUpdateGroupAdmin() { CreatedAt: s.blockTime, }, }, + "with invalid new admin address": { + req: &group.MsgUpdateGroupAdmin{ + GroupId: groupID, + Admin: oldAdmin, + NewAdmin: "%s", + }, + expErr: true, + expErrMsg: "new admin address", + }, } for msg, spec := range specs { spec := spec @@ -1215,6 +1224,23 @@ func (s *TestSuite) TestUpdateGroupPolicyAdmin() { }, expErr: false, }, + "with invalid new admin address": { + req: &group.MsgUpdateGroupPolicyAdmin{ + Admin: admin.String(), + GroupPolicyAddress: groupPolicyAddr, + NewAdmin: "%s", + }, + expGroupPolicy: &group.GroupPolicyInfo{ + Admin: admin.String(), + Address: groupPolicyAddr, + GroupId: myGroupID, + Version: 2, + DecisionPolicy: nil, + CreatedAt: s.blockTime, + }, + expErr: true, + expErrMsg: "new admin address", + }, } for msg, spec := range specs { spec := spec