From 7b12cdfb85018d4fc14125b34811ad61b28054cb Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:38:25 +0900 Subject: [PATCH] add genesis test --- x/gov/types/genesis_test.go | 110 ++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 x/gov/types/genesis_test.go diff --git a/x/gov/types/genesis_test.go b/x/gov/types/genesis_test.go new file mode 100644 index 00000000..2c0311dc --- /dev/null +++ b/x/gov/types/genesis_test.go @@ -0,0 +1,110 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + + "github.com/initia-labs/initia/x/gov/types" +) + +func TestEmptyGenesis(t *testing.T) { + state1 := types.GenesisState{} + require.True(t, state1.Empty()) + + state2 := types.DefaultGenesisState() + require.False(t, state2.Empty()) +} + +func TestValidateGenesis(t *testing.T) { + params := types.DefaultParams() + + testCases := []struct { + name string + genesisState func() *types.GenesisState + expErr bool + }{ + { + name: "valid", + genesisState: func() *types.GenesisState { + return types.NewGenesisState(v1.DefaultStartingProposalID, params, time.Now().UTC()) + }, + }, + { + name: "invalid StartingProposalId", + genesisState: func() *types.GenesisState { + return types.NewGenesisState(0, params, time.Now().UTC()) + }, + expErr: true, + }, + { + name: "invalid min deposit", + genesisState: func() *types.GenesisState { + params1 := params + params1.MinDeposit = sdk.Coins{{ + Denom: sdk.DefaultBondDenom, + Amount: sdk.NewInt(-100), + }} + + return types.NewGenesisState(0, params1, time.Now().UTC()) + }, + expErr: true, + }, + { + name: "invalid max deposit period", + genesisState: func() *types.GenesisState { + params1 := params + params1.MaxDepositPeriod = 0 + + return types.NewGenesisState(0, params1, time.Now().UTC()) + }, + expErr: true, + }, + { + name: "invalid quorum", + genesisState: func() *types.GenesisState { + params1 := params + params1.Quorum = "2" + + return types.NewGenesisState(0, params1, time.Now().UTC()) + }, + expErr: true, + }, + { + name: "invalid threshold", + genesisState: func() *types.GenesisState { + params1 := params + params1.Threshold = "2" + + return types.NewGenesisState(0, params1, time.Now().UTC()) + }, + expErr: true, + }, + { + name: "invalid veto threshold", + genesisState: func() *types.GenesisState { + params1 := params + params1.VetoThreshold = "2" + + return types.NewGenesisState(0, params1, time.Now().UTC()) + }, + expErr: true, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := types.ValidateGenesis(tc.genesisState()) + if tc.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +}