Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(group): Allow group total weight to be 0 #11682

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/group/keeper/invariants.go
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g
}
}

groupWeight, err := groupmath.NewPositiveDecFromString(groupInfo.GetTotalWeight())
groupWeight, err := groupmath.NewNonNegativeDecFromString(groupInfo.GetTotalWeight())
if err != nil {
msg += fmt.Sprintf("error while parsing non-nengative decimal for group with ID %d\n%v\n", groupInfo.Id, err)
return msg, broken
2 changes: 1 addition & 1 deletion x/group/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -2753,7 +2753,7 @@ func (s *TestSuite) TestLeaveGroup() {
math.NewDecFromInt64(0),
},
{
"valid testcase: decision policy is not present",
"valid testcase: decision policy is not present (and group total weight can be 0)",
&group.MsgLeaveGroup{
GroupId: groupID2,
Address: member1.String(),
6 changes: 3 additions & 3 deletions x/group/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -97,9 +97,9 @@ func (k Keeper) CreateGroup(goCtx context.Context, req *group.MsgCreateGroup) (*
func (k Keeper) UpdateGroupMembers(goCtx context.Context, req *group.MsgUpdateGroupMembers) (*group.MsgUpdateGroupMembersResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
action := func(g *group.GroupInfo) error {
totalWeight, err := math.NewPositiveDecFromString(g.TotalWeight)
totalWeight, err := math.NewNonNegativeDecFromString(g.TotalWeight)
if err != nil {
return err
return sdkerrors.Wrap(err, "group total weight")
}
for i := range req.MemberUpdates {
if err := k.assertMetadataLength(req.MemberUpdates[i].Metadata, "group member metadata"); err != nil {
@@ -800,7 +800,7 @@ func (k Keeper) LeaveGroup(goCtx context.Context, req *group.MsgLeaveGroup) (*gr
return nil, sdkerrors.Wrap(err, "group")
}

groupWeight, err := math.NewPositiveDecFromString(groupInfo.TotalWeight)
groupWeight, err := math.NewNonNegativeDecFromString(groupInfo.TotalWeight)
if err != nil {
return nil, err
}