Skip to content

Commit

Permalink
Merge branch 'tip/auth/use_x_tx' of https://github.com/cosmos/cosmos-sdk
Browse files Browse the repository at this point in the history
 into tip/auth/use_x_tx
  • Loading branch information
facundomedica committed Feb 20, 2024
2 parents 944ed5b + e879571 commit d725e5f
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 219 deletions.
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func NewSimApp(
config.MaxProposalTitleLen = 255 // example max title length in characters
config.MaxProposalSummaryLen = 10200 // example max summary length in characters
*/
app.GroupKeeper = groupkeeper.NewKeeper(runtime.NewKVStoreService(keys[group.StoreKey]), appCodec, app.MsgServiceRouter(), app.AuthKeeper, groupConfig)
app.GroupKeeper = groupkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[group.StoreKey]), logger), appCodec, app.MsgServiceRouter(), app.AuthKeeper, groupConfig)

// get skipUpgradeHeights from the app options
skipUpgradeHeights := map[int64]bool{}
Expand Down
1 change: 1 addition & 0 deletions x/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* [#19489](https://github.com/cosmos/cosmos-sdk/pull/19489) `appmodule.Environment` is received on the Keeper to get access to different application services.
* [#19410](https://github.com/cosmos/cosmos-sdk/pull/19410) Migrate to Store Service.
15 changes: 15 additions & 0 deletions x/group/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package keeper

import (
"context"
)

// EndBlocker called at every block, updates proposal's `FinalTallyResult` and
// prunes expired proposals.
func (k Keeper) EndBlocker(ctx context.Context) error {
if err := k.TallyProposalsAtVPEnd(ctx, k.environment); err != nil {
return err
}

return k.PruneProposals(ctx, k.environment)
}
47 changes: 23 additions & 24 deletions x/group/module/abci_test.go → x/group/keeper/abci_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package module_test
package keeper_test

import (
"context"
Expand All @@ -17,7 +17,6 @@ import (
banktypes "cosmossdk.io/x/bank/types"
"cosmossdk.io/x/group"
"cosmossdk.io/x/group/keeper"
"cosmossdk.io/x/group/module"
grouptestutil "cosmossdk.io/x/group/testutil"
stakingkeeper "cosmossdk.io/x/staking/keeper"

Expand Down Expand Up @@ -164,7 +163,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
"proposal pruned after executor result success": {
setupProposal: func(ctx sdk.Context) uint64 {
msgs := []sdk.Msg{msgSend1}
pID, err := submitProposalAndVote(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
pID, err := submitProposalAndVoteHelper(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
s.Require().NoError(err)
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
Expand All @@ -179,7 +178,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
"proposal with multiple messages pruned when executed with result success": {
setupProposal: func(ctx sdk.Context) uint64 {
msgs := []sdk.Msg{msgSend1, msgSend1}
pID, err := submitProposalAndVote(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
pID, err := submitProposalAndVoteHelper(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
s.Require().NoError(err)
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
Expand All @@ -194,7 +193,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
"proposal not pruned when not executed and rejected": {
setupProposal: func(ctx sdk.Context) uint64 {
msgs := []sdk.Msg{msgSend1}
pID, err := submitProposalAndVote(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_NO)
pID, err := submitProposalAndVoteHelper(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_NO)
s.Require().NoError(err)
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
Expand All @@ -209,7 +208,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
},
"open proposal is not pruned which must not fail ": {
setupProposal: func(ctx sdk.Context) uint64 {
pID, err := submitProposal(s, s.app, ctx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
pID, err := submitProposalHelper(s, s.app, ctx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
s.Require().NoError(err)
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
Expand All @@ -223,7 +222,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
},
"proposal not pruned with group policy modified before tally": {
setupProposal: func(ctx sdk.Context) uint64 {
pID, err := submitProposal(s, s.app, ctx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
pID, err := submitProposalHelper(s, s.app, ctx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
s.Require().NoError(err)
_, err = s.groupKeeper.UpdateGroupPolicyMetadata(ctx, &group.MsgUpdateGroupPolicyMetadata{
Admin: addr1.String(),
Expand All @@ -243,7 +242,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
"pruned when proposal is executable when failed before": {
setupProposal: func(ctx sdk.Context) uint64 {
msgs := []sdk.Msg{msgSend1}
pID, err := submitProposalAndVote(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
pID, err := submitProposalAndVoteHelper(s, s.app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
s.Require().NoError(err)
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: s.addrs[2].String(), ProposalId: pID})
s.Require().NoError(err)
Expand All @@ -255,7 +254,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
},
"proposal with status withdrawn is pruned after voting period end": {
setupProposal: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposal(s, s.app, sdkCtx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
pID, err := submitProposalHelper(s, s.app, sdkCtx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
s.Require().NoError(err)
_, err = s.groupKeeper.WithdrawProposal(ctx, &group.MsgWithdrawProposal{
ProposalId: pID,
Expand All @@ -270,7 +269,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
},
"proposal with status withdrawn is not pruned (before voting period)": {
setupProposal: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposal(s, s.app, sdkCtx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
pID, err := submitProposalHelper(s, s.app, sdkCtx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
s.Require().NoError(err)
_, err = s.groupKeeper.WithdrawProposal(ctx, &group.MsgWithdrawProposal{
ProposalId: pID,
Expand All @@ -286,7 +285,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
},
"proposal with status aborted is pruned after voting period end (due to updated group policy decision policy)": {
setupProposal: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposal(s, s.app, sdkCtx, []sdk.Msg{msgSend2}, proposers, groupPolicyAddr2)
pID, err := submitProposalHelper(s, s.app, sdkCtx, []sdk.Msg{msgSend2}, proposers, groupPolicyAddr2)
s.Require().NoError(err)

policy := group.NewThresholdDecisionPolicy("3", time.Second, 0)
Expand All @@ -308,7 +307,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
},
"proposal with status aborted is not pruned before voting period end (due to updated group policy)": {
setupProposal: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposal(s, s.app, sdkCtx, []sdk.Msg{msgSend2}, proposers, groupPolicyAddr2)
pID, err := submitProposalHelper(s, s.app, sdkCtx, []sdk.Msg{msgSend2}, proposers, groupPolicyAddr2)
s.Require().NoError(err)

policy := group.NewThresholdDecisionPolicy("3", time.Second, 0)
Expand All @@ -334,7 +333,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
s.Run(msg, func() {
proposalID := spec.setupProposal(ctx)

err := module.EndBlocker(spec.newCtx, s.groupKeeper)
err := s.groupKeeper.EndBlocker(spec.newCtx)
s.Require().NoError(err)

if spec.expErrMsg != "" && spec.expExecutorResult != group.PROPOSAL_EXECUTOR_RESULT_SUCCESS {
Expand Down Expand Up @@ -426,7 +425,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
}{
"tally updated after voting period end": {
preRun: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposal(s, app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
pID, err := submitProposalHelper(s, app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
s.Require().NoError(err)
return pID
},
Expand All @@ -437,7 +436,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
},
"tally within voting period": {
preRun: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposal(s, app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
pID, err := submitProposalHelper(s, app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
s.Require().NoError(err)

return pID
Expand All @@ -449,7 +448,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
},
"tally within voting period(with votes)": {
preRun: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposalAndVote(s, app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
pID, err := submitProposalAndVoteHelper(s, app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
s.Require().NoError(err)

return pID
Expand All @@ -462,7 +461,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
"tally after voting period (not passing)": {
preRun: func(sdkCtx sdk.Context) uint64 {
// `addrs[1]` has weight 1
pID, err := submitProposalAndVote(s, app, ctx, []sdk.Msg{msgSend}, []string{addrs[1].String()}, groupPolicyAddr, group.VOTE_OPTION_YES)
pID, err := submitProposalAndVoteHelper(s, app, ctx, []sdk.Msg{msgSend}, []string{addrs[1].String()}, groupPolicyAddr, group.VOTE_OPTION_YES)
s.Require().NoError(err)

return pID
Expand All @@ -479,7 +478,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
},
"tally after voting period(with votes)": {
preRun: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposalAndVote(s, app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
pID, err := submitProposalAndVoteHelper(s, app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
s.Require().NoError(err)

return pID
Expand All @@ -496,7 +495,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
},
"tally of withdrawn proposal": {
preRun: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposal(s, app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
pID, err := submitProposalHelper(s, app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
s.Require().NoError(err)

_, err = s.groupKeeper.WithdrawProposal(ctx, &group.MsgWithdrawProposal{
Expand All @@ -514,7 +513,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
},
"tally of withdrawn proposal (with votes)": {
preRun: func(sdkCtx sdk.Context) uint64 {
pID, err := submitProposalAndVote(s, app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
pID, err := submitProposalAndVoteHelper(s, app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
s.Require().NoError(err)

_, err = s.groupKeeper.WithdrawProposal(ctx, &group.MsgWithdrawProposal{
Expand All @@ -537,7 +536,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
spec := spec
pID := spec.preRun(ctx)

err := module.EndBlocker(spec.newCtx, s.groupKeeper)
err := s.groupKeeper.EndBlocker(spec.newCtx)
s.Require().NoError(err)
resp, err := s.groupKeeper.Proposal(spec.newCtx, &group.QueryProposalRequest{
ProposalId: pID,
Expand All @@ -556,7 +555,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
}
}

func submitProposal(s *IntegrationTestSuite, app *runtime.App, ctx context.Context, msgs []sdk.Msg, proposers []string, groupPolicyAddr sdk.AccAddress) (uint64, error) {
func submitProposalHelper(s *IntegrationTestSuite, app *runtime.App, ctx context.Context, msgs []sdk.Msg, proposers []string, groupPolicyAddr sdk.AccAddress) (uint64, error) {
proposalReq := &group.MsgSubmitProposal{
GroupPolicyAddress: groupPolicyAddr.String(),
Proposers: proposers,
Expand All @@ -574,11 +573,11 @@ func submitProposal(s *IntegrationTestSuite, app *runtime.App, ctx context.Conte
return proposalRes.ProposalId, nil
}

func submitProposalAndVote(
func submitProposalAndVoteHelper(
s *IntegrationTestSuite, app *runtime.App, ctx context.Context, msgs []sdk.Msg,
proposers []string, groupPolicyAddr sdk.AccAddress, voteOption group.VoteOption,
) (uint64, error) {
myProposalID, err := submitProposal(s, app, ctx, msgs, proposers, groupPolicyAddr)
myProposalID, err := submitProposalHelper(s, app, ctx, msgs, proposers, groupPolicyAddr)
if err != nil {
return 0, err
}
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 @@ -17,7 +17,7 @@ func (k Keeper) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.
var genesisState group.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)

store := k.storeService.OpenKVStore(ctx)
store := k.environment.KVStoreService.OpenKVStore(ctx)

if err := k.groupTable.Import(store, genesisState.Groups, genesisState.GroupSeq); err != nil {
panic(errors.Wrap(err, "groups"))
Expand Down Expand Up @@ -52,7 +52,7 @@ func (k Keeper) ExportGenesis(ctx context.Context, _ codec.JSONCodec) *group.Gen

var groups []*group.GroupInfo

store := k.storeService.OpenKVStore(ctx)
store := k.environment.KVStoreService.OpenKVStore(ctx)

groupSeq, err := k.groupTable.Export(store, &groups)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion x/group/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (s *GenesisTestSuite) SetupTest() {
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{})
env := runtime.NewEnvironment(storeService, log.NewNopLogger())

ctrl := gomock.NewController(s.T())
accountKeeper := grouptestutil.NewMockAccountKeeper(ctrl)
Expand All @@ -73,7 +74,7 @@ func (s *GenesisTestSuite) SetupTest() {
s.cdc = codec.NewProtoCodec(encCfg.InterfaceRegistry)
s.ctx = s.sdkCtx

s.keeper = keeper.NewKeeper(storeService, s.cdc, bApp.MsgServiceRouter(), accountKeeper, group.DefaultConfig())
s.keeper = keeper.NewKeeper(env, s.cdc, bApp.MsgServiceRouter(), accountKeeper, group.DefaultConfig())
}

func (s *GenesisTestSuite) TestInitExportGenesis() {
Expand Down
Loading

0 comments on commit d725e5f

Please sign in to comment.