Skip to content

Commit

Permalink
refactor(x/group): check the new admin address when updating the grou…
Browse files Browse the repository at this point in the history
…p policy admin (backport #18350) (#18352)

Co-authored-by: Luke Ma <lukema95@gmail.com>
  • Loading branch information
mergify[bot] and lukema95 authored Nov 3, 2023
1 parent 7907810 commit f6d4b2e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x/group/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions x/group/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f6d4b2e

Please sign in to comment.