From 33868606a86864dcc68510a3c7cc80c449ea5ec0 Mon Sep 17 00:00:00 2001 From: samricotta <37125168+samricotta@users.noreply.github.com> Date: Wed, 14 Feb 2024 00:17:13 +0100 Subject: [PATCH] feat(mint): add env bundler to mint module (#19398) Co-authored-by: Marko --- core/appmodule/environment.go | 2 ++ core/go.mod | 5 +++++ core/go.sum | 19 +++++++++++++++++++ runtime/environment.go | 4 +++- runtime/module.go | 4 ++-- simapp/app.go | 6 +++--- tests/integration/example/example_test.go | 2 +- x/circuit/keeper/genesis_test.go | 3 ++- x/circuit/keeper/keeper_test.go | 3 ++- x/mint/CHANGELOG.md | 2 ++ x/mint/depinject.go | 5 ++--- x/mint/{ => keeper}/abci.go | 23 +++++++++-------------- x/mint/keeper/genesis_test.go | 3 ++- x/mint/keeper/grpc_query_test.go | 3 ++- x/mint/keeper/keeper.go | 16 ++++++++-------- x/mint/keeper/keeper_test.go | 4 +++- x/mint/module.go | 2 +- x/nft/keeper/keeper_test.go | 3 ++- 18 files changed, 70 insertions(+), 39 deletions(-) rename x/mint/{ => keeper}/abci.go (70%) diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go index f7305db9fc..17ab778191 100644 --- a/core/appmodule/environment.go +++ b/core/appmodule/environment.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/core/gas" "cosmossdk.io/core/header" "cosmossdk.io/core/store" + "cosmossdk.io/log" ) // Environment is used to get all services to their respective module @@ -16,4 +17,5 @@ type Environment struct { HeaderService header.Service KVStoreService store.KVStoreService MemStoreService store.MemoryStoreService + Logger log.Logger } diff --git a/core/go.mod b/core/go.mod index edeea757b6..fda367de2e 100644 --- a/core/go.mod +++ b/core/go.mod @@ -3,6 +3,7 @@ module cosmossdk.io/core go 1.20 require ( + cosmossdk.io/log v1.3.1 github.com/stretchr/testify v1.8.4 google.golang.org/grpc v1.61.0 google.golang.org/protobuf v1.32.0 @@ -12,8 +13,12 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/kr/pretty v0.3.1 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rs/zerolog v1.32.0 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/core/go.sum b/core/go.sum index 6cb44a1b40..c1cf8458d9 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,6 +1,10 @@ +cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= +cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -13,16 +17,30 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= +github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= @@ -41,3 +59,4 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= diff --git a/runtime/environment.go b/runtime/environment.go index 6f34e9f67d..2a592363eb 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -3,16 +3,18 @@ package runtime import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/core/store" + "cosmossdk.io/log" ) // NewEnvironment creates a new environment for the application // if memstoreservice is needed, it can be added to the environment: environment.MemStoreService = memstoreservice -func NewEnvironment(kvService store.KVStoreService) appmodule.Environment { +func NewEnvironment(kvService store.KVStoreService, logger log.Logger) appmodule.Environment { return appmodule.Environment{ EventService: EventService{}, HeaderService: HeaderService{}, BranchService: BranchService{}, GasService: GasService{}, KVStoreService: kvService, + Logger: logger, } } diff --git a/runtime/module.go b/runtime/module.go index dbfe511b92..2633918092 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -224,10 +224,10 @@ func ProvideGenesisTxHandler(appBuilder *AppBuilder) genesis.TxHandler { return appBuilder.app } -func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) (store.KVStoreService, appmodule.Environment) { +func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder, logger log.Logger) (store.KVStoreService, appmodule.Environment) { storeKey := ProvideKVStoreKey(config, key, app) kvService := kvStoreService{key: storeKey} - return kvService, NewEnvironment(kvService) + return kvService, NewEnvironment(kvService, logger) } func ProvideMemoryStoreService(key depinject.ModuleKey, app *AppBuilder) store.MemoryStoreService { diff --git a/simapp/app.go b/simapp/app.go index 8533a40f72..66c216eaa9 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -335,7 +335,7 @@ func NewSimApp( app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), ) - app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[minttypes.StoreKey]), logger), app.StakingKeeper, app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.PoolKeeper = poolkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[pooltypes.StoreKey]), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String()) @@ -353,7 +353,7 @@ func NewSimApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[circuittypes.StoreKey])), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) + app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[circuittypes.StoreKey]), logger), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AuthKeeper) @@ -401,7 +401,7 @@ func NewSimApp( ), ) - app.NFTKeeper = nftkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[nftkeeper.StoreKey])), appCodec, app.AuthKeeper, app.BankKeeper) + app.NFTKeeper = nftkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[nftkeeper.StoreKey]), logger), appCodec, app.AuthKeeper, app.BankKeeper) // create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( diff --git a/tests/integration/example/example_test.go b/tests/integration/example/example_test.go index 2b5cadc6eb..1db39ca237 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -54,7 +54,7 @@ func Example() { // here bankkeeper and staking keeper is nil because we are not testing them // subspace is nil because we don't test params (which is legacy anyway) - mintKeeper := mintkeeper.NewKeeper(encodingCfg.Codec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), nil, accountKeeper, nil, authtypes.FeeCollectorName, authority) + mintKeeper := mintkeeper.NewKeeper(encodingCfg.Codec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[minttypes.StoreKey]), logger), nil, accountKeeper, nil, authtypes.FeeCollectorName, authority) mintModule := mint.NewAppModule(encodingCfg.Codec, mintKeeper, accountKeeper, nil) // create the application and register all the modules from the previous step diff --git a/x/circuit/keeper/genesis_test.go b/x/circuit/keeper/genesis_test.go index e11e0da5b3..9848d23799 100644 --- a/x/circuit/keeper/genesis_test.go +++ b/x/circuit/keeper/genesis_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/suite" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/circuit" @@ -48,7 +49,7 @@ func (s *GenesisTestSuite) SetupTest() { s.Require().NoError(err) s.addrBytes = bz - s.keeper = keeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(key)), s.cdc, authority.String(), ac) + s.keeper = keeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), s.cdc, authority.String(), ac) } func (s *GenesisTestSuite) TestInitExportGenesis() { diff --git a/x/circuit/keeper/keeper_test.go b/x/circuit/keeper/keeper_test.go index f3091989dd..e77691c38d 100644 --- a/x/circuit/keeper/keeper_test.go +++ b/x/circuit/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/core/address" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/circuit" @@ -43,7 +44,7 @@ func initFixture(t *testing.T) *fixture { ac := addresscodec.NewBech32Codec("cosmos") mockStoreKey := storetypes.NewKVStoreKey("test") - env := runtime.NewEnvironment(runtime.NewKVStoreService(mockStoreKey)) + env := runtime.NewEnvironment(runtime.NewKVStoreService(mockStoreKey), log.NewNopLogger()) k := keeper.NewKeeper(env, encCfg.Codec, authtypes.NewModuleAddress("gov").String(), ac) bz, err := ac.StringToBytes(authtypes.NewModuleAddress("gov").String()) diff --git a/x/mint/CHANGELOG.md b/x/mint/CHANGELOG.md index 85ad31d779..4b16a9cb86 100644 --- a/x/mint/CHANGELOG.md +++ b/x/mint/CHANGELOG.md @@ -31,4 +31,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#19367](https://github.com/cosmos/cosmos-sdk/pull/19398) `appmodule.Environment` is received on the Keeper to get access to different application services + ### Bug Fixes diff --git a/x/mint/depinject.go b/x/mint/depinject.go index d2c5112a42..556a7c4b7a 100644 --- a/x/mint/depinject.go +++ b/x/mint/depinject.go @@ -3,7 +3,6 @@ package mint import ( modulev1 "cosmossdk.io/api/cosmos/mint/module/v1" "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/store" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" authtypes "cosmossdk.io/x/auth/types" @@ -29,7 +28,7 @@ type ModuleInputs struct { ModuleKey depinject.OwnModuleKey Config *modulev1.Module - StoreService store.KVStoreService + Environment appmodule.Environment Cdc codec.Codec InflationCalculationFn types.InflationCalculationFn `optional:"true"` @@ -64,7 +63,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { k := keeper.NewKeeper( in.Cdc, - in.StoreService, + in.Environment, in.StakingKeeper, in.AccountKeeper, in.BankKeeper, diff --git a/x/mint/abci.go b/x/mint/keeper/abci.go similarity index 70% rename from x/mint/abci.go rename to x/mint/keeper/abci.go index 18ed10aad6..8c3c1b3a4b 100644 --- a/x/mint/abci.go +++ b/x/mint/keeper/abci.go @@ -1,10 +1,10 @@ -package mint +package keeper import ( "context" "time" - "cosmossdk.io/x/mint/keeper" + "cosmossdk.io/core/event" "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/telemetry" @@ -12,7 +12,7 @@ import ( ) // BeginBlocker mints new tokens for the previous block. -func BeginBlocker(ctx context.Context, k keeper.Keeper, ic types.InflationCalculationFn) error { +func (k Keeper) BeginBlocker(ctx context.Context, ic types.InflationCalculationFn) error { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) // fetch stored minter & params @@ -62,16 +62,11 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper, ic types.InflationCalcul defer telemetry.ModuleSetGauge(types.ModuleName, float32(mintedCoin.Amount.Int64()), "minted_tokens") } - sdkCtx := sdk.UnwrapSDKContext(ctx) - sdkCtx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeMint, - sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()), - sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()), - sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()), - sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), - ), + return k.environment.EventService.EventManager(ctx).EmitKV( + types.EventTypeMint, + event.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()), + event.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()), + event.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()), + event.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), ) - - return nil } diff --git a/x/mint/keeper/genesis_test.go b/x/mint/keeper/genesis_test.go index 7690c490b0..c46260c735 100644 --- a/x/mint/keeper/genesis_test.go +++ b/x/mint/keeper/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/collections" + "cosmossdk.io/log" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" authtypes "cosmossdk.io/x/auth/types" @@ -56,7 +57,7 @@ func (s *GenesisTestSuite) SetupTest() { accountKeeper.EXPECT().GetModuleAddress(minterAcc.Name).Return(minterAcc.GetAddress()) accountKeeper.EXPECT().GetModuleAccount(s.sdkCtx, minterAcc.Name).Return(minterAcc) - s.keeper = keeper.NewKeeper(s.cdc, runtime.NewKVStoreService(key), stakingKeeper, accountKeeper, bankKeeper, "", "") + s.keeper = keeper.NewKeeper(s.cdc, runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), stakingKeeper, accountKeeper, bankKeeper, "", "") } func (s *GenesisTestSuite) TestImportExportGenesis() { diff --git a/x/mint/keeper/grpc_query_test.go b/x/mint/keeper/grpc_query_test.go index 6080019910..7b06a894de 100644 --- a/x/mint/keeper/grpc_query_test.go +++ b/x/mint/keeper/grpc_query_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/mint" @@ -32,7 +33,7 @@ type MintTestSuite struct { func (suite *MintTestSuite) SetupTest() { encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) key := storetypes.NewKVStoreKey(types.StoreKey) - storeService := runtime.NewKVStoreService(key) + storeService := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 25932ca13d..9dbccd31fa 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -5,7 +5,7 @@ import ( "fmt" "cosmossdk.io/collections" - storetypes "cosmossdk.io/core/store" + "cosmossdk.io/core/appmodule" "cosmossdk.io/log" "cosmossdk.io/math" "cosmossdk.io/x/mint/types" @@ -17,11 +17,11 @@ import ( // Keeper of the mint store type Keeper struct { cdc codec.BinaryCodec - storeService storetypes.KVStoreService + environment appmodule.Environment stakingKeeper types.StakingKeeper bankKeeper types.BankKeeper + logger log.Logger feeCollectorName string - // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string @@ -34,7 +34,7 @@ type Keeper struct { // NewKeeper creates a new mint Keeper instance func NewKeeper( cdc codec.BinaryCodec, - storeService storetypes.KVStoreService, + env appmodule.Environment, sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, @@ -46,12 +46,13 @@ func NewKeeper( panic(fmt.Sprintf("the x/%s module account has not been set", types.ModuleName)) } - sb := collections.NewSchemaBuilder(storeService) + sb := collections.NewSchemaBuilder(env.KVStoreService) k := Keeper{ cdc: cdc, - storeService: storeService, + environment: env, stakingKeeper: sk, bankKeeper: bk, + logger: env.Logger, feeCollectorName: feeCollectorName, authority: authority, Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), @@ -73,8 +74,7 @@ func (k Keeper) GetAuthority() string { // Logger returns a module-specific logger. func (k Keeper) Logger(ctx context.Context) log.Logger { - sdkCtx := sdk.UnwrapSDKContext(ctx) - return sdkCtx.Logger().With("module", "x/"+types.ModuleName) + return k.environment.Logger.With("module", "x/"+types.ModuleName) } // StakingTokenSupply implements an alias call to the underlying staking keeper's diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index 41888b3341..02b96a2856 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + "cosmossdk.io/log" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" authtypes "cosmossdk.io/x/auth/types" @@ -40,6 +41,7 @@ func (s *IntegrationTestSuite) SetupTest() { encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) + env := runtime.NewEnvironment(storeService, log.NewNopLogger()) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx @@ -53,7 +55,7 @@ func (s *IntegrationTestSuite) SetupTest() { s.mintKeeper = keeper.NewKeeper( encCfg.Codec, - storeService, + env, stakingKeeper, accountKeeper, bankKeeper, diff --git a/x/mint/module.go b/x/mint/module.go index d2fc4358ce..64fcb93560 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -152,7 +152,7 @@ func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // BeginBlock returns the begin blocker for the mint module. func (am AppModule) BeginBlock(ctx context.Context) error { - return BeginBlocker(ctx, am.keeper, am.inflationCalculator) + return am.keeper.BeginBlocker(ctx, am.inflationCalculator) } // AppModuleSimulation functions diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 863dba3c3a..b685cdbc73 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/core/header" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/nft" "cosmossdk.io/x/nft/keeper" @@ -72,7 +73,7 @@ func (s *TestSuite) SetupTest() { s.accountKeeper = accountKeeper - env := runtime.NewEnvironment(runtime.NewKVStoreService(key)) + env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) nftKeeper := keeper.NewKeeper(env, s.encCfg.Codec, accountKeeper, bankKeeper) queryHelper := baseapp.NewQueryServerTestHelper(ctx, s.encCfg.InterfaceRegistry) nft.RegisterQueryServer(queryHelper, nftKeeper)