refactor(x/group): check the new admin address when updating the group policy admin (backport #18350) (#18352)

Co-authored-by: Luke Ma <lukema95@gmail.com>
This commit is contained in:
mergify[bot] 2023-11-03 09:56:42 +00:00 committed by GitHub
parent 790781009d
commit f6d4b2e838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -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