diff --git a/app/app.go b/app/app.go index 109ec89da..a77186769 100644 --- a/app/app.go +++ b/app/app.go @@ -865,9 +865,10 @@ func NewElysApp( ) marginModule := marginmodule.NewAppModule(appCodec, app.MarginKeeper, app.AccountKeeper, app.BankKeeper) - app.ClockKeeper = clockmodulekeeper.NewKeeper( + app.ClockKeeper = *clockmodulekeeper.NewKeeper( keys[clockmoduletypes.StoreKey], appCodec, + app.GetSubspace(clockmoduletypes.ModuleName), *app.ContractKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) diff --git a/testutil/keeper/clock.go b/testutil/keeper/clock.go new file mode 100644 index 000000000..275640d2a --- /dev/null +++ b/testutil/keeper/clock.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "testing" + + wasmmodulekeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + tmdb "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/log" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/elys-network/elys/x/clock/keeper" + "github.com/elys-network/elys/x/clock/types" + "github.com/stretchr/testify/require" +) + +func ClockKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := tmdb.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + paramsSubspace := typesparams.NewSubspace(cdc, + types.Amino, + storeKey, + memStoreKey, + "ClockParams", + ) + + k := keeper.NewKeeper( + storeKey, + cdc, + paramsSubspace, + wasmmodulekeeper.PermissionedKeeper{}, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + k.SetParams(ctx, types.DefaultParams()) + + return k, ctx +} diff --git a/x/clock/genesis_test.go b/x/clock/genesis_test.go index 897bed8eb..fcf6f9f5d 100644 --- a/x/clock/genesis_test.go +++ b/x/clock/genesis_test.go @@ -21,7 +21,7 @@ type GenesisTestSuite struct { ctx sdk.Context - app *app.App + app *app.ElysApp } func TestGenesisTestSuite(t *testing.T) { @@ -29,13 +29,10 @@ func TestGenesisTestSuite(t *testing.T) { } func (suite *GenesisTestSuite) SetupTest() { - app := app.Setup(suite.T()) - ctx := app.BaseApp.NewContext(false, tmproto.Header{ + suite.app = app.InitElysTestApp(true) + suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{ ChainID: "testing", }) - - suite.app = app - suite.ctx = ctx } func (suite *GenesisTestSuite) TestClockInitGenesis() { @@ -92,14 +89,14 @@ func (suite *GenesisTestSuite) TestClockInitGenesis() { if tc.expPanic { suite.Require().Panics(func() { - clock.InitGenesis(suite.ctx, suite.app.AppKeepers.ClockKeeper, tc.genesis) + clock.InitGenesis(suite.ctx, suite.app.ClockKeeper, tc.genesis) }) } else { suite.Require().NotPanics(func() { - clock.InitGenesis(suite.ctx, suite.app.AppKeepers.ClockKeeper, tc.genesis) + clock.InitGenesis(suite.ctx, suite.app.ClockKeeper, tc.genesis) }) - params := suite.app.AppKeepers.ClockKeeper.GetParams(suite.ctx) + params := suite.app.ClockKeeper.GetParams(suite.ctx) suite.Require().Equal(tc.genesis.Params, params) } }) diff --git a/x/clock/keeper/keeper.go b/x/clock/keeper/keeper.go index d5ce1f0fb..cd59ecee9 100644 --- a/x/clock/keeper/keeper.go +++ b/x/clock/keeper/keeper.go @@ -2,11 +2,10 @@ package keeper import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/elys-network/elys/x/clock/types" ) @@ -23,10 +22,16 @@ type Keeper struct { func NewKeeper( key storetypes.StoreKey, cdc codec.BinaryCodec, + ps paramtypes.Subspace, contractKeeper wasmkeeper.PermissionedKeeper, authority string, -) Keeper { - return Keeper{ +) *Keeper { + // set KeyTable if it has not already been set + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + + return &Keeper{ cdc: cdc, storeKey: key, contractKeeper: contractKeeper, diff --git a/x/clock/keeper/keeper_test.go b/x/clock/keeper/keeper_test.go index a6f592c09..52d0cb5c8 100644 --- a/x/clock/keeper/keeper_test.go +++ b/x/clock/keeper/keeper_test.go @@ -30,8 +30,7 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupTest() { isCheckTx := false - s.app = app.Setup(s.T()) - + s.app = app.InitElysTestApp(true) s.ctx = s.app.BaseApp.NewContext(isCheckTx, tmproto.Header{ ChainID: "testing", Height: 1, diff --git a/x/clock/keeper/msg_server_test.go b/x/clock/keeper/msg_server_test.go index d274471ad..1b94e38f6 100644 --- a/x/clock/keeper/msg_server_test.go +++ b/x/clock/keeper/msg_server_test.go @@ -60,7 +60,7 @@ func (s *IntegrationTestSuite) TestUpdateClockParams() { params := types.DefaultParams() params.ContractAddresses = tc.ContractAddresses - err := s.app.AppKeepers.ClockKeeper.SetParams(s.ctx, params) + err := s.app.ClockKeeper.SetParams(s.ctx, params) if !tc.success { s.Require().Error(err) diff --git a/x/clock/keeper/querier_test.go b/x/clock/keeper/querier_test.go index c0fb37731..1aaef0d34 100644 --- a/x/clock/keeper/querier_test.go +++ b/x/clock/keeper/querier_test.go @@ -42,7 +42,7 @@ func (s *IntegrationTestSuite) TestClockQueryParams() { tc := tc s.Run(tc.desc, func() { // Set the params to what is expected, then query and ensure the query is the same - err := s.app.AppKeepers.ClockKeeper.SetParams(s.ctx, tc.Expected) + err := s.app.ClockKeeper.SetParams(s.ctx, tc.Expected) s.Require().NoError(err) // Contracts check diff --git a/x/clock/types/codec.go b/x/clock/types/codec.go index b56a741ac..7a83031aa 100644 --- a/x/clock/types/codec.go +++ b/x/clock/types/codec.go @@ -12,7 +12,9 @@ import ( ) var ( - amino = codec.NewLegacyAmino() + amino = codec.NewLegacyAmino() + // retro compatibility purpose with the test interface + Amino = amino AminoCdc = codec.NewAminoCodec(amino) ) diff --git a/x/clock/types/keys.go b/x/clock/types/keys.go index 5345c36f1..0ce7c04d4 100644 --- a/x/clock/types/keys.go +++ b/x/clock/types/keys.go @@ -11,4 +11,7 @@ const ( // RouterKey to be used for message routing RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_clock" )