Skip to content

Commit

Permalink
add genesis test
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 17, 2023
1 parent 67aae27 commit 7b12cdf
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions x/gov/types/genesis_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}

0 comments on commit 7b12cdf

Please sign in to comment.