diff --git a/x/gov/types/params.go b/x/gov/types/params.go index c199076a..089ca415 100644 --- a/x/gov/types/params.go +++ b/x/gov/types/params.go @@ -118,6 +118,17 @@ func (p Params) ValidateBasic() error { return fmt.Errorf("veto threshold too large: %s", vetoThreshold) } + minInitialDepositRatio, err := sdk.NewDecFromStr(p.MinInitialDepositRatio) + if err != nil { + return fmt.Errorf("invalid minInitialDepositRatio string: %w", err) + } + if minInitialDepositRatio.IsNegative() { + return fmt.Errorf("min initial deposit ratio must be zero or positive: %s", minInitialDepositRatio) + } + if minInitialDepositRatio.GT(math.LegacyOneDec()) { + return fmt.Errorf("min initial deposit ratio too large: %s", minInitialDepositRatio) + } + if p.VotingPeriod.Seconds() <= 0 { return fmt.Errorf("voting period must be positive: %s", p.VotingPeriod) } diff --git a/x/gov/types/params_test.go b/x/gov/types/params_test.go new file mode 100644 index 00000000..c727b7ed --- /dev/null +++ b/x/gov/types/params_test.go @@ -0,0 +1,70 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/initia-labs/initia/x/gov/types" +) + +func Test_Params(t *testing.T) { + params := types.DefaultParams() + require.NoError(t, params.ValidateBasic()) + + _emergencyMinDeposit := params.EmergencyMinDeposit + params.EmergencyMinDeposit = []sdk.Coin{{ + Denom: "foo", + Amount: sdk.NewInt(-1), + }} + require.Error(t, params.ValidateBasic()) + + params.EmergencyMinDeposit = _emergencyMinDeposit + + _minDeposit := params.MinDeposit + params.MinDeposit = []sdk.Coin{{ + Denom: "foo", + Amount: sdk.NewInt(-1), + }} + require.Error(t, params.ValidateBasic()) + + params.MinDeposit = _minDeposit + + _maxDepositPeriod := params.MaxDepositPeriod + params.MaxDepositPeriod = 0 + require.Error(t, params.ValidateBasic()) + + params.MaxDepositPeriod = _maxDepositPeriod + + _minInitialDepositRatio := params.MinInitialDepositRatio + params.MinInitialDepositRatio = "-1" + require.Error(t, params.ValidateBasic()) + + params.MinInitialDepositRatio = _minInitialDepositRatio + + _quorum := params.Quorum + params.Quorum = "-1" + require.Error(t, params.ValidateBasic()) + + params.Quorum = _quorum + + _threshold := params.Threshold + params.Threshold = "-1" + require.Error(t, params.ValidateBasic()) + + params.Threshold = _threshold + + _vetoThreshold := params.VetoThreshold + params.VetoThreshold = "-1" + require.Error(t, params.ValidateBasic()) + + params.VetoThreshold = _vetoThreshold + + _votingPeriod := params.VotingPeriod + params.VotingPeriod = 0 + require.Error(t, params.ValidateBasic()) + + params.VotingPeriod = _votingPeriod + require.NoError(t, params.ValidateBasic()) +}