Skip to content

Commit

Permalink
add params test
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 17, 2023
1 parent b7de1fc commit 7f01974
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
11 changes: 11 additions & 0 deletions x/gov/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
70 changes: 70 additions & 0 deletions x/gov/types/params_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 7f01974

Please sign in to comment.