refactor: move x/auth, x/authz, x/slashing and x/mint Init/Export genesis to keeper (#11871)

This commit is contained in:
likhita-809
2022-05-04 12:50:33 -04:00
committed by GitHub
parent 710b57c0fb
commit 6e18f582bf
10 changed files with 73 additions and 71 deletions
@@ -1,15 +1,14 @@
package slashing
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/keeper"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
// InitGenesis initialize default parameters
// and the keeper's address to pubkey map
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.StakingKeeper, data *types.GenesisState) {
func (keeper Keeper) InitGenesis(ctx sdk.Context, stakingKeeper types.StakingKeeper, data *types.GenesisState) {
stakingKeeper.IterateValidators(ctx,
func(index int64, validator stakingtypes.ValidatorI) bool {
consPk, err := validator.ConsPubKey()
@@ -45,7 +44,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.Stak
// ExportGenesis writes the current store values
// to a genesis file, which can be imported again
// with InitGenesis
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisState) {
func (keeper Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) {
params := keeper.GetParams(ctx)
signingInfos := make([]types.SigningInfo, 0)
missedBlocks := make([]types.ValidatorMissedBlocks, 0)
@@ -1,4 +1,4 @@
package slashing_test
package keeper_test
import (
"testing"
@@ -9,7 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/slashing/testslashing"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)
@@ -29,7 +28,7 @@ func TestExportAndInitGenesis(t *testing.T) {
app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), info1)
app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1]), info2)
genesisState := slashing.ExportGenesis(ctx, app.SlashingKeeper)
genesisState := app.SlashingKeeper.ExportGenesis(ctx)
require.Equal(t, genesisState.Params, testslashing.TestParams())
require.Len(t, genesisState.SigningInfos, 2)
@@ -45,7 +44,8 @@ func TestExportAndInitGenesis(t *testing.T) {
newInfo1, ok := app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]))
require.NotEqual(t, info1, newInfo1)
// Initialise genesis with genesis state before tombstone
slashing.InitGenesis(ctx, app.SlashingKeeper, app.StakingKeeper, genesisState)
app.SlashingKeeper.InitGenesis(ctx, app.StakingKeeper, genesisState)
// Validator isTombstoned should return false as GenesisState is initialised
ok = app.SlashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[0]))
+2 -2
View File
@@ -142,14 +142,14 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.keeper, am.stakingKeeper, &genesisState)
am.keeper.InitGenesis(ctx, am.stakingKeeper, &genesisState)
return []abci.ValidatorUpdate{}
}
// ExportGenesis returns the exported genesis state as raw bytes for the slashing
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
gs := ExportGenesis(ctx, am.keeper)
gs := am.keeper.ExportGenesis(ctx)
return cdc.MustMarshalJSON(gs)
}