From 18a816284a5ac0bd397ca483c8464bdbf0cc54bb Mon Sep 17 00:00:00 2001 From: Marie Gauthier Date: Mon, 14 Mar 2022 16:52:07 +0100 Subject: [PATCH] fix: Fix group simulations (#11347) ## Description It seems like https://github.com/cosmos/cosmos-sdk/pull/10887 broke group simulations, fixing them here. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- x/group/keeper/invariants.go | 2 +- x/group/simulation/operations.go | 10 +++++----- x/group/simulation/operations_test.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/group/keeper/invariants.go b/x/group/keeper/invariants.go index 221257348..1d222e91d 100644 --- a/x/group/keeper/invariants.go +++ b/x/group/keeper/invariants.go @@ -167,6 +167,7 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g msg += fmt.Sprintf("error while returning group member iterator for group with ID %d\n%v\n", groupInfo.Id, err) return msg, broken } + defer memIt.Close() for { _, err = memIt.LoadNext(&groupMember) @@ -184,7 +185,6 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g return msg, broken } } - memIt.Close() groupWeight, err := groupmath.NewNonNegativeDecFromString(groupInfo.GetTotalWeight()) if err != nil { diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index 43d5da6ed..22ac6138c 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -67,7 +67,7 @@ const ( WeightMsgSubmitProposal = 90 WeightMsgVote = 90 WeightMsgExec = 90 - WeightMsgLeaveGroup = 20 + WeightMsgLeaveGroup = 5 WeightMsgUpdateGroupMetadata = 5 WeightMsgUpdateGroupAdmin = 5 WeightMsgUpdateGroupMembers = 5 @@ -188,10 +188,6 @@ func WeightedOperations( weightMsgCreateGroupPolicy, SimulateMsgCreateGroupPolicy(ak, bk, k), ), - simulation.NewWeightedOperation( - weightMsgLeaveGroup, - SimulateMsgLeaveGroup(k, ak, bk), - ), simulation.NewWeightedOperation( weightMsgCreateGroupWithPolicy, SimulateMsgCreateGroupWithPolicy(ak, bk), @@ -235,6 +231,10 @@ func WeightedOperations( weightMsgUpdateGroupPolicyMetadata, SimulateMsgUpdateGroupPolicyMetadata(ak, bk, k), ), + simulation.NewWeightedOperation( + weightMsgLeaveGroup, + SimulateMsgLeaveGroup(k, ak, bk), + ), } return append(wPreCreateProposalOps, append(createProposalOps, wPostCreateProposalOps...)...) diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index b1981d793..12f476b88 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -53,7 +53,6 @@ func (suite *SimTestSuite) TestWeightedOperations() { }{ {simulation.WeightMsgCreateGroup, group.MsgCreateGroup{}.Route(), simulation.TypeMsgCreateGroup}, {simulation.WeightMsgCreateGroupPolicy, group.MsgCreateGroupPolicy{}.Route(), simulation.TypeMsgCreateGroupPolicy}, - {simulation.WeightMsgLeaveGroup, group.MsgLeaveGroup{}.Route(), simulation.TypeMsgLeaveGroup}, {simulation.WeightMsgCreateGroupWithPolicy, group.MsgCreateGroupWithPolicy{}.Route(), simulation.TypeMsgCreateGroupWithPolicy}, {simulation.WeightMsgSubmitProposal, group.MsgSubmitProposal{}.Route(), simulation.TypeMsgSubmitProposal}, {simulation.WeightMsgSubmitProposal, group.MsgSubmitProposal{}.Route(), simulation.TypeMsgSubmitProposal}, @@ -66,6 +65,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { {simulation.WeightMsgUpdateGroupPolicyAdmin, group.MsgUpdateGroupPolicyAdmin{}.Route(), simulation.TypeMsgUpdateGroupPolicyAdmin}, {simulation.WeightMsgUpdateGroupPolicyDecisionPolicy, group.MsgUpdateGroupPolicyDecisionPolicy{}.Route(), simulation.TypeMsgUpdateGroupPolicyDecisionPolicy}, {simulation.WeightMsgUpdateGroupPolicyMetadata, group.MsgUpdateGroupPolicyMetadata{}.Route(), simulation.TypeMsgUpdateGroupPolicyMetadata}, + {simulation.WeightMsgLeaveGroup, group.MsgLeaveGroup{}.Route(), simulation.TypeMsgLeaveGroup}, } for i, w := range weightedOps {