2023-09-22 16:05:12 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
sdkmath "cosmossdk.io/math"
|
2024-02-06 22:54:10 +00:00
|
|
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
|
|
tmtime "github.com/cometbft/cometbft/types/time"
|
2023-09-22 16:05:12 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2024-08-03 09:51:56 +00:00
|
|
|
"github.com/0glabs/0g-chain/app"
|
|
|
|
"github.com/0glabs/0g-chain/x/community/keeper"
|
|
|
|
"github.com/0glabs/0g-chain/x/community/types"
|
2023-09-22 16:05:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Test suite used for all store tests
|
|
|
|
type StoreTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
App app.TestApp
|
|
|
|
Ctx sdk.Context
|
|
|
|
Keeper keeper.Keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
// The default state used by each test
|
|
|
|
func (suite *StoreTestSuite) SetupTest() {
|
|
|
|
app.SetSDKConfig()
|
|
|
|
suite.App = app.NewTestApp()
|
|
|
|
suite.Ctx = suite.App.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
|
|
|
suite.Keeper = suite.App.GetCommunityKeeper()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStoreTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(StoreTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StoreTestSuite) TestGetSetParams() {
|
|
|
|
suite.Run("get params returns not found on empty store", func() {
|
|
|
|
_, found := suite.Keeper.GetParams(suite.Ctx)
|
|
|
|
suite.Require().False(found)
|
|
|
|
})
|
|
|
|
|
|
|
|
suite.Run("set params cannot store invalid params", func() {
|
|
|
|
invalid := types.Params{UpgradeTimeDisableInflation: time.Date(-1, 1, 1, 0, 0, 0, 0, time.UTC)}
|
|
|
|
suite.Panics(func() {
|
|
|
|
suite.Keeper.SetParams(suite.Ctx, invalid)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
suite.Run("get params returns stored params", func() {
|
|
|
|
suite.Keeper.SetParams(suite.Ctx, types.DefaultParams())
|
|
|
|
|
|
|
|
storedParams, found := suite.Keeper.GetParams(suite.Ctx)
|
|
|
|
suite.True(found)
|
|
|
|
suite.Equal(types.DefaultParams(), storedParams)
|
|
|
|
})
|
|
|
|
|
|
|
|
suite.Run("set overwrite previous value", func() {
|
|
|
|
suite.Keeper.SetParams(suite.Ctx, types.DefaultParams())
|
|
|
|
|
|
|
|
params := types.NewParams(
|
|
|
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
|
2023-09-26 17:08:26 +00:00
|
|
|
sdkmath.LegacyNewDec(1000),
|
2023-10-03 15:41:54 +00:00
|
|
|
sdkmath.LegacyNewDec(1000),
|
2023-09-22 16:05:12 +00:00
|
|
|
)
|
|
|
|
suite.Keeper.SetParams(suite.Ctx, params)
|
|
|
|
|
|
|
|
storedParams, found := suite.Keeper.GetParams(suite.Ctx)
|
|
|
|
suite.True(found)
|
|
|
|
suite.NotEqual(params, types.DefaultParams())
|
|
|
|
suite.Equal(params, storedParams)
|
|
|
|
})
|
|
|
|
}
|