diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index bf03f9a10..b4504bdf8 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -76,14 +76,15 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage { } // Random genesis states + vp := time.Duration(r.Intn(2*172800)) * time.Second govGenesis := gov.GenesisState{ StartingProposalID: uint64(r.Intn(100)), DepositParams: gov.DepositParams{ MinDeposit: sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, int64(r.Intn(1e3)))}, - MaxDepositPeriod: time.Duration(r.Intn(2*172800)) * time.Second, + MaxDepositPeriod: vp, }, VotingParams: gov.VotingParams{ - VotingPeriod: time.Duration(r.Intn(2*172800)) * time.Second, + VotingPeriod: vp, }, TallyParams: gov.TallyParams{ Threshold: sdk.NewDecWithPrec(5, 1), diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 8498e3b5a..7a8fab0b6 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -1,6 +1,7 @@ package gov import ( + "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -61,6 +62,34 @@ func DefaultGenesisState() GenesisState { // ValidateGenesis TODO https://github.com/cosmos/cosmos-sdk/issues/3007 func ValidateGenesis(data GenesisState) error { + threshold := data.TallyParams.Threshold + if threshold.IsNegative() || threshold.GT(sdk.OneDec()) { + return fmt.Errorf("Governance vote threshold should be positive and less or equal to one, is %s", + threshold.String()) + } + + veto := data.TallyParams.Veto + if veto.IsNegative() || veto.GT(sdk.OneDec()) { + return fmt.Errorf("Governance vote veto threshold should be positive and less or equal to one, is %s", + veto.String()) + } + + govPenalty := data.TallyParams.GovernancePenalty + if govPenalty.IsNegative() || govPenalty.GT(sdk.OneDec()) { + return fmt.Errorf("Governance vote veto threshold should be positive and less or equal to one, is %s", + govPenalty.String()) + } + + if data.DepositParams.MaxDepositPeriod > data.VotingParams.VotingPeriod { + return fmt.Errorf("Governance deposit period should be less than or equal to the voting period (%ds), is %ds", + data.VotingParams.VotingPeriod, data.DepositParams.MaxDepositPeriod) + } + + if !data.DepositParams.MinDeposit.IsValid() { + return fmt.Errorf("Governance deposit amount must be a valid sdk.Coins amount, is %s", + data.DepositParams.MinDeposit.String()) + } + return nil }