fix(gov): don't export deprecated params (#14408)

This commit is contained in:
Julien Robert 2022-12-24 15:21:50 +01:00 committed by GitHub
parent 7cc1c351d2
commit bc46bbbec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 28 deletions

View File

@ -58,10 +58,6 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v1.GenesisState {
proposals := k.GetProposals(ctx)
params := k.GetParams(ctx)
depositParams := v1.NewDepositParams(params.MinDeposit, params.MaxDepositPeriod) //nolint:staticcheck
votingParams := v1.NewVotingParams(params.VotingPeriod) //nolint:staticcheck
tallyParams := v1.NewTallyParams(params.Quorum, params.Threshold, params.VetoThreshold) //nolint:staticcheck
var proposalsDeposits v1.Deposits
var proposalsVotes v1.Votes
for _, proposal := range proposals {
@ -77,9 +73,6 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v1.GenesisState {
Deposits: proposalsDeposits,
Votes: proposalsVotes,
Proposals: proposals,
DepositParams: &depositParams,
VotingParams: &votingParams,
TallyParams: &tallyParams,
Params: &params,
}
}

View File

@ -20,9 +20,28 @@ func TestMigrateJSON(t *testing.T) {
WithCodec(encodingConfig.Codec)
govGenState := v1.DefaultGenesisState()
oldGovState := &v1.GenesisState{
StartingProposalId: govGenState.StartingProposalId,
Deposits: govGenState.Deposits,
Votes: govGenState.Votes,
Proposals: govGenState.Proposals,
DepositParams: &v1.DepositParams{
MinDeposit: govGenState.Params.MinDeposit,
MaxDepositPeriod: govGenState.Params.MaxDepositPeriod,
},
VotingParams: &v1.VotingParams{
VotingPeriod: govGenState.Params.VotingPeriod,
},
TallyParams: &v1.TallyParams{
Quorum: govGenState.Params.Quorum,
Threshold: govGenState.Params.Threshold,
VetoThreshold: govGenState.Params.VetoThreshold,
},
}
migrated, err := v4.MigrateJSON(govGenState)
migrated, err := v4.MigrateJSON(oldGovState)
require.NoError(t, err)
require.Equal(t, migrated, govGenState)
bz, err := clientCtx.Codec.MarshalJSON(migrated)
require.NoError(t, err)

View File

@ -2,22 +2,14 @@ package v1
import (
"errors"
"fmt"
"github.com/cosmos/cosmos-sdk/codec/types"
)
// NewGenesisState creates a new genesis state for the governance module
func NewGenesisState(startingProposalID uint64, params Params) *GenesisState {
dp := NewDepositParams(params.MinDeposit, params.MaxDepositPeriod)
vp := NewVotingParams(params.VotingPeriod)
tp := NewTallyParams(params.Quorum, params.Threshold, params.VetoThreshold)
return &GenesisState{
StartingProposalId: startingProposalID,
DepositParams: &dp,
VotingParams: &vp,
TallyParams: &tp,
Params: &params,
}
}
@ -41,18 +33,6 @@ func ValidateGenesis(data *GenesisState) error {
return errors.New("starting proposal id must be greater than 0")
}
if err := validateTallyParams(*data.TallyParams); err != nil {
return fmt.Errorf("invalid tally params: %w", err)
}
if err := validateVotingParams(*data.VotingParams); err != nil {
return fmt.Errorf("invalid voting params: %w", err)
}
if err := validateDepositParams(*data.DepositParams); err != nil {
return fmt.Errorf("invalid deposit params: %w", err)
}
return data.Params.ValidateBasic()
}