Skip to content

Commit

Permalink
feat: Add simulations to group module (#10723)
Browse files Browse the repository at this point in the history
## Description

Closes: #9901



---

### 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))
- [x] 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)
- [x] 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`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] 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)
  • Loading branch information
blushi committed Jan 21, 2022
1 parent fd5b97b commit f52d870
Show file tree
Hide file tree
Showing 21 changed files with 2,215 additions and 192 deletions.
142 changes: 70 additions & 72 deletions api/cosmos/group/v1beta1/genesis.pulsar.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion api/cosmos/orm/v1alpha1/orm.pulsar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,8 @@ type SecondaryIndexDescriptor struct {
// store the remaining primary key fields in the value..
Fields string `protobuf:"bytes,1,opt,name=fields,proto3" json:"fields,omitempty"`
// id is a non-zero integer ID that must be unique within the indexes for this
// table. It may be deprecated in the future when this can be auto-generated.
// table and less than 32768. It may be deprecated in the future when this can
// be auto-generated.
Id uint32 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
// unique specifies that this an unique index.
Unique bool `protobuf:"varint,3,opt,name=unique,proto3" json:"unique,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ=
github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down
4 changes: 2 additions & 2 deletions proto/cosmos/group/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ message GenesisState {
// group_members is the list of groups members.
repeated GroupMember group_members = 3;

// group_policy_account_seq is the group policy table orm.Sequence,
// group_policy_seq is the group policy table orm.Sequence,
// it is used to generate the next group policy account address.
uint64 group_policy_account_seq = 4;
uint64 group_policy_seq = 4;

// group_policies is the list of group policies info.
repeated GroupPolicyInfo group_policies = 5;
Expand Down
69 changes: 34 additions & 35 deletions x/group/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/group/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestGenesisStateValidate(t *testing.T) {
GroupSeq: 2,
Groups: []*GroupInfo{{GroupId: 1, Admin: accAddr.String(), Metadata: []byte("1"), Version: 1, TotalWeight: "1"}, {GroupId: 2, Admin: accAddr.String(), Metadata: []byte("2"), Version: 2, TotalWeight: "2"}},
GroupMembers: []*GroupMember{{GroupId: 1, Member: &Member{Address: memberAddr.String(), Weight: "1", Metadata: []byte("member metadata")}}, {GroupId: 2, Member: &Member{Address: memberAddr.String(), Weight: "2", Metadata: []byte("member metadata")}}},
GroupPolicyAccountSeq: 1,
GroupPolicySeq: 1,
GroupPolicies: []*GroupPolicyInfo{groupPolicy},
ProposalSeq: 1,
Proposals: []*Proposal{proposal},
Expand Down
4 changes: 2 additions & 2 deletions x/group/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (k Keeper) InitGenesis(ctx types.Context, cdc codec.JSONCodec, data json.Ra
panic(errors.Wrap(err, "group policies"))
}

if err := k.groupPolicySeq.InitVal(ctx.KVStore(k.key), genesisState.GroupPolicyAccountSeq); err != nil {
if err := k.groupPolicySeq.InitVal(ctx.KVStore(k.key), genesisState.GroupPolicySeq); err != nil {
panic(errors.Wrap(err, "group policy account seq"))
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func (k Keeper) ExportGenesis(ctx types.Context, cdc codec.JSONCodec) *group.Gen
panic(errors.Wrap(err, "group policies"))
}
genesisState.GroupPolicies = groupPolicies
genesisState.GroupPolicyAccountSeq = k.groupPolicySeq.CurVal(ctx.KVStore(k.key))
genesisState.GroupPolicySeq = k.groupPolicySeq.CurVal(ctx.KVStore(k.key))

var proposals []*group.Proposal
proposalSeq, err := k.proposalTable.Export(ctx.KVStore(k.key), &proposals)
Expand Down
4 changes: 2 additions & 2 deletions x/group/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s *GenesisTestSuite) TestInitExportGenesis() {
GroupSeq: 2,
Groups: []*group.GroupInfo{{GroupId: 1, Admin: accAddr.String(), Metadata: []byte("1"), Version: 1, TotalWeight: "1"}, {GroupId: 2, Admin: accAddr.String(), Metadata: []byte("2"), Version: 2, TotalWeight: "2"}},
GroupMembers: []*group.GroupMember{{GroupId: 1, Member: &group.Member{Address: memberAddr.String(), Weight: "1", Metadata: []byte("member metadata")}}, {GroupId: 2, Member: &group.Member{Address: memberAddr.String(), Weight: "2", Metadata: []byte("member metadata")}}},
GroupPolicyAccountSeq: 1,
GroupPolicySeq: 1,
GroupPolicies: []*group.GroupPolicyInfo{groupPolicy},
ProposalSeq: 1,
Proposals: []*group.Proposal{proposal},
Expand Down Expand Up @@ -189,7 +189,7 @@ func (s *GenesisTestSuite) TestInitExportGenesis() {
s.Require().Equal(genesisState.Votes, exportedGenesisState.Votes)

s.Require().Equal(genesisState.GroupSeq, exportedGenesisState.GroupSeq)
s.Require().Equal(genesisState.GroupPolicyAccountSeq, exportedGenesisState.GroupPolicyAccountSeq)
s.Require().Equal(genesisState.GroupPolicySeq, exportedGenesisState.GroupPolicySeq)
s.Require().Equal(genesisState.ProposalSeq, exportedGenesisState.ProposalSeq)

}
Expand Down
5 changes: 5 additions & 0 deletions x/group/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,8 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router *authmiddle
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", group.ModuleName))
}

// GetGroupSequence returns the current value of the group table sequence
func (k Keeper) GetGroupSequence(ctx sdk.Context) uint64 {
return k.groupTable.Sequence().CurVal(ctx.KVStore(k.key))
}
2 changes: 1 addition & 1 deletion x/group/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (k Keeper) UpdateGroupMembers(goCtx context.Context, req *group.MsgUpdateGr
},
}

// Checking if the group member is already part of the
// Checking if the group member is already part of the group
var found bool
var prevGroupMember group.GroupMember
switch err := k.groupMemberTable.GetOne(ctx.KVStore(k.key), orm.PrimaryKey(&groupMember), &prevGroupMember); {
Expand Down
27 changes: 16 additions & 11 deletions x/group/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/group"
"github.com/cosmos/cosmos-sdk/x/group/client/cli"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
"github.com/cosmos/cosmos-sdk/x/group/keeper"
"github.com/cosmos/cosmos-sdk/x/group/simulation"
)

var (
Expand All @@ -30,19 +31,19 @@ var (

type AppModule struct {
AppModuleBasic
keeper groupkeeper.Keeper
BankKeeper group.BankKeeper
AccountKeeper group.AccountKeeper
registry cdctypes.InterfaceRegistry
keeper keeper.Keeper
bankKeeper group.BankKeeper
accKeeper group.AccountKeeper
registry cdctypes.InterfaceRegistry
}

// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper groupkeeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule {
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
BankKeeper: bk,
AccountKeeper: ak,
bankKeeper: bk,
accKeeper: ak,
registry: registry,
}
}
Expand Down Expand Up @@ -107,7 +108,7 @@ func (AppModule) Name() string {

// RegisterInvariants does nothing, there are no invariants to enforce
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
groupkeeper.RegisterInvariants(ir, am.keeper)
keeper.RegisterInvariants(ir, am.keeper)
}

// Deprecated: Route returns the message routing key for the group module.
Expand Down Expand Up @@ -164,6 +165,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val

// GenerateGenesisState creates a randomized GenState of the group module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}

// ProposalContents returns all the group content functions used to
Expand All @@ -179,10 +181,13 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {

// RegisterStoreDecoder registers a decoder for group module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
sdr[group.StoreKey] = simulation.NewDecodeStore(am.cdc)
}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
// TODO
return nil
return simulation.WeightedOperations(
simState.AppParams, simState.Cdc,
am.accKeeper, am.bankKeeper, am.keeper, am.cdc,
)
}

0 comments on commit f52d870

Please sign in to comment.