Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (crypto) [#24414](https://github.com/cosmos/cosmos-sdk/pull/24414) Remove sr25519 support, since it was removed in CometBFT v1.x (see: CometBFT [#3646](https://github.com/cometbft/cometbft/pull/3646)).
* (x/gov) [#25615](https://github.com/cosmos/cosmos-sdk/pull/25615) Decouple `x/gov` from `x/staking` by making `CalculateVoteResultsAndVotingPowerFn` a required parameter to `keeper.NewKeeper` instead of `StakingKeeper`.
`BondedTokens` has been renamed to `ValidatorPower` and `TotalBondedTokens` has been renamed to `TotalValidatorPower` to allow for multiple validator power representations.
* (x/gov) [#25616](https://github.com/cosmos/cosmos-sdk/pull/25616) `DistrKeeper` `x/distribution` is now optional. Genesis validation ensures `distrKeeper` is set if distribution module is used as proposal cancel destination.

### Features

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/gov/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestImportExportQueues(t *testing.T) {
distributionGenState := s1.DistrKeeper.ExportGenesis(ctx)

// export the state and import it into a new app
govGenState, _ := gov.ExportGenesis(ctx, s1.GovKeeper)
govGenState, _ := keeper.ExportGenesis(ctx, s1.GovKeeper)
genesisState := s1.appBuilder.DefaultGenesis()

genesisState[authtypes.ModuleName] = s1.cdc.MustMarshalJSON(authGenState)
Expand Down
39 changes: 0 additions & 39 deletions x/gov/genesis_test.go

This file was deleted.

13 changes: 9 additions & 4 deletions x/gov/genesis.go → x/gov/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package gov
package keeper

import (
"fmt"

"cosmossdk.io/collections"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

// InitGenesis - store genesis parameters
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, data *v1.GenesisState) {
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k *Keeper, data *v1.GenesisState) {
err := k.ProposalID.Set(ctx, data.StartingProposalId)
if err != nil {
panic(err)
}

distrAddress := ak.GetModuleAddress(disttypes.ModuleName).String()
if data.Params.ProposalCancelDest == distrAddress && distrAddress != "" && k.distrKeeper == nil {
panic(fmt.Sprintf("must set DistrKeeper first if using distribution module (%s) as proposal cancel destination", distrAddress))
}

err = k.Params.Set(ctx, *data.Params)
if err != nil {
panic(err)
Expand Down Expand Up @@ -86,7 +91,7 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
}

// ExportGenesis - output genesis parameters
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) (*v1.GenesisState, error) {
func ExportGenesis(ctx sdk.Context, k *Keeper) (*v1.GenesisState, error) {
startingProposalID, err := k.ProposalID.Peek(ctx)
if err != nil {
return nil, err
Expand Down
36 changes: 36 additions & 0 deletions x/gov/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package keeper_test

import (
"go.uber.org/mock/gomock"

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

func (suite *KeeperTestSuite) TestImportExportQueues_ErrorUnconsistentState() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up item should be to test this function more thoroughly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suite.reset()
suite.acctKeeper.EXPECT().SetModuleAccount(suite.ctx, gomock.Any()).AnyTimes()
suite.Require().Panics(func() {
keeper.InitGenesis(suite.ctx, suite.acctKeeper, suite.bankKeeper, suite.govKeeper, &v1.GenesisState{
Deposits: v1.Deposits{
{
ProposalId: 1234,
Depositor: "me",
Amount: sdk.Coins{
sdk.NewCoin(
"stake",
sdkmath.NewInt(1234),
),
},
},
},
})
})
keeper.InitGenesis(suite.ctx, suite.acctKeeper, suite.bankKeeper, suite.govKeeper, v1.DefaultGenesisState())
genState, err := keeper.ExportGenesis(suite.ctx, suite.govKeeper)
suite.Require().NoError(err)
suite.Require().Equal(genState, v1.DefaultGenesisState())
}
4 changes: 2 additions & 2 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
var genesisState v1.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, &genesisState)
keeper.InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, &genesisState)
}

// ExportGenesis returns the exported genesis state as raw bytes for the gov
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
gs, err := ExportGenesis(ctx, am.keeper)
gs, err := keeper.ExportGenesis(ctx, am.keeper)
if err != nil {
panic(err)
}
Expand Down
Loading