From 99ef23e502985294356ac767d312cb75184ff13e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 10:30:51 -0300 Subject: [PATCH 01/29] init --- core/log/service.go | 30 ++++++++++++++++++++++++++++++ runtime/module.go | 5 +++++ 2 files changed, 35 insertions(+) create mode 100644 core/log/service.go diff --git a/core/log/service.go b/core/log/service.go new file mode 100644 index 000000000000..95a4cf890d7c --- /dev/null +++ b/core/log/service.go @@ -0,0 +1,30 @@ +package log + +type Service interface { + Logger() Logger +} + +// Logger is the Cosmos SDK logger interface (copied from cosmossdk.io/log). +// It maintains as much backward compatibility with the CometBFT logger as possible. +// All functionalities of the logger are available through the Impl() method. +type Logger interface { + // Info takes a message and a set of key/value pairs and logs with level INFO. + // The key of the tuple must be a string. + Info(msg string, keyVals ...any) + + // Error takes a message and a set of key/value pairs and logs with level ERR. + // The key of the tuple must be a string. + Error(msg string, keyVals ...any) + + // Debug takes a message and a set of key/value pairs and logs with level DEBUG. + // The key of the tuple must be a string. + Debug(msg string, keyVals ...any) + + // With returns a new wrapped logger with additional context provided by a set. + With(keyVals ...any) Logger + + // Impl returns the underlying logger implementation. + // It is used to access the full functionalities of the underlying logger. + // Advanced users can type cast the returned value to the actual logger. + Impl() any +} diff --git a/runtime/module.go b/runtime/module.go index 82ee40470fba..76d594f48ae6 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "cosmossdk.io/core/log" "cosmossdk.io/core/store" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" @@ -209,3 +210,7 @@ func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) stor func ProvideEventService() event.Service { return EventService{} } + +func ProvideLoggerService(key depinject.ModuleKey, app *AppBuilder) log.Service { + return app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name())) +} From 07ad3debbf02314c1f8af57a65ced6bb05f6a21e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 11:18:39 -0300 Subject: [PATCH 02/29] implement + adr --- core/log/service.go | 10 ++--- docs/architecture/adr-063-core-module-api.md | 41 ++++++++++++++++++++ go.mod | 1 + runtime/logger.go | 30 ++++++++++++++ runtime/module.go | 3 +- 5 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 runtime/logger.go diff --git a/core/log/service.go b/core/log/service.go index 95a4cf890d7c..2d5a25b4dea5 100644 --- a/core/log/service.go +++ b/core/log/service.go @@ -1,13 +1,9 @@ package log -type Service interface { - Logger() Logger -} - -// Logger is the Cosmos SDK logger interface (copied from cosmossdk.io/log). +// Service is the same as the Cosmos SDK logger interface (copied from cosmossdk.io/log). // It maintains as much backward compatibility with the CometBFT logger as possible. // All functionalities of the logger are available through the Impl() method. -type Logger interface { +type Service interface { // Info takes a message and a set of key/value pairs and logs with level INFO. // The key of the tuple must be a string. Info(msg string, keyVals ...any) @@ -21,7 +17,7 @@ type Logger interface { Debug(msg string, keyVals ...any) // With returns a new wrapped logger with additional context provided by a set. - With(keyVals ...any) Logger + With(keyVals ...any) Service // Impl returns the underlying logger implementation. // It is used to access the full functionalities of the underlying logger. diff --git a/docs/architecture/adr-063-core-module-api.md b/docs/architecture/adr-063-core-module-api.md index a977688ec71d..cb685137c1ee 100644 --- a/docs/architecture/adr-063-core-module-api.md +++ b/docs/architecture/adr-063-core-module-api.md @@ -160,6 +160,47 @@ the block or app hash is left to the runtime to specify). Events emitted by `EmitKVEvent` and `EmitProtoEventNonConsensus` are not considered to be part of consensus and cannot be observed by other modules. If there is a client-side need to add events in patch releases, these methods can be used. +#### Logger Service + +The logger `Service` will be defined in the `cosmossdk.io/core/log` package and it implements the full Cosmos SDK logger interface. + +```go +package log + +// Service is the same as the Cosmos SDK logger interface (copied from cosmossdk.io/log). +// All functionalities of the logger are available through the Impl() method. +type Service interface { + // Info takes a message and a set of key/value pairs and logs with level INFO. + // The key of the tuple must be a string. + Info(msg string, keyVals ...any) + + // Error takes a message and a set of key/value pairs and logs with level ERR. + // The key of the tuple must be a string. + Error(msg string, keyVals ...any) + + // Debug takes a message and a set of key/value pairs and logs with level DEBUG. + // The key of the tuple must be a string. + Debug(msg string, keyVals ...any) + + // With returns a new wrapped logger with additional context provided by a set. + With(keyVals ...any) Service + + // Impl returns the underlying logger implementation. + // It is used to access the full functionalities of the underlying logger. + // Advanced users can type cast the returned value to the actual logger. + Impl() any +} +``` + +Modules using this service should not need to add any context related to the module name, +as the runtime will do this when providing, following the current pattern in the SDK: + +```go +func ProvideLoggerService(key depinject.ModuleKey, app *AppBuilder) log.Service { + return LoggerService{app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name()))} +} +``` + ### Core `AppModule` extension interfaces diff --git a/go.mod b/go.mod index 3d278dae0a1a..e77fc5116d4f 100644 --- a/go.mod +++ b/go.mod @@ -171,6 +171,7 @@ replace ( github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 // Downgraded to avoid bugs in following commits which caused simulations to fail. github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 + cosmossdk.io/core => ./core ) retract ( diff --git a/runtime/logger.go b/runtime/logger.go new file mode 100644 index 000000000000..4f9e20a9b132 --- /dev/null +++ b/runtime/logger.go @@ -0,0 +1,30 @@ +package runtime + +import ( + corelog "cosmossdk.io/core/log" + "cosmossdk.io/log" +) + +type LoggerService struct { + logger log.Logger +} + +func (ls LoggerService) Info(msg string, keyVals ...any) { + ls.logger.Info(msg, keyVals...) +} + +func (ls LoggerService) Error(msg string, keyVals ...any) { + ls.logger.Error(msg, keyVals...) +} + +func (ls LoggerService) Debug(msg string, keyVals ...any) { + ls.logger.Debug(msg, keyVals...) +} + +func (ls LoggerService) With(keyVals ...any) corelog.Service { + return LoggerService{logger: ls.logger.With(keyVals...)} +} + +func (ls LoggerService) Impl() any { + return ls.logger +} diff --git a/runtime/module.go b/runtime/module.go index 76d594f48ae6..3ee96d6fde45 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -66,6 +66,7 @@ func init() { ProvideMemoryStoreService, ProvideTransientStoreService, ProvideEventService, + ProvideLoggerService, ), appmodule.Invoke(SetupAppBuilder), ) @@ -212,5 +213,5 @@ func ProvideEventService() event.Service { } func ProvideLoggerService(key depinject.ModuleKey, app *AppBuilder) log.Service { - return app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name())) + return LoggerService{app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name()))} } From f709e1a12cc45924006900b807fea978ea0c948c Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 11:20:23 -0300 Subject: [PATCH 03/29] update --- core/log/service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/log/service.go b/core/log/service.go index 2d5a25b4dea5..50651193a90f 100644 --- a/core/log/service.go +++ b/core/log/service.go @@ -1,7 +1,6 @@ package log // Service is the same as the Cosmos SDK logger interface (copied from cosmossdk.io/log). -// It maintains as much backward compatibility with the CometBFT logger as possible. // All functionalities of the logger are available through the Impl() method. type Service interface { // Info takes a message and a set of key/value pairs and logs with level INFO. From 55dfec46d6b18067fa9ce27eb3151eb805a825df Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 17:41:41 -0300 Subject: [PATCH 04/29] use cosmossdk.io\/log --- core/log/service.go | 25 ------------- docs/architecture/adr-063-core-module-api.md | 37 +++----------------- runtime/logger.go | 30 ---------------- runtime/module.go | 8 ++--- 4 files changed, 8 insertions(+), 92 deletions(-) delete mode 100644 core/log/service.go delete mode 100644 runtime/logger.go diff --git a/core/log/service.go b/core/log/service.go deleted file mode 100644 index 50651193a90f..000000000000 --- a/core/log/service.go +++ /dev/null @@ -1,25 +0,0 @@ -package log - -// Service is the same as the Cosmos SDK logger interface (copied from cosmossdk.io/log). -// All functionalities of the logger are available through the Impl() method. -type Service interface { - // Info takes a message and a set of key/value pairs and logs with level INFO. - // The key of the tuple must be a string. - Info(msg string, keyVals ...any) - - // Error takes a message and a set of key/value pairs and logs with level ERR. - // The key of the tuple must be a string. - Error(msg string, keyVals ...any) - - // Debug takes a message and a set of key/value pairs and logs with level DEBUG. - // The key of the tuple must be a string. - Debug(msg string, keyVals ...any) - - // With returns a new wrapped logger with additional context provided by a set. - With(keyVals ...any) Service - - // Impl returns the underlying logger implementation. - // It is used to access the full functionalities of the underlying logger. - // Advanced users can type cast the returned value to the actual logger. - Impl() any -} diff --git a/docs/architecture/adr-063-core-module-api.md b/docs/architecture/adr-063-core-module-api.md index cb685137c1ee..c3b1ab61edfe 100644 --- a/docs/architecture/adr-063-core-module-api.md +++ b/docs/architecture/adr-063-core-module-api.md @@ -162,42 +162,13 @@ by other modules. If there is a client-side need to add events in patch releases #### Logger Service -The logger `Service` will be defined in the `cosmossdk.io/core/log` package and it implements the full Cosmos SDK logger interface. - -```go -package log - -// Service is the same as the Cosmos SDK logger interface (copied from cosmossdk.io/log). -// All functionalities of the logger are available through the Impl() method. -type Service interface { - // Info takes a message and a set of key/value pairs and logs with level INFO. - // The key of the tuple must be a string. - Info(msg string, keyVals ...any) - - // Error takes a message and a set of key/value pairs and logs with level ERR. - // The key of the tuple must be a string. - Error(msg string, keyVals ...any) - - // Debug takes a message and a set of key/value pairs and logs with level DEBUG. - // The key of the tuple must be a string. - Debug(msg string, keyVals ...any) - - // With returns a new wrapped logger with additional context provided by a set. - With(keyVals ...any) Service - - // Impl returns the underlying logger implementation. - // It is used to access the full functionalities of the underlying logger. - // Advanced users can type cast the returned value to the actual logger. - Impl() any -} -``` - -Modules using this service should not need to add any context related to the module name, +A logger (`cosmossdk.io/log`) is provided by default by the `runtime` package. +Modules using it should not need to add any context related to the module name, as the runtime will do this when providing, following the current pattern in the SDK: ```go -func ProvideLoggerService(key depinject.ModuleKey, app *AppBuilder) log.Service { - return LoggerService{app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name()))} +func ProvideLogger(key depinject.ModuleKey, app *AppBuilder) log.Logger { + return app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name())) } ``` diff --git a/runtime/logger.go b/runtime/logger.go deleted file mode 100644 index 4f9e20a9b132..000000000000 --- a/runtime/logger.go +++ /dev/null @@ -1,30 +0,0 @@ -package runtime - -import ( - corelog "cosmossdk.io/core/log" - "cosmossdk.io/log" -) - -type LoggerService struct { - logger log.Logger -} - -func (ls LoggerService) Info(msg string, keyVals ...any) { - ls.logger.Info(msg, keyVals...) -} - -func (ls LoggerService) Error(msg string, keyVals ...any) { - ls.logger.Error(msg, keyVals...) -} - -func (ls LoggerService) Debug(msg string, keyVals ...any) { - ls.logger.Debug(msg, keyVals...) -} - -func (ls LoggerService) With(keyVals ...any) corelog.Service { - return LoggerService{logger: ls.logger.With(keyVals...)} -} - -func (ls LoggerService) Impl() any { - return ls.logger -} diff --git a/runtime/module.go b/runtime/module.go index 3ee96d6fde45..a28effa20825 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - "cosmossdk.io/core/log" "cosmossdk.io/core/store" + "cosmossdk.io/log" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoregistry" @@ -66,7 +66,7 @@ func init() { ProvideMemoryStoreService, ProvideTransientStoreService, ProvideEventService, - ProvideLoggerService, + ProvideLogger, ), appmodule.Invoke(SetupAppBuilder), ) @@ -212,6 +212,6 @@ func ProvideEventService() event.Service { return EventService{} } -func ProvideLoggerService(key depinject.ModuleKey, app *AppBuilder) log.Service { - return LoggerService{app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name()))} +func ProvideLogger(key depinject.ModuleKey, app *AppBuilder) log.Logger { + return app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name())) } From 1b72a6642100c94a4ca211c0da178e3a950c7f96 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 20:17:40 -0300 Subject: [PATCH 05/29] progress --- go.mod | 1 - runtime/app.go | 2 ++ runtime/builder.go | 4 +--- runtime/module.go | 11 ++++++----- simapp/app_v2.go | 3 ++- testutil/sims/app_helpers.go | 10 +++++++--- x/bank/keeper/keeper.go | 12 +++++++----- x/bank/keeper/keeper_test.go | 3 +++ x/bank/keeper/view.go | 6 ------ x/bank/module.go | 6 ++++++ 10 files changed, 34 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index e77fc5116d4f..3d278dae0a1a 100644 --- a/go.mod +++ b/go.mod @@ -171,7 +171,6 @@ replace ( github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 // Downgraded to avoid bugs in following commits which caused simulations to fail. github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 - cosmossdk.io/core => ./core ) retract ( diff --git a/runtime/app.go b/runtime/app.go index 7388ec9faa23..b97a56a9ffa6 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -9,6 +9,7 @@ import ( runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -49,6 +50,7 @@ type App struct { baseAppOptions []BaseAppOption msgServiceRouter *baseapp.MsgServiceRouter appConfig *appv1alpha1.Config + logger log.Logger // initChainer is the init chainer function defined by the app config. // this is only required if the chain wants to add special InitChainer logic. initChainer sdk.InitChainer diff --git a/runtime/builder.go b/runtime/builder.go index c4a8a8f2e3c8..22aaf329ad6c 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -4,7 +4,6 @@ import ( "encoding/json" "io" - "cosmossdk.io/log" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" @@ -26,7 +25,6 @@ func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage { // Build builds an *App instance. func (a *AppBuilder) Build( - logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*baseapp.BaseApp), @@ -35,7 +33,7 @@ func (a *AppBuilder) Build( baseAppOptions = append(baseAppOptions, option) } - bApp := baseapp.NewBaseApp(a.app.config.AppName, logger, db, nil, baseAppOptions...) + bApp := baseapp.NewBaseApp(a.app.config.AppName, a.app.logger, db, nil, baseAppOptions...) bApp.SetMsgServiceRouter(a.app.msgServiceRouter) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) diff --git a/runtime/module.go b/runtime/module.go index a28effa20825..2df75d77f747 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -5,7 +5,6 @@ import ( "os" "cosmossdk.io/core/store" - "cosmossdk.io/log" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoregistry" @@ -66,7 +65,6 @@ func init() { ProvideMemoryStoreService, ProvideTransientStoreService, ProvideEventService, - ProvideLogger, ), appmodule.Invoke(SetupAppBuilder), ) @@ -212,6 +210,9 @@ func ProvideEventService() event.Service { return EventService{} } -func ProvideLogger(key depinject.ModuleKey, app *AppBuilder) log.Logger { - return app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name())) -} +// func ProvideLogger(key depinject.ModuleKey, logger log.Logger) log.Logger { +// // if app.app.Logger() == nil { +// // panic("app is not initialized") +// // } +// return logger.With("module", fmt.Sprintf("x/%s", key.Name())) +// } diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 89d77b2205ba..51d30fe00003 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -168,6 +168,7 @@ func NewSimApp( depinject.Supply( // supply the application options appOpts, + logger, // ADVANCED CONFIGURATION @@ -248,7 +249,7 @@ func NewSimApp( // } // baseAppOptions = append(baseAppOptions, prepareOpt) - app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) + app.App = appBuilder.Build(db, traceStore, baseAppOptions...) // register streaming services if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil { diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 349215bb6da7..4a3659336344 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -14,6 +14,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -119,16 +120,19 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon ) if err := depinject.Inject( - appConfig, + depinject.Configs( + appConfig, + depinject.Supply(log.NewNopLogger()), + ), append(extraOutputs, &appBuilder, &codec)..., ); err != nil { return nil, fmt.Errorf("failed to inject dependencies: %w", err) } if startupConfig.BaseAppOption != nil { - app = appBuilder.Build(log.NewNopLogger(), startupConfig.DB, nil, startupConfig.BaseAppOption) + app = appBuilder.Build(startupConfig.DB, nil, startupConfig.BaseAppOption) } else { - app = appBuilder.Build(log.NewNopLogger(), startupConfig.DB, nil) + app = appBuilder.Build(startupConfig.DB, nil) } if err := app.Load(true); err != nil { return nil, fmt.Errorf("failed to load app: %w", err) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index d767ae5f31bb..e3c4c92b0e79 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + "cosmossdk.io/log" "cosmossdk.io/math" errorsmod "cosmossdk.io/errors" @@ -59,6 +60,7 @@ type BaseKeeper struct { cdc codec.BinaryCodec storeKey storetypes.StoreKey mintCoinsRestrictionFn MintingRestrictionFn + logger log.Logger } type MintingRestrictionFn func(ctx sdk.Context, coins sdk.Coins) error @@ -89,6 +91,7 @@ func NewBaseKeeper( ak types.AccountKeeper, blockedAddrs map[string]bool, authority string, + logger log.Logger, ) BaseKeeper { if _, err := sdk.AccAddressFromBech32(authority); err != nil { panic(fmt.Errorf("invalid bank authority address: %w", err)) @@ -100,6 +103,7 @@ func NewBaseKeeper( cdc: cdc, storeKey: storeKey, mintCoinsRestrictionFn: func(ctx sdk.Context, coins sdk.Coins) error { return nil }, + logger: logger, } } @@ -347,7 +351,7 @@ func (k BaseKeeper) UndelegateCoinsFromModuleToAccount( func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error { err := k.mintCoinsRestrictionFn(ctx, amounts) if err != nil { - ctx.Logger().Error(fmt.Sprintf("Module %q attempted to mint coins %s it doesn't have permission for, error %v", moduleName, amounts, err)) + k.logger.Error(fmt.Sprintf("Module %q attempted to mint coins %s it doesn't have permission for, error %v", moduleName, amounts, err)) return err } acc := k.ak.GetModuleAccount(ctx, moduleName) @@ -370,8 +374,7 @@ func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Co k.setSupply(ctx, supply) } - logger := k.Logger(ctx) - logger.Debug("minted coins from module account", "amount", amounts.String(), "from", moduleName) + k.logger.Debug("minted coins from module account", "amount", amounts.String(), "from", moduleName) // emit mint event ctx.EventManager().EmitEvent( @@ -404,8 +407,7 @@ func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Co k.setSupply(ctx, supply) } - logger := k.Logger(ctx) - logger.Debug("burned tokens from module account", "amount", amounts.String(), "from", moduleName) + k.logger.Debug("burned tokens from module account", "amount", amounts.String(), "from", moduleName) // emit burn event ctx.EventManager().EmitEvent( diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 14d2b7c7f978..0862ac9c482b 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "cosmossdk.io/log" "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -139,6 +140,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.authKeeper, map[string]bool{accAddrs[4].String(): true}, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + log.NewNopLogger(), ) banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) @@ -240,6 +242,7 @@ func (suite *KeeperTestSuite) TestGetAuthority() { nil, nil, authority, + log.NewNopLogger(), ) } diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 308557889388..9851a211d26d 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" - "cosmossdk.io/log" "cosmossdk.io/math" errorsmod "cosmossdk.io/errors" @@ -95,11 +94,6 @@ func NewBaseViewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak t return k } -// Logger returns a module-specific logger. -func (k BaseViewKeeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+types.ModuleName) -} - // HasBalance returns whether or not an account has at least amt balance. func (k BaseViewKeeper) HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool { return k.GetBalance(ctx, addr, amt.Denom).IsGTE(amt) diff --git a/x/bank/module.go b/x/bank/module.go index adfea3c183d9..a485bb18f706 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -9,6 +9,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -212,6 +213,7 @@ type ModuleInputs struct { Config *modulev1.Module Cdc codec.Codec Key *store.KVStoreKey + Logger log.Logger AccountKeeper types.AccountKeeper @@ -248,12 +250,16 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) } + // add the module name to the logger + logger := in.Logger.With("module", "x/"+types.ModuleName) + bankKeeper := keeper.NewBaseKeeper( in.Cdc, in.Key, in.AccountKeeper, blockedAddresses, authority.String(), + logger, ) m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper, in.LegacySubspace) From c9cafd3d190c0092ea1864d36ab4c04da043b348 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 20:30:31 -0300 Subject: [PATCH 06/29] fix --- runtime/module.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/module.go b/runtime/module.go index 2df75d77f747..03859d044815 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -5,6 +5,7 @@ import ( "os" "cosmossdk.io/core/store" + "cosmossdk.io/log" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoregistry" @@ -127,6 +128,7 @@ type AppInputs struct { BaseAppOptions []BaseAppOption InterfaceRegistry codectypes.InterfaceRegistry LegacyAmino *codec.LegacyAmino + Logger log.Logger } func SetupAppBuilder(inputs AppInputs) { @@ -135,6 +137,7 @@ func SetupAppBuilder(inputs AppInputs) { app.config = inputs.Config app.ModuleManager = module.NewManagerFromMap(inputs.Modules) app.appConfig = inputs.AppConfig + app.logger = inputs.Logger for name, mod := range inputs.Modules { if basicMod, ok := mod.(module.AppModuleBasic); ok { From 0262fcd594cfc8ab2df3d4b587f15696cb498961 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 20:47:58 -0300 Subject: [PATCH 07/29] small fixes --- docs/architecture/adr-063-core-module-api.md | 25 +++++++++++++++----- runtime/module.go | 7 ------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/architecture/adr-063-core-module-api.md b/docs/architecture/adr-063-core-module-api.md index 659302257e8d..ee855c3818ab 100644 --- a/docs/architecture/adr-063-core-module-api.md +++ b/docs/architecture/adr-063-core-module-api.md @@ -166,15 +166,28 @@ the block or app hash is left to the runtime to specify). Events emitted by `EmitKVEvent` and `EmitProtoEventNonConsensus` are not considered to be part of consensus and cannot be observed by other modules. If there is a client-side need to add events in patch releases, these methods can be used. -#### Logger Service +#### Logger -A logger (`cosmossdk.io/log`) is provided by default by the `runtime` package. -Modules using it should not need to add any context related to the module name, -as the runtime will do this when providing, following the current pattern in the SDK: +A logger (`cosmossdk.io/log`) must be supplied using `depinject`, and will +be made available for modules to use via `depinject.In`. +Modules using it should follow the current pattern in the SDK by adding the module name before using it. ```go -func ProvideLogger(key depinject.ModuleKey, app *AppBuilder) log.Logger { - return app.app.Logger().With("module", fmt.Sprintf("x/%s", key.Name())) +type ModuleInputs struct { + depinject.In + + Logger log.Logger +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + // ... + // add the module name to the logger + logger := in.Logger.With("module", "x/"+types.ModuleName) + + someKeeper := keeper.NewBaseKeeper( + logger, + ) + // ... } ``` diff --git a/runtime/module.go b/runtime/module.go index 03859d044815..81cda6e1ed0f 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -212,10 +212,3 @@ func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) stor func ProvideEventService() event.Service { return EventService{} } - -// func ProvideLogger(key depinject.ModuleKey, logger log.Logger) log.Logger { -// // if app.app.Logger() == nil { -// // panic("app is not initialized") -// // } -// return logger.With("module", fmt.Sprintf("x/%s", key.Name())) -// } From 65b6a86294472a0489cafcc95e89a0dd86060a4b Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 20:49:14 -0300 Subject: [PATCH 08/29] small fixes --- docs/architecture/adr-063-core-module-api.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/architecture/adr-063-core-module-api.md b/docs/architecture/adr-063-core-module-api.md index ee855c3818ab..cf2a898d3dd3 100644 --- a/docs/architecture/adr-063-core-module-api.md +++ b/docs/architecture/adr-063-core-module-api.md @@ -174,19 +174,19 @@ Modules using it should follow the current pattern in the SDK by adding the modu ```go type ModuleInputs struct { - depinject.In + depinject.In - Logger log.Logger + Logger log.Logger } func ProvideModule(in ModuleInputs) ModuleOutputs { // ... // add the module name to the logger - logger := in.Logger.With("module", "x/"+types.ModuleName) + logger := in.Logger.With("module", "x/"+types.ModuleName) - someKeeper := keeper.NewBaseKeeper( - logger, - ) + someKeeper := keeper.NewBaseKeeper( + logger, + ) // ... } ``` From 0998943d10f62fa928ab65b2617f00fbbef9e1fb Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 20:50:28 -0300 Subject: [PATCH 09/29] small fixes --- docs/architecture/adr-063-core-module-api.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/architecture/adr-063-core-module-api.md b/docs/architecture/adr-063-core-module-api.md index cf2a898d3dd3..a1bc8e258b94 100644 --- a/docs/architecture/adr-063-core-module-api.md +++ b/docs/architecture/adr-063-core-module-api.md @@ -180,14 +180,12 @@ type ModuleInputs struct { } func ProvideModule(in ModuleInputs) ModuleOutputs { - // ... // add the module name to the logger logger := in.Logger.With("module", "x/"+types.ModuleName) - someKeeper := keeper.NewBaseKeeper( + keeper := keeper.NewKeeper( logger, ) - // ... } ``` From 5e1ca87889bc94e80e877398c8ddd806fc602b32 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 20:56:54 -0300 Subject: [PATCH 10/29] small fixes --- testutil/network/network.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index 8ed0bd5354c2..d021cb00a9ed 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -203,11 +203,15 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { cfg.AppConstructor = func(val ValidatorI) servertypes.Application { // we build a unique app instance for every validator here var appBuilder *runtime.AppBuilder - if err := depinject.Inject(appConfig, &appBuilder); err != nil { + if err := depinject.Inject( + depinject.Configs( + appConfig, + depinject.Supply(val.GetCtx().Logger), + ), + &appBuilder); err != nil { panic(err) } app := appBuilder.Build( - val.GetCtx().Logger, dbm.NewMemDB(), nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), From f7e41da4efae3022f775b0cf583a2ba52dd2c382 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 20:59:32 -0300 Subject: [PATCH 11/29] small fixes --- tests/e2e/params/suite.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/e2e/params/suite.go b/tests/e2e/params/suite.go index 0d4e852ebd14..1f69d4725c98 100644 --- a/tests/e2e/params/suite.go +++ b/tests/e2e/params/suite.go @@ -57,7 +57,12 @@ func (s *E2ETestSuite) SetupSuite() { appBuilder *runtime.AppBuilder paramsKeeper keeper.Keeper ) - if err := depinject.Inject(AppConfig, &appBuilder, ¶msKeeper); err != nil { + if err := depinject.Inject( + depinject.Configs( + AppConfig, + depinject.Supply(val.GetCtx().Logger), + ), + &appBuilder, ¶msKeeper); err != nil { panic(err) } @@ -66,7 +71,6 @@ func (s *E2ETestSuite) SetupSuite() { subspace := paramsKeeper.Subspace(mySubspace).WithKeyTable(paramtypes.NewKeyTable().RegisterParamSet(¶mSet)) app := appBuilder.Build( - val.GetCtx().Logger, dbm.NewMemDB(), nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), From db7b086a996d5538c2e64e10e7fcb4931eadf07f Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 21:04:50 -0300 Subject: [PATCH 12/29] cl++ --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5273e6c44d6..fc3a2cfd0435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (runtime) [#15818](https://github.com/cosmos/cosmos-sdk/pull/15818) Provide logger through `depinject` instead of appBuilder. * (testutil/integration) [#15556](https://github.com/cosmos/cosmos-sdk/pull/15556) Introduce `testutil/integration` package for module integration testing. * (types) [#15735](https://github.com/cosmos/cosmos-sdk/pull/15735) Make `ValidateBasic() error` method of `Msg` interface optional. Modules should validate messages directly in their message handlers ([RFC 001](https://docs.cosmos.network/main/rfc/rfc-001-tx-validation)). * (x/genutil) [#15679](https://github.com/cosmos/cosmos-sdk/pull/15679) Allow applications to specify a custom genesis migration function for the `genesis migrate` command. From e3b7073f4ba46deb519b6c21c6c8d415964cdfb8 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 12 Apr 2023 21:09:43 -0300 Subject: [PATCH 13/29] fix app v1 --- simapp/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/simapp/app.go b/simapp/app.go index 0f0416547dad..64ceb7c01447 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -297,6 +297,7 @@ func NewSimApp( app.AccountKeeper, BlockedAddresses(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), + logger, ) app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), From e58ea4072b67c854c18e0254ad0c3c91573afb19 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 13 Apr 2023 19:08:39 -0300 Subject: [PATCH 14/29] fix more tests --- baseapp/block_gas_test.go | 3 +-- client/grpc_query_test.go | 9 +++++++-- testutil/network/network.go | 6 +++++- x/auth/simulation/decoder_test.go | 6 +++++- x/auth/types/account_test.go | 6 +++++- x/evidence/simulation/decoder_test.go | 6 +++++- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 9c2ddd1c3c2b..6e1097fa1ed9 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -6,7 +6,6 @@ import ( "testing" "cosmossdk.io/depinject" - "cosmossdk.io/log" sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" cmtjson "github.com/cometbft/cometbft/libs/json" @@ -99,7 +98,7 @@ func TestBaseApp_BlockGas(t *testing.T) { &appBuilder) require.NoError(t, err) - bapp := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) + bapp := appBuilder.Build(dbm.NewMemDB(), nil) err = bapp.Load(true) require.NoError(t, err) diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index f0594fc228f4..f19656b172bd 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -51,10 +51,15 @@ func (s *IntegrationTestSuite) SetupSuite() { // TODO duplicated from testutils/sims/app_helpers.go // need more composable startup options for simapp, this test needed a handle to the closed over genesis account // to query balances - err := depinject.Inject(testutil.AppConfig, &interfaceRegistry, &bankKeeper, &appBuilder, &cdc) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + &interfaceRegistry, &bankKeeper, &appBuilder, &cdc) s.NoError(err) - app := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) + app := appBuilder.Build(dbm.NewMemDB(), nil) err = app.Load(true) s.NoError(err) diff --git a/testutil/network/network.go b/testutil/network/network.go index d021cb00a9ed..ab3e493209ae 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -182,7 +182,11 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { interfaceRegistry codectypes.InterfaceRegistry ) - if err := depinject.Inject(appConfig, + if err := depinject.Inject( + depinject.Configs( + appConfig, + // depinject.Supply(log.NewNopLogger()), + ), &appBuilder, &txConfig, &cdc, diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index da1099ed59bf..17a4433561e7 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -31,7 +32,10 @@ func TestDecodeStore(t *testing.T) { cdc codec.Codec accountKeeper authkeeper.AccountKeeper ) - err := depinject.Inject(testutil.AppConfig, &cdc, &accountKeeper) + err := depinject.Inject(depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc, &accountKeeper) require.NoError(t, err) acc := types.NewBaseAccountWithAddress(delAddr1) diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index e6d3c5c468cf..8f0952f2e088 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -67,7 +68,10 @@ func TestBaseSequence(t *testing.T) { func TestBaseAccountMarshal(t *testing.T) { var accountKeeper authkeeper.AccountKeeper - err := depinject.Inject(testutil.AppConfig, &accountKeeper) + err := depinject.Inject(depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper) require.NoError(t, err) _, pub, addr := testdata.KeyTestPubAddr() diff --git a/x/evidence/simulation/decoder_test.go b/x/evidence/simulation/decoder_test.go index c9dddff69c5f..bfcd1d88d296 100644 --- a/x/evidence/simulation/decoder_test.go +++ b/x/evidence/simulation/decoder_test.go @@ -6,6 +6,7 @@ import ( "time" "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/x/evidence/keeper" "cosmossdk.io/x/evidence/simulation" "cosmossdk.io/x/evidence/testutil" @@ -19,7 +20,10 @@ import ( func TestDecodeStore(t *testing.T) { var evidenceKeeper keeper.Keeper - err := depinject.Inject(testutil.AppConfig, &evidenceKeeper) + err := depinject.Inject(depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &evidenceKeeper) require.NoError(t, err) dec := simulation.NewDecodeStore(evidenceKeeper) From 1f9c0bfb968e6e61390d400beb2cc7e522f5356c Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 13 Apr 2023 19:15:32 -0300 Subject: [PATCH 15/29] more tests --- baseapp/block_gas_test.go | 21 +++++++++++++-------- baseapp/grpcrouter_test.go | 10 ++++++++-- baseapp/msg_service_router_test.go | 25 +++++++++++++++++++------ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 6e1097fa1ed9..3630cc65e401 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -6,6 +6,7 @@ import ( "testing" "cosmossdk.io/depinject" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" cmtjson "github.com/cometbft/cometbft/libs/json" @@ -81,14 +82,18 @@ func TestBaseApp_BlockGas(t *testing.T) { err error ) - err = depinject.Inject(configurator.NewAppConfig( - configurator.AuthModule(), - configurator.TxModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.BankModule(), - configurator.StakingModule(), - ), + err = depinject.Inject( + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.TxModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.BankModule(), + configurator.StakingModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), &bankKeeper, &accountKeeper, &interfaceRegistry, diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index 419c2e2845a0..825a89dad284 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -55,10 +56,15 @@ func TestGRPCQueryRouter(t *testing.T) { func TestRegisterQueryServiceTwice(t *testing.T) { // Setup baseapp. var appBuilder *runtime.AppBuilder - err := depinject.Inject(makeMinimalConfig(), &appBuilder) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewTestLogger(t)), + ), + &appBuilder) require.NoError(t, err) db := dbm.NewMemDB() - app := appBuilder.Build(log.NewTestLogger(t), db, nil) + app := appBuilder.Build(db, nil) // First time registering service shouldn't panic. require.NotPanics(t, func() { diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 16f780e078f0..68aab4bd5784 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -26,9 +27,13 @@ func TestRegisterMsgService(t *testing.T) { appBuilder *runtime.AppBuilder registry codectypes.InterfaceRegistry ) - err := depinject.Inject(makeMinimalConfig(), &appBuilder, ®istry) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewTestLogger(t)), + ), &appBuilder, ®istry) require.NoError(t, err) - app := appBuilder.Build(log.NewTestLogger(t), dbm.NewMemDB(), nil) + app := appBuilder.Build(dbm.NewMemDB(), nil) require.Panics(t, func() { testdata.RegisterMsgServer( @@ -54,10 +59,14 @@ func TestRegisterMsgServiceTwice(t *testing.T) { appBuilder *runtime.AppBuilder registry codectypes.InterfaceRegistry ) - err := depinject.Inject(makeMinimalConfig(), &appBuilder, ®istry) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewTestLogger(t)), + ), &appBuilder, ®istry) require.NoError(t, err) db := dbm.NewMemDB() - app := appBuilder.Build(log.NewTestLogger(t), db, nil) + app := appBuilder.Build(db, nil) testdata.RegisterInterfaces(registry) // First time registering service shouldn't panic. @@ -85,9 +94,13 @@ func TestMsgService(t *testing.T) { cdc codec.ProtoCodecMarshaler interfaceRegistry codectypes.InterfaceRegistry ) - err := depinject.Inject(makeMinimalConfig(), &appBuilder, &cdc, &interfaceRegistry) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewNopLogger()), + ), &appBuilder, &cdc, &interfaceRegistry) require.NoError(t, err) - app := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) + app := appBuilder.Build(dbm.NewMemDB(), nil) // patch in TxConfig instead of using an output from x/auth/tx txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) From c7b25a36e1f6cd33e12fc9214bb32ceb31c91f4e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 18 Apr 2023 09:22:02 -0300 Subject: [PATCH 16/29] tests --- crypto/armor_test.go | 8 +++++++- crypto/keys/multisig/multisig_test.go | 8 +++++++- testutil/sims/app_helpers.go | 8 +------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crypto/armor_test.go b/crypto/armor_test.go index 23c5e629cf2b..69d56cbeaacc 100644 --- a/crypto/armor_test.go +++ b/crypto/armor_test.go @@ -13,6 +13,8 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/crypto" @@ -75,7 +77,11 @@ func TestArmorUnarmorPrivKey(t *testing.T) { func TestArmorUnarmorPubKey(t *testing.T) { // Select the encryption and storage for your cryptostore var cdc codec.Codec - err := depinject.Inject(configurator.NewAppConfig(), &cdc) + + err := depinject.Inject(depinject.Configs( + configurator.NewAppConfig(), + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) cstore := keyring.NewInMemory(cdc) diff --git a/crypto/keys/multisig/multisig_test.go b/crypto/keys/multisig/multisig_test.go index cc9b6cf176bc..9c02fe6e1550 100644 --- a/crypto/keys/multisig/multisig_test.go +++ b/crypto/keys/multisig/multisig_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/types" @@ -354,7 +356,11 @@ func TestDisplay(t *testing.T) { require.NotEmpty(msig.String()) var cdc codec.Codec - err := depinject.Inject(configurator.NewAppConfig(), &cdc) + err := depinject.Inject( + depinject.Configs( + configurator.NewAppConfig(), + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(err) bz, err := cdc.MarshalInterfaceJSON(msig) require.NoError(err) diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 1de7859310cd..f4dae4d1cc3a 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -117,13 +117,7 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon codec codec.Codec ) - if err := depinject.Inject( - depinject.Configs( - appConfig, - // depinject.Supply(log.NewNopLogger()), - ), - append(extraOutputs, &appBuilder, &codec)..., - ); err != nil { + if err := depinject.Inject(appConfig, append(extraOutputs, &appBuilder, &codec)...); err != nil { return nil, fmt.Errorf("failed to inject dependencies: %w", err) } From c277e3aaa497731b07054ea35e3bee4c5f69884e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 18 Apr 2023 09:28:30 -0300 Subject: [PATCH 17/29] update bank --- x/bank/keeper/keeper.go | 5 ++++- x/bank/keeper/send.go | 4 ++++ x/bank/keeper/view.go | 9 ++++++++- x/bank/module.go | 5 +---- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index e3c4c92b0e79..c987c48fd2cc 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -97,8 +97,11 @@ func NewBaseKeeper( panic(fmt.Errorf("invalid bank authority address: %w", err)) } + // add the module name to the logger + logger = logger.With("module", "x/"+types.ModuleName) + return BaseKeeper{ - BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, blockedAddrs, authority), + BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, blockedAddrs, authority, logger), ak: ak, cdc: cdc, storeKey: storeKey, diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index da48effc09ef..2635081cf947 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -4,6 +4,7 @@ import ( "fmt" "cosmossdk.io/collections" + "cosmossdk.io/log" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" @@ -53,6 +54,7 @@ type BaseSendKeeper struct { cdc codec.BinaryCodec ak types.AccountKeeper storeKey storetypes.StoreKey + logger log.Logger // list of addresses that are restricted from receiving transactions blockedAddrs map[string]bool @@ -68,6 +70,7 @@ func NewBaseSendKeeper( ak types.AccountKeeper, blockedAddrs map[string]bool, authority string, + logger log.Logger, ) BaseSendKeeper { if _, err := sdk.AccAddressFromBech32(authority); err != nil { panic(fmt.Errorf("invalid bank authority address: %w", err)) @@ -80,6 +83,7 @@ func NewBaseSendKeeper( storeKey: storeKey, blockedAddrs: blockedAddrs, authority: authority, + logger: logger, } } diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 9851a211d26d..8cb9091f315d 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -4,6 +4,7 @@ import ( "fmt" "cosmossdk.io/collections/indexes" + "cosmossdk.io/log" "github.com/cockroachdb/errors" @@ -63,6 +64,7 @@ type BaseViewKeeper struct { cdc codec.BinaryCodec storeKey storetypes.StoreKey ak types.AccountKeeper + logger log.Logger Schema collections.Schema Supply collections.Map[string, math.Int] @@ -73,12 +75,13 @@ type BaseViewKeeper struct { } // NewBaseViewKeeper returns a new BaseViewKeeper. -func NewBaseViewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak types.AccountKeeper) BaseViewKeeper { +func NewBaseViewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak types.AccountKeeper, logger log.Logger) BaseViewKeeper { sb := collections.NewSchemaBuilder(runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey))) k := BaseViewKeeper{ cdc: cdc, storeKey: storeKey, ak: ak, + logger: logger, Supply: collections.NewMap(sb, types.SupplyKey, "supply", collections.StringKey, sdk.IntValue), DenomMetadata: collections.NewMap(sb, types.DenomMetadataPrefix, "denom_metadata", collections.StringKey, codec.CollValue[types.Metadata](cdc)), SendEnabled: collections.NewMap(sb, types.SendEnabledPrefix, "send_enabled", collections.StringKey, codec.BoolValue), // NOTE: we use a bool value which uses protobuf to retain state backwards compat @@ -99,6 +102,10 @@ func (k BaseViewKeeper) HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk return k.GetBalance(ctx, addr, amt.Denom).IsGTE(amt) } +func (k BaseViewKeeper) Logger() log.Logger { + return k.logger +} + // GetAllBalances returns all the account balances for the given account address. func (k BaseViewKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins { balances := sdk.NewCoins() diff --git a/x/bank/module.go b/x/bank/module.go index a485bb18f706..0ffe412b7124 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -250,16 +250,13 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) } - // add the module name to the logger - logger := in.Logger.With("module", "x/"+types.ModuleName) - bankKeeper := keeper.NewBaseKeeper( in.Cdc, in.Key, in.AccountKeeper, blockedAddresses, authority.String(), - logger, + in.Logger, ) m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper, in.LegacySubspace) From 54bb8f6a5277926e1efd5f57b6b50dc290c17526 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 18 Apr 2023 09:32:58 -0300 Subject: [PATCH 18/29] update bank --- x/bank/keeper/send.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index 2635081cf947..1ab7dd22c0ff 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -77,7 +77,7 @@ func NewBaseSendKeeper( } return BaseSendKeeper{ - BaseViewKeeper: NewBaseViewKeeper(cdc, storeKey, ak), + BaseViewKeeper: NewBaseViewKeeper(cdc, storeKey, ak, logger), cdc: cdc, ak: ak, storeKey: storeKey, From 87bc493a35ee3900981f531b0ffb8af808bb906c Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 18 Apr 2023 11:48:54 -0300 Subject: [PATCH 19/29] fix more test --- .../staking/keeper/determinstic_test.go | 9 +++++-- x/bank/app_test.go | 26 +++++++++++------- x/bank/simulation/operations_test.go | 22 +++++++++------ x/gov/simulation/operations_test.go | 27 ++++++++++++------- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/tests/integration/staking/keeper/determinstic_test.go b/tests/integration/staking/keeper/determinstic_test.go index ded82a8be2d4..3697762419ae 100644 --- a/tests/integration/staking/keeper/determinstic_test.go +++ b/tests/integration/staking/keeper/determinstic_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "gotest.tools/v3/assert" @@ -25,7 +27,7 @@ import ( ) var ( - validator1 = "cosmosvaloper1qqqryrs09ggeuqszqygqyqd2tgqmsqzewacjj7" + validator1 = "cosmosva§per1qqqryrs09ggeuqszqygqyqd2tgqmsqzewacjj7" validatorAddr1, _ = sdk.ValAddressFromBech32(validator1) validator2 = "cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj" validatorAddr2, _ = sdk.ValAddressFromBech32(validator2) @@ -51,7 +53,10 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { var interfaceRegistry codectypes.InterfaceRegistry app, err := simtestutil.Setup( - stakingtestutil.AppConfig, + depinject.Configs( + stakingtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &f.bankKeeper, &f.accountKeeper, &f.stakingKeeper, diff --git a/x/bank/app_test.go b/x/bank/app_test.go index a47e060a96f5..663227ae913c 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -3,6 +3,8 @@ package bank_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/assert" @@ -109,16 +111,20 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s startupCfg := simtestutil.DefaultStartUpConfig() startupCfg.GenesisAccounts = genAccounts - app, err := simtestutil.SetupWithConfiguration(configurator.NewAppConfig( - configurator.ParamsModule(), - configurator.AuthModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.BankModule(), - configurator.GovModule(), - configurator.DistributionModule(), - ), + app, err := simtestutil.SetupWithConfiguration( + depinject.Configs( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.BankModule(), + configurator.GovModule(), + configurator.DistributionModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &res.BankKeeper, &res.AccountKeeper, &res.DistributionKeeper) res.App = app diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index ee50ddf0cd59..d261c64a1c4a 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -4,6 +4,8 @@ import ( "math/rand" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -41,14 +43,18 @@ func (suite *SimTestSuite) SetupTest() { appBuilder *runtime.AppBuilder err error ) - suite.app, err = simtestutil.Setup(configurator.NewAppConfig( - configurator.AuthModule(), - configurator.ParamsModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.ConsensusModule(), - configurator.TxModule(), - ), &suite.accountKeeper, &suite.bankKeeper, &suite.cdc, &appBuilder) + suite.app, err = simtestutil.Setup( + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.ParamsModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.ConsensusModule(), + configurator.TxModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), &suite.accountKeeper, &suite.bankKeeper, &suite.cdc, &appBuilder) suite.NoError(err) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index d0b85dfdc7ed..eaaf3f00df7f 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -380,16 +382,21 @@ type suite struct { func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { res := suite{} - app, err := simtestutil.Setup(configurator.NewAppConfig( - configurator.AuthModule(), - configurator.TxModule(), - configurator.ParamsModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.ConsensusModule(), - configurator.DistributionModule(), - configurator.GovModule(), - ), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.DistributionKeeper) + app, err := simtestutil.Setup( + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.TxModule(), + configurator.ParamsModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.ConsensusModule(), + configurator.DistributionModule(), + configurator.GovModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), + &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.DistributionKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(isCheckTx, cmtproto.Header{}) From 9c4c448eecf81ad39e263444f658e35f77c1b9ae Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 18 Apr 2023 14:05:57 -0300 Subject: [PATCH 20/29] fix tests --- .../staking/keeper/determinstic_test.go | 2 +- x/authz/simulation/operations_test.go | 7 ++++- x/gov/common_test.go | 27 +++++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/integration/staking/keeper/determinstic_test.go b/tests/integration/staking/keeper/determinstic_test.go index 3697762419ae..a1a97ff36c3f 100644 --- a/tests/integration/staking/keeper/determinstic_test.go +++ b/tests/integration/staking/keeper/determinstic_test.go @@ -27,7 +27,7 @@ import ( ) var ( - validator1 = "cosmosva§per1qqqryrs09ggeuqszqygqyqd2tgqmsqzewacjj7" + validator1 = "cosmosvaloper1qqqryrs09ggeuqszqygqyqd2tgqmsqzewacjj7" validatorAddr1, _ = sdk.ValAddressFromBech32(validator1) validator2 = "cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj" validatorAddr2, _ = sdk.ValAddressFromBech32(validator2) diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 3a5ec4c9380d..ae2bb7627095 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -41,7 +43,10 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { app, err := simtestutil.Setup( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &suite.legacyAmino, &suite.codec, &suite.interfaceRegistry, diff --git a/x/gov/common_test.go b/x/gov/common_test.go index 55e684439663..9c1eb7ef6d18 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -2,11 +2,14 @@ package gov_test import ( "bytes" - "log" - "sort" += "sort" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -29,7 +32,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" ) var ( @@ -112,14 +114,17 @@ func createTestSuite(t *testing.T) suite { res := suite{} app, err := simtestutil.SetupWithConfiguration( - configurator.NewAppConfig( - configurator.ParamsModule(), - configurator.AuthModule(), - configurator.StakingModule(), - configurator.BankModule(), - configurator.GovModule(), - configurator.ConsensusModule(), - configurator.DistributionModule(), + depinject.Configs( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.BankModule(), + configurator.GovModule(), + configurator.ConsensusModule(), + configurator.DistributionModule(), + ), + depinject.Supply(log.NewNopLogger()), ), simtestutil.DefaultStartUpConfig(), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.DistributionKeeper, &res.StakingKeeper, From 601e89fa172aeaaccae50c0373808f27db0e5856 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 18 Apr 2023 19:22:00 -0300 Subject: [PATCH 21/29] fix --- x/gov/common_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/gov/common_test.go b/x/gov/common_test.go index 9c1eb7ef6d18..b624759f52ca 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -2,7 +2,7 @@ package gov_test import ( "bytes" -= "sort" + "sort" "testing" "cosmossdk.io/depinject" From 7312bda2acf82599bf916c895895c156388e1c98 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 18 Apr 2023 19:32:53 -0300 Subject: [PATCH 22/29] fix --- x/distribution/client/cli/suite_test.go | 9 ++++++++- x/gov/common_test.go | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/x/distribution/client/cli/suite_test.go b/x/distribution/client/cli/suite_test.go index e9d83416cc46..68396380e4a1 100644 --- a/x/distribution/client/cli/suite_test.go +++ b/x/distribution/client/cli/suite_test.go @@ -7,6 +7,8 @@ import ( "strings" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" @@ -65,7 +67,12 @@ func (s *CLITestSuite) SetupSuite() { } s.clientCtx = ctxGen().WithOutput(&outBuf) - cfg, err := network.DefaultConfigWithAppConfig(distrtestutil.AppConfig) + cfg, err := network.DefaultConfigWithAppConfig( + depinject.Configs( + distrtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + ) s.Require().NoError(err) genesisState := cfg.GenesisState diff --git a/x/gov/common_test.go b/x/gov/common_test.go index b624759f52ca..0837c14cca8d 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -2,11 +2,12 @@ package gov_test import ( "bytes" + "log" "sort" "testing" "cosmossdk.io/depinject" - "cosmossdk.io/log" + sdklog "cosmossdk.io/log" "cosmossdk.io/math" "github.com/stretchr/testify/require" @@ -124,7 +125,7 @@ func createTestSuite(t *testing.T) suite { configurator.ConsensusModule(), configurator.DistributionModule(), ), - depinject.Supply(log.NewNopLogger()), + depinject.Supply(sdklog.NewNopLogger()), ), simtestutil.DefaultStartUpConfig(), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.DistributionKeeper, &res.StakingKeeper, From cf98c0774b997b30fb1122b7dc046194cfbf8e9e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 19 Apr 2023 12:40:53 -0300 Subject: [PATCH 23/29] fix some more tests --- tests/integration/distribution/module_test.go | 9 ++++++- tests/integration/gov/module_test.go | 21 +++++++++------ .../staking/keeper/msg_server_test.go | 17 +++++++----- x/auth/module_test.go | 9 ++++++- x/distribution/testutil/app_config.go | 26 +++++++------------ x/gov/simulation/operations_test.go | 2 +- x/mint/module_test.go | 8 +++++- x/staking/module_test.go | 8 +++++- x/staking/simulation/operations_test.go | 10 ++++++- 9 files changed, 73 insertions(+), 37 deletions(-) diff --git a/tests/integration/distribution/module_test.go b/tests/integration/distribution/module_test.go index 2497c5b3a1ee..226e3f937ca5 100644 --- a/tests/integration/distribution/module_test.go +++ b/tests/integration/distribution/module_test.go @@ -3,6 +3,8 @@ package distribution_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "gotest.tools/v3/assert" @@ -16,7 +18,12 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper authkeeper.AccountKeeper - app, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &accountKeeper) + app, err := simtestutil.SetupAtGenesis( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + &accountKeeper) assert.NilError(t, err) ctx := app.BaseApp.NewContext(false, cmtproto.Header{}) diff --git a/tests/integration/gov/module_test.go b/tests/integration/gov/module_test.go index 83bf6321f2e5..67106e5674f9 100644 --- a/tests/integration/gov/module_test.go +++ b/tests/integration/gov/module_test.go @@ -3,6 +3,8 @@ package gov_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "gotest.tools/v3/assert" @@ -18,14 +20,17 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper authkeeper.AccountKeeper app, err := simtestutil.SetupAtGenesis( - configurator.NewAppConfig( - configurator.ParamsModule(), - configurator.AuthModule(), - configurator.StakingModule(), - configurator.BankModule(), - configurator.GovModule(), - configurator.DistributionModule(), - configurator.ConsensusModule(), + depinject.Configs( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.BankModule(), + configurator.GovModule(), + configurator.DistributionModule(), + configurator.ConsensusModule(), + ), + depinject.Supply(log.NewNopLogger()), ), &accountKeeper, ) diff --git a/tests/integration/staking/keeper/msg_server_test.go b/tests/integration/staking/keeper/msg_server_test.go index 50b3e9d3c47e..c09711d77636 100644 --- a/tests/integration/staking/keeper/msg_server_test.go +++ b/tests/integration/staking/keeper/msg_server_test.go @@ -25,13 +25,16 @@ func TestCancelUnbondingDelegation(t *testing.T) { accountKeeper authkeeper.AccountKeeper ) app, err := simtestutil.SetupWithConfiguration( - configurator.NewAppConfig( - configurator.BankModule(), - configurator.TxModule(), - configurator.StakingModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.AuthModule(), + depinject.Configs( + configurator.NewAppConfig( + configurator.BankModule(), + configurator.TxModule(), + configurator.StakingModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.AuthModule(), + ), + depinject.Supply(log.NewNopLogger()), ), simtestutil.DefaultStartUpConfig(), &stakingKeeper, &bankKeeper, &accountKeeper) diff --git a/x/auth/module_test.go b/x/auth/module_test.go index 73ab20793194..cacc42bd69d0 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -3,6 +3,8 @@ package auth_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -14,7 +16,12 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper keeper.AccountKeeper - app, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &accountKeeper) + app, err := simtestutil.SetupAtGenesis( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + &accountKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(false, cmtproto.Header{}) diff --git a/x/distribution/testutil/app_config.go b/x/distribution/testutil/app_config.go index d4757ee01ab5..8c3e33586570 100644 --- a/x/distribution/testutil/app_config.go +++ b/x/distribution/testutil/app_config.go @@ -1,9 +1,6 @@ package testutil import ( - "cosmossdk.io/depinject" - "cosmossdk.io/log" - "github.com/cosmos/cosmos-sdk/testutil/configurator" _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring @@ -17,17 +14,14 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring ) -var AppConfig = depinject.Configs( - configurator.NewAppConfig( - configurator.AuthModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.ParamsModule(), - configurator.GenutilModule(), - configurator.DistributionModule(), - configurator.MintModule(), - ), - depinject.Supply(log.NewNopLogger()), +var AppConfig = configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.ParamsModule(), + configurator.GenutilModule(), + configurator.DistributionModule(), + configurator.MintModule(), ) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 5b3a9e229fbe..3ccdefe6c197 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -398,7 +398,7 @@ func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { ), depinject.Supply(log.NewNopLogger()), ), - ), &res.TxConfig, &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.DistributionKeeper) + &res.TxConfig, &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.DistributionKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(isCheckTx, cmtproto.Header{}) diff --git a/x/mint/module_test.go b/x/mint/module_test.go index ed4f510bfc68..37bf7d4d88ab 100644 --- a/x/mint/module_test.go +++ b/x/mint/module_test.go @@ -3,6 +3,8 @@ package mint_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -16,7 +18,11 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper authkeeper.AccountKeeper - app, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &accountKeeper) + app, err := simtestutil.SetupAtGenesis( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(false, cmtproto.Header{}) diff --git a/x/staking/module_test.go b/x/staking/module_test.go index aaea7b0cd52c..d8e6530a487c 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -3,6 +3,8 @@ package staking_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -15,7 +17,11 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper authKeeper.AccountKeeper - app, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &accountKeeper) + app, err := simtestutil.SetupAtGenesis( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(false, cmtproto.Header{}) diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 6d1484a6991f..ac3fe9874020 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + sdklog "cosmossdk.io/log" "cosmossdk.io/math" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -13,6 +15,7 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/client" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -88,7 +91,12 @@ func (s *SimTestSuite) SetupTest() { stakingKeeper *stakingkeeper.Keeper ) - app, err := simtestutil.SetupWithConfiguration(testutil.AppConfig, startupCfg, &s.txConfig, &bankKeeper, &accountKeeper, &mintKeeper, &distrKeeper, &stakingKeeper) + cfg := depinject.Configs( + testutil.AppConfig, + depinject.Supply(sdklog.NewNopLogger()), + ) + + app, err := simtestutil.SetupWithConfiguration(cfg, startupCfg, &s.txConfig, &bankKeeper, &accountKeeper, &mintKeeper, &distrKeeper, &stakingKeeper) require.NoError(s.T(), err) ctx := app.BaseApp.NewContext(false, cmtproto.Header{}) From 046c9181ffa96fa07b3360c2421cf3ad4f32d42e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 19 Apr 2023 13:19:17 -0300 Subject: [PATCH 24/29] im tired --- .../bank/keeper/deterministic_test.go | 19 ++++++++------ .../distribution/keeper/msg_server_test.go | 1 + tests/integration/genutil/gentx_test.go | 20 +++++++++------ tests/integration/gov/genesis_test.go | 13 ++++++++-- tests/integration/runtime/query_test.go | 19 ++++++++------ .../slashing/keeper/keeper_test.go | 7 +++++- .../staking/keeper/msg_server_test.go | 2 ++ types/query/pagination_test.go | 5 ++++ x/auth/migrations/v2/store_test.go | 7 +++++- x/auth/migrations/v3/store_test.go | 7 +++++- x/distribution/client/cli/suite_test.go | 9 +------ x/distribution/simulation/operations_test.go | 9 ++++++- x/group/module/abci_test.go | 10 ++++++-- x/group/simulation/operations_test.go | 7 +++++- x/slashing/abci_test.go | 7 +++++- x/slashing/app_test.go | 25 +++++++++++++------ x/slashing/simulation/operations_test.go | 7 +++++- x/staking/app_test.go | 11 +++++++- 18 files changed, 136 insertions(+), 49 deletions(-) diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 2acef84bad15..ef92d9cebf34 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -7,6 +7,8 @@ import ( "gotest.tools/v3/assert" "pgregory.net/rapid" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/configurator" @@ -62,13 +64,16 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { var interfaceRegistry codectypes.InterfaceRegistry app, err := simstestutil.Setup( - configurator.NewAppConfig( - configurator.AuthModule(), - configurator.TxModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.BankModule(), - configurator.StakingModule(), + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.TxModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.BankModule(), + configurator.StakingModule(), + ), + depinject.Supply(log.NewNopLogger()), ), &f.bankKeeper, &interfaceRegistry, diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 65bd57837ba5..513365ae48de 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -92,6 +92,7 @@ func initFixture(t testing.TB) *fixture { accountKeeper, blockedAddresses, authority.String(), + log.NewNopLogger(), ) stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String()) diff --git a/tests/integration/genutil/gentx_test.go b/tests/integration/genutil/gentx_test.go index 2b9001b68ae2..4663fe0d6b21 100644 --- a/tests/integration/genutil/gentx_test.go +++ b/tests/integration/genutil/gentx_test.go @@ -7,6 +7,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -61,13 +63,17 @@ func initFixture(t assert.TestingT) *fixture { encCfg := moduletestutil.TestEncodingConfig{} app, err := simtestutil.SetupWithConfiguration( - configurator.NewAppConfig( - configurator.BankModule(), - configurator.TxModule(), - configurator.StakingModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.AuthModule()), + depinject.Configs( + configurator.NewAppConfig( + configurator.BankModule(), + configurator.TxModule(), + configurator.StakingModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.AuthModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), simtestutil.DefaultStartUpConfig(), &encCfg.InterfaceRegistry, &encCfg.Codec, &encCfg.TxConfig, &encCfg.Amino, &f.accountKeeper, &f.bankKeeper, &f.stakingKeeper) diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go index 0a0036a41a1d..2bb1e6d439b8 100644 --- a/tests/integration/gov/genesis_test.go +++ b/tests/integration/gov/genesis_test.go @@ -8,6 +8,9 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "gotest.tools/v3/assert" + "cosmossdk.io/depinject" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/configurator" @@ -60,7 +63,10 @@ func TestImportExportQueues(t *testing.T) { s1 := suite{} s1.app, err = simtestutil.SetupWithConfiguration( - appConfig, + depinject.Configs( + appConfig, + depinject.Supply(log.NewNopLogger()), + ), simtestutil.DefaultStartUpConfig(), &s1.AccountKeeper, &s1.BankKeeper, &s1.DistrKeeper, &s1.GovKeeper, &s1.StakingKeeper, &s1.cdc, &s1.appBuilder, ) @@ -113,7 +119,10 @@ func TestImportExportQueues(t *testing.T) { s2 := suite{} s2.app, err = simtestutil.SetupWithConfiguration( - appConfig, + depinject.Configs( + appConfig, + depinject.Supply(log.NewNopLogger()), + ), simtestutil.DefaultStartUpConfig(), &s2.AccountKeeper, &s2.BankKeeper, &s2.DistrKeeper, &s2.GovKeeper, &s2.StakingKeeper, &s2.cdc, &s2.appBuilder, ) diff --git a/tests/integration/runtime/query_test.go b/tests/integration/runtime/query_test.go index f000c827d758..9ff348602936 100644 --- a/tests/integration/runtime/query_test.go +++ b/tests/integration/runtime/query_test.go @@ -13,6 +13,8 @@ import ( appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -41,13 +43,16 @@ func initFixture(t assert.TestingT) *fixture { var interfaceRegistry codectypes.InterfaceRegistry app, err := simtestutil.Setup( - configurator.NewAppConfig( - configurator.AuthModule(), - configurator.TxModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.BankModule(), - configurator.StakingModule(), + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.TxModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.BankModule(), + configurator.StakingModule(), + ), + depinject.Supply(log.NewNopLogger()), ), &interfaceRegistry, ) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 78c1222f0781..844850486a98 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/require" "gotest.tools/v3/assert" + "cosmossdk.io/depinject" + "cosmossdk.io/log" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/testutil" @@ -35,7 +37,10 @@ type fixture struct { func initFixture(t assert.TestingT) *fixture { f := &fixture{} app, err := simtestutil.Setup( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &f.bankKeeper, &f.slashingKeeper, &f.stakingKeeper, diff --git a/tests/integration/staking/keeper/msg_server_test.go b/tests/integration/staking/keeper/msg_server_test.go index c09711d77636..8212dba951a4 100644 --- a/tests/integration/staking/keeper/msg_server_test.go +++ b/tests/integration/staking/keeper/msg_server_test.go @@ -7,6 +7,8 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "gotest.tools/v3/assert" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/testutil/configurator" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index a31c43c0e3e9..6f729296237e 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -5,6 +5,8 @@ import ( "fmt" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -65,6 +67,7 @@ func (s *paginationTestSuite) SetupTest() { ) app, err := testutilsims.Setup( + depinject.Configs( configurator.NewAppConfig( configurator.AuthModule(), configurator.BankModule(), @@ -72,6 +75,8 @@ func (s *paginationTestSuite) SetupTest() { configurator.ConsensusModule(), configurator.OmitInitGenesis(), ), + depinject.Supply(log.NewNopLogger()), + ), &bankKeeper, &accountKeeper, ®, &cdc) s.NoError(err) diff --git a/x/auth/migrations/v2/store_test.go b/x/auth/migrations/v2/store_test.go index 0663f29f1a3a..b4508b5c3af4 100644 --- a/x/auth/migrations/v2/store_test.go +++ b/x/auth/migrations/v2/store_test.go @@ -8,6 +8,8 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/depinject" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -57,7 +59,10 @@ func TestMigrateVestingAccounts(t *testing.T) { stakingKeeper *stakingkeeper.Keeper ) app, err := simtestutil.Setup( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper, &bankKeeper, &stakingKeeper, diff --git a/x/auth/migrations/v3/store_test.go b/x/auth/migrations/v3/store_test.go index df48533de972..39c958707d30 100644 --- a/x/auth/migrations/v3/store_test.go +++ b/x/auth/migrations/v3/store_test.go @@ -8,6 +8,8 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/depinject" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -50,7 +52,10 @@ func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) { var accountKeeper keeper.AccountKeeper app, err := simtestutil.Setup( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper, ) require.NoError(t, err) diff --git a/x/distribution/client/cli/suite_test.go b/x/distribution/client/cli/suite_test.go index 68396380e4a1..e9d83416cc46 100644 --- a/x/distribution/client/cli/suite_test.go +++ b/x/distribution/client/cli/suite_test.go @@ -7,8 +7,6 @@ import ( "strings" "testing" - "cosmossdk.io/depinject" - "cosmossdk.io/log" sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" @@ -67,12 +65,7 @@ func (s *CLITestSuite) SetupSuite() { } s.clientCtx = ctxGen().WithOutput(&outBuf) - cfg, err := network.DefaultConfigWithAppConfig( - depinject.Configs( - distrtestutil.AppConfig, - depinject.Supply(log.NewNopLogger()), - ), - ) + cfg, err := network.DefaultConfigWithAppConfig(distrtestutil.AppConfig) s.Require().NoError(err) genesisState := cfg.GenesisState diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 9a5ed8b246c3..2bafc656bd41 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -4,6 +4,8 @@ import ( "math/rand" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -234,7 +236,12 @@ func (suite *SimTestSuite) SetupTest() { appBuilder *runtime.AppBuilder err error ) - suite.app, err = simtestutil.Setup(distrtestutil.AppConfig, &suite.accountKeeper, + suite.app, err = simtestutil.Setup( + depinject.Configs( + distrtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + &suite.accountKeeper, &suite.bankKeeper, &suite.cdc, &appBuilder, diff --git a/x/group/module/abci_test.go b/x/group/module/abci_test.go index c669fb3b4654..330af29dd1f4 100644 --- a/x/group/module/abci_test.go +++ b/x/group/module/abci_test.go @@ -6,9 +6,13 @@ import ( "time" "cosmossdk.io/core/address" + "cosmossdk.io/depinject" + "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttime "github.com/cometbft/cometbft/types/time" + "github.com/stretchr/testify/suite" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -22,7 +26,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/group/module" grouptestutil "github.com/cosmos/cosmos-sdk/x/group/testutil" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/suite" ) type IntegrationTestSuite struct { @@ -45,7 +48,10 @@ func TestIntegrationTestSuite(t *testing.T) { func (s *IntegrationTestSuite) SetupTest() { app, err := simtestutil.Setup( - grouptestutil.AppConfig, + depinject.Configs( + grouptestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &s.interfaceRegistry, &s.bankKeeper, &s.stakingKeeper, diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 315b5280ad0f..936c0267aeae 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -42,7 +44,10 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { app, err := simtestutil.Setup( - grouptestutil.AppConfig, + depinject.Configs( + grouptestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &suite.codec, &suite.interfaceRegistry, &suite.txConfig, diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index a87cf4bf827f..8547825939eb 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -27,7 +29,10 @@ func TestBeginBlocker(t *testing.T) { var slashingKeeper slashingkeeper.Keeper app, err := simtestutil.Setup( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &interfaceRegistry, &bankKeeper, &stakingKeeper, diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index aa5ac935f197..028f3e77bedc 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -4,11 +4,14 @@ import ( "errors" "testing" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/depinject" "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/configurator" @@ -51,15 +54,21 @@ func TestSlashingMsgs(t *testing.T) { slashingKeeper keeper.Keeper ) - app, err := sims.SetupWithConfiguration(configurator.NewAppConfig( - configurator.ParamsModule(), - configurator.AuthModule(), - configurator.StakingModule(), - configurator.SlashingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.BankModule()), + app, err := sims.SetupWithConfiguration( + depinject.Configs( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.SlashingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.BankModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &stakingKeeper, &bankKeeper, &slashingKeeper) + require.NoError(t, err) baseApp := app.BaseApp diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 0990f5f9e891..324d55e2d160 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -11,6 +11,8 @@ import ( cmttypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/suite" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" @@ -78,7 +80,10 @@ func (suite *SimTestSuite) SetupTest() { startupCfg.ValidatorSet = createValidator app, err := simtestutil.SetupWithConfiguration( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &suite.legacyAmino, &suite.codec, diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 4a81bac5eb83..fd854894a2fb 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -5,12 +5,16 @@ import ( "github.com/stretchr/testify/require" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -53,7 +57,12 @@ func TestStakingMsgs(t *testing.T) { startupCfg := simtestutil.DefaultStartUpConfig() startupCfg.GenesisAccounts = accs - app, err := simtestutil.SetupWithConfiguration(testutil.AppConfig, startupCfg, &bankKeeper, &stakingKeeper) + app, err := simtestutil.SetupWithConfiguration( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + startupCfg, &bankKeeper, &stakingKeeper) require.NoError(t, err) ctxCheck := app.BaseApp.NewContext(true, cmtproto.Header{}) From 089e7750f52ca6c94c45d7d230e1a0d97814ad9e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 19 Apr 2023 13:27:58 -0300 Subject: [PATCH 25/29] hopefully the last --- tests/integration/bank/keeper/keeper_test.go | 18 +++++++++++------- .../evidence/keeper/infraction_test.go | 8 +++++++- .../integration/staking/keeper/params_test.go | 19 ++++++++++++------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/tests/integration/bank/keeper/keeper_test.go b/tests/integration/bank/keeper/keeper_test.go index a5840dd5b5f5..c62d66832250 100644 --- a/tests/integration/bank/keeper/keeper_test.go +++ b/tests/integration/bank/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "time" authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" @@ -119,13 +120,16 @@ func initFixture(t assert.TestingT) *fixture { var interfaceRegistry codectypes.InterfaceRegistry app, err := sims.Setup( - configurator.NewAppConfig( - configurator.AuthModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.VestingModule()), + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.VestingModule()), + depinject.Supply(log.NewNopLogger()), + ), &f.accountKeeper, &f.bankKeeper, &f.stakingKeeper, &f.appCodec, &f.authConfig, &interfaceRegistry, ) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 41fe09ec5e97..3603ab299585 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/x/evidence/exported" "cosmossdk.io/x/evidence/keeper" "cosmossdk.io/x/evidence/testutil" @@ -63,7 +65,11 @@ func initFixture(t assert.TestingT) *fixture { f := &fixture{} var evidenceKeeper keeper.Keeper - app, err := simtestutil.Setup(testutil.AppConfig, + app, err := simtestutil.Setup( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &evidenceKeeper, &f.interfaceRegistry, &f.accountKeeper, diff --git a/tests/integration/staking/keeper/params_test.go b/tests/integration/staking/keeper/params_test.go index e77240c5bbb6..e7db4ef6574c 100644 --- a/tests/integration/staking/keeper/params_test.go +++ b/tests/integration/staking/keeper/params_test.go @@ -3,6 +3,8 @@ package keeper import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "gotest.tools/v3/assert" @@ -15,13 +17,16 @@ import ( func TestParams(t *testing.T) { var stakingKeeper *keeper.Keeper app, err := simtestutil.SetupWithConfiguration( - configurator.NewAppConfig( - configurator.BankModule(), - configurator.TxModule(), - configurator.StakingModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.AuthModule(), + depinject.Configs( + configurator.NewAppConfig( + configurator.BankModule(), + configurator.TxModule(), + configurator.StakingModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.AuthModule(), + ), + depinject.Supply(log.NewNopLogger()), ), simtestutil.DefaultStartUpConfig(), &stakingKeeper) From 8c2cf2b88bcae8b63ca7676ce77422aa6a84a152 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 20 Apr 2023 09:30:22 -0300 Subject: [PATCH 26/29] lint --- types/query/pagination_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 6f729296237e..4c34399c5279 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -68,15 +68,15 @@ func (s *paginationTestSuite) SetupTest() { app, err := testutilsims.Setup( depinject.Configs( - configurator.NewAppConfig( - configurator.AuthModule(), - configurator.BankModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.OmitInitGenesis(), + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.OmitInitGenesis(), + ), + depinject.Supply(log.NewNopLogger()), ), - depinject.Supply(log.NewNopLogger()), - ), &bankKeeper, &accountKeeper, ®, &cdc) s.NoError(err) From f14a89d6eaad4f84ea9c7b8a5008f70172ba74a9 Mon Sep 17 00:00:00 2001 From: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Date: Thu, 20 Apr 2023 16:22:25 -0300 Subject: [PATCH 27/29] Update x/bank/keeper/keeper.go Co-authored-by: Julien Robert --- x/bank/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index c987c48fd2cc..fda321702681 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -98,7 +98,7 @@ func NewBaseKeeper( } // add the module name to the logger - logger = logger.With("module", "x/"+types.ModuleName) + logger = logger.With(log.ModuleKey, "x/"+types.ModuleName) return BaseKeeper{ BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, blockedAddrs, authority, logger), From c038a61426d7ada625ce614148d2d1d9255c24fc Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 20 Apr 2023 17:45:21 -0300 Subject: [PATCH 28/29] adr++ and upgrading++ --- UPGRADING.md | 24 ++++++++++++++++++++ docs/architecture/adr-063-core-module-api.md | 13 +++++++---- x/bank/keeper/view.go | 1 + 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 891c6dcba7c0..4447ba33f685 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -82,6 +82,30 @@ app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper( ) ``` +The following modules `NewKeeper` function now also take a `log.Logger`: + +* `x/bank` + + +### depinject + +For `depinject` users, now the logger must be supplied through the main `depinject.Inject` function instead of passing it to `appBuilder.Build`. + +```diff +appConfig = depinject.Configs( + AppConfig, + depinject.Supply( + // supply the application options + appOpts, ++ logger, + ... +``` + +```diff +- app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) ++ app.App = appBuilder.Build(db, traceStore, baseAppOptions...) +``` + ### Packages #### Store diff --git a/docs/architecture/adr-063-core-module-api.md b/docs/architecture/adr-063-core-module-api.md index a1bc8e258b94..c065ce92ee75 100644 --- a/docs/architecture/adr-063-core-module-api.md +++ b/docs/architecture/adr-063-core-module-api.md @@ -180,13 +180,18 @@ type ModuleInputs struct { } func ProvideModule(in ModuleInputs) ModuleOutputs { - // add the module name to the logger - logger := in.Logger.With("module", "x/"+types.ModuleName) - keeper := keeper.NewKeeper( - logger, + in.logger, ) } + +func NewKeeper(logger log.Logger) Keeper { + return Keeper{ + logger: logger.With(log.ModuleKey, "x/"+types.ModuleName), + } +} +``` + ``` ### Core `AppModule` extension interfaces diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 8cb9091f315d..9e55f8d354c7 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -102,6 +102,7 @@ func (k BaseViewKeeper) HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk return k.GetBalance(ctx, addr, amt.Denom).IsGTE(amt) } +// Logger returns a module-specific logger. func (k BaseViewKeeper) Logger() log.Logger { return k.logger } From 3a856a5bf30c5c8ecb322a8e3b08748d7ad6f7ed Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 20 Apr 2023 17:48:49 -0300 Subject: [PATCH 29/29] cl++ --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b4f13e7bcde..8a7f8f7ace6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/bank) [#15818](https://github.com/cosmos/cosmos-sdk/issues/15818) `BaseViewKeeper`'s `Logger` method now doesn't require a context. `NewBaseKeeper`, `NewBaseSendKeeper` and `NewBaseViewKeeper` now also require a `log.Logger` to be passed in. * (x/*all*) [#15648](https://github.com/cosmos/cosmos-sdk/issues/15648) Make `SetParams` consistent across all modules and validate the params at the message handling instead of `SetParams` method. * (x/genutil) [#15679](https://github.com/cosmos/cosmos-sdk/pull/15679) `MigrateGenesisCmd` now takes a `MigrationMap` instead of having the SDK genesis migration hardcoded. * (client) [#15673](https://github.com/cosmos/cosmos-sdk/pull/15673) Move `client/keys.OutputFormatJSON` and `client/keys.OutputFormatText` to `client/flags` package.