0g-chain/x/committee/genesis_test.go

77 lines
1.6 KiB
Go
Raw Normal View History

2020-03-15 00:00:05 +00:00
package committee_test
import (
"testing"
"github.com/stretchr/testify/suite"
2020-04-30 14:23:41 +00:00
2020-03-15 00:00:05 +00:00
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/committee"
"github.com/kava-labs/kava/x/committee/types"
)
type GenesisTestSuite struct {
suite.Suite
app app.TestApp
ctx sdk.Context
keeper committee.Keeper
}
func (suite *GenesisTestSuite) TestGenesis() {
testCases := []struct {
name string
genState types.GenesisState
expectPass bool
}{
{
name: "normal",
genState: types.DefaultGenesisState(),
expectPass: true,
},
{
name: "invalid",
genState: types.NewGenesisState(
2,
[]types.Committee{},
[]types.Proposal{{ID: 1, CommitteeID: 57}},
[]types.Vote{},
),
expectPass: false,
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
// Setup (note: suite.SetupTest is not run before every suite.Run)
suite.app = app.NewTestApp()
suite.keeper = suite.app.GetCommitteeKeeper()
suite.ctx = suite.app.NewContext(true, abci.Header{})
// Run
var exportedGenState types.GenesisState
run := func() {
committee.InitGenesis(suite.ctx, suite.keeper, tc.genState)
exportedGenState = committee.ExportGenesis(suite.ctx, suite.keeper)
}
if tc.expectPass {
suite.NotPanics(run)
} else {
suite.Panics(run)
}
// Check
if tc.expectPass {
suite.Equal(tc.genState, exportedGenState)
}
})
}
}
func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(GenesisTestSuite))
}