package clock_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/suite"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cybercongress/go-cyber/v7/app"
clock "github.com/cybercongress/go-cyber/v7/x/clock"
"github.com/cybercongress/go-cyber/v7/x/clock/types"
)
type GenesisTestSuite struct {
suite.Suite
ctx sdk.Context
app *app.App
}
func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(GenesisTestSuite))
}
func (suite *GenesisTestSuite) SetupTest() {
app := app.Setup(suite.T())
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ChainID: "testing",
})
suite.app = app
suite.ctx = ctx
}
func (suite *GenesisTestSuite) TestClockInitGenesis() {
testCases := []struct {
name string
genesis types.GenesisState
success bool
}{
{
"Success - Default Genesis",
*clock.DefaultGenesisState(),
true,
},
{
"Success - Custom Genesis",
types.GenesisState{
Params: types.Params{
ContractGasLimit: 500_000,
},
},
true,
},
{
"Fail - Invalid Gas Amount",
types.GenesisState{
Params: types.Params{
ContractGasLimit: 1,
},
},
false,
},
}
for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
suite.SetupTest()
if tc.success {
suite.Require().NotPanics(func() {
clock.InitGenesis(suite.ctx, suite.app.AppKeepers.ClockKeeper, tc.genesis)
})
params := suite.app.AppKeepers.ClockKeeper.GetParams(suite.ctx)
suite.Require().Equal(tc.genesis.Params, params)
} else {
suite.Require().Panics(func() {
clock.InitGenesis(suite.ctx, suite.app.AppKeepers.ClockKeeper, tc.genesis)
})
}
})
}
}