From 871b91c3e78839f066d793859eeb5c1a7bd44558 Mon Sep 17 00:00:00 2001 From: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com> Date: Fri, 23 Feb 2024 02:12:49 +0530 Subject: [PATCH] feat(x/authz): Add env bundler to x/authz (#19490) Co-authored-by: Julien Robert --- simapp/app.go | 2 +- x/authz/CHANGELOG.md | 1 + x/authz/keeper/genesis.go | 2 +- x/authz/keeper/genesis_test.go | 3 +- x/authz/keeper/grpc_query.go | 6 +-- x/authz/keeper/keeper.go | 80 +++++++++++++---------------- x/authz/keeper/keeper_test.go | 3 +- x/authz/keeper/migrations.go | 2 +- x/authz/keeper/msg_server.go | 5 +- x/authz/migrations/v2/store.go | 15 +++--- x/authz/migrations/v2/store_test.go | 4 +- x/authz/module/abci_test.go | 3 +- x/authz/module/depinject.go | 5 +- x/authz/testutil/bank_helpers.go | 10 ++-- 14 files changed, 69 insertions(+), 72 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index b2e47f60c4..07557dfab0 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -350,7 +350,7 @@ func NewSimApp( app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[circuittypes.StoreKey]), logger), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) - app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AuthKeeper) + app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), logger), appCodec, app.MsgServiceRouter(), app.AuthKeeper) groupConfig := group.DefaultConfig() /* diff --git a/x/authz/CHANGELOG.md b/x/authz/CHANGELOG.md index 5f798f3acb..4954a50128 100644 --- a/x/authz/CHANGELOG.md +++ b/x/authz/CHANGELOG.md @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#19490](https://github.com/cosmos/cosmos-sdk/pull/19490) `appmodule.Environment` is received on the Keeper to get access to different application services * [#18737](https://github.com/cosmos/cosmos-sdk/pull/18737) Update the keeper method `DequeueAndDeleteExpiredGrants` to take a limit argument for the number of grants to prune. * [#16509](https://github.com/cosmos/cosmos-sdk/pull/16509) `AcceptResponse` has been moved to sdk/types/authz and the `Updated` field is now of the type `sdk.Msg` instead of `authz.Authorization`. diff --git a/x/authz/keeper/genesis.go b/x/authz/keeper/genesis.go index 43ca074568..d7f28d1b07 100644 --- a/x/authz/keeper/genesis.go +++ b/x/authz/keeper/genesis.go @@ -10,7 +10,7 @@ import ( // InitGenesis initializes new authz genesis func (k Keeper) InitGenesis(ctx context.Context, data *authz.GenesisState) { - now := sdk.UnwrapSDKContext(ctx).HeaderInfo().Time + now := k.environment.HeaderService.GetHeaderInfo(ctx).Time for _, entry := range data.Authorization { // ignore expired authorizations if entry.Expiration != nil && entry.Expiration.Before(now) { diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index 5a3d34579d..e3ced43a0e 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -47,6 +47,7 @@ func (suite *GenesisTestSuite) SetupTest() { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) + env := runtime.NewEnvironment(storeService, log.NewNopLogger()) suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) @@ -68,7 +69,7 @@ func (suite *GenesisTestSuite) SetupTest() { msr := suite.baseApp.MsgServiceRouter() msr.SetInterfaceRegistry(suite.encCfg.InterfaceRegistry) - suite.keeper = keeper.NewKeeper(storeService, suite.encCfg.Codec, msr, suite.accountKeeper) + suite.keeper = keeper.NewKeeper(env, suite.encCfg.Codec, msr, suite.accountKeeper) } func (suite *GenesisTestSuite) TestImportExportGenesis() { diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 943781782b..4b7c45a19a 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -58,7 +58,7 @@ func (k Keeper) Grants(ctx context.Context, req *authz.QueryGrantsRequest) (*aut }, nil } - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx)) key := grantStoreKey(grantee, granter, "") grantsStore := prefix.NewStore(store, key) @@ -100,7 +100,7 @@ func (k Keeper) GranterGrants(ctx context.Context, req *authz.QueryGranterGrants return nil, err } - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx)) authzStore := prefix.NewStore(store, grantStoreKey(nil, granter, "")) grants, pageRes, err := query.GenericFilteredPaginate(k.cdc, authzStore, req.Pagination, func(key []byte, auth *authz.Grant) (*authz.GrantAuthorization, error) { @@ -151,7 +151,7 @@ func (k Keeper) GranteeGrants(ctx context.Context, req *authz.QueryGranteeGrants return nil, err } - store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), GrantKey) + store := prefix.NewStore(runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx)), GrantKey) authorizations, pageRes, err := query.GenericFilteredPaginate(k.cdc, store, req.Pagination, func(key []byte, auth *authz.Grant) (*authz.GrantAuthorization, error) { auth1, err := auth.GetAuthorization() diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 7a8e4ffe34..0554638428 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -7,10 +7,10 @@ import ( "strconv" "time" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" - corestoretypes "cosmossdk.io/core/store" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/event" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -30,31 +30,30 @@ import ( const gasCostPerIteration = uint64(20) type Keeper struct { - storeService corestoretypes.KVStoreService - cdc codec.Codec - router baseapp.MessageRouter - authKeeper authz.AccountKeeper + environment appmodule.Environment + cdc codec.Codec + router baseapp.MessageRouter + authKeeper authz.AccountKeeper } // NewKeeper constructs a message authorization Keeper -func NewKeeper(storeService corestoretypes.KVStoreService, cdc codec.Codec, router baseapp.MessageRouter, ak authz.AccountKeeper) Keeper { +func NewKeeper(env appmodule.Environment, cdc codec.Codec, router baseapp.MessageRouter, ak authz.AccountKeeper) Keeper { return Keeper{ - storeService: storeService, - cdc: cdc, - router: router, - authKeeper: ak, + environment: env, + cdc: cdc, + router: router, + authKeeper: ak, } } // Logger returns a module-specific logger. -func (k Keeper) Logger(ctx context.Context) log.Logger { - sdkCtx := sdk.UnwrapSDKContext(ctx) - return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s", authz.ModuleName)) +func (k Keeper) Logger() log.Logger { + return k.environment.Logger.With("module", fmt.Sprintf("x/%s", authz.ModuleName)) } // getGrant returns grant stored at skey. func (k Keeper) getGrant(ctx context.Context, skey []byte) (grant authz.Grant, found bool) { - store := k.storeService.OpenKVStore(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) bz, err := store.Get(skey) if err != nil { @@ -86,7 +85,7 @@ func (k Keeper) update(ctx context.Context, grantee, granter sdk.AccAddress, upd } grant.Authorization = any - store := k.storeService.OpenKVStore(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) return store.Set(skey, k.cdc.MustMarshal(&grant)) } @@ -165,16 +164,16 @@ func (k Keeper) DispatchActions(ctx context.Context, grantee sdk.AccAddress, msg results[i] = msgResp.Data // emit the events from the dispatched actions - events := msgResp.Events - sdkEvents := make([]sdk.Event, 0, len(events)) - for _, event := range events { - e := event - e.Attributes = append(e.Attributes, abci.EventAttribute{Key: "authz_msg_index", Value: strconv.Itoa(i)}) - - sdkEvents = append(sdkEvents, sdk.Event(e)) + for i = range msgResp.Events { + err := k.environment.EventService.EventManager(ctx).EmitKV( + "dispatch actions", + event.NewAttribute("authz_msg_index", strconv.Itoa(i)), + ) + if err != nil { + return nil, err + } } - sdkCtx.EventManager().EmitEvents(sdkEvents) } return results, nil @@ -184,12 +183,11 @@ func (k Keeper) DispatchActions(ctx context.Context, grantee sdk.AccAddress, msg // with the provided expiration time and insert authorization key into the grants queue. If there is an existing authorization grant for the // same `sdk.Msg` type, this grant overwrites that. func (k Keeper) SaveGrant(ctx context.Context, grantee, granter sdk.AccAddress, authorization authz.Authorization, expiration *time.Time) error { - sdkCtx := sdk.UnwrapSDKContext(ctx) msgType := authorization.MsgTypeURL() - store := k.storeService.OpenKVStore(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) skey := grantStoreKey(grantee, granter, msgType) - grant, err := authz.NewGrant(sdkCtx.HeaderInfo().Time, authorization, expiration) + grant, err := authz.NewGrant(k.environment.HeaderService.GetHeaderInfo(ctx).Time, authorization, expiration) if err != nil { return err } @@ -222,7 +220,7 @@ func (k Keeper) SaveGrant(ctx context.Context, grantee, granter sdk.AccAddress, return err } - return sdkCtx.EventManager().EmitTypedEvent(&authz.EventGrant{ + return k.environment.EventService.EventManager(ctx).Emit(&authz.EventGrant{ MsgTypeUrl: authorization.MsgTypeURL(), Granter: granter.String(), Grantee: grantee.String(), @@ -232,7 +230,7 @@ func (k Keeper) SaveGrant(ctx context.Context, grantee, granter sdk.AccAddress, // DeleteGrant revokes any authorization for the provided message type granted to the grantee // by the granter. func (k Keeper) DeleteGrant(ctx context.Context, grantee, granter sdk.AccAddress, msgType string) error { - store := k.storeService.OpenKVStore(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) skey := grantStoreKey(grantee, granter, msgType) grant, found := k.getGrant(ctx, skey) if !found { @@ -251,8 +249,7 @@ func (k Keeper) DeleteGrant(ctx context.Context, grantee, granter sdk.AccAddress return err } - sdkCtx := sdk.UnwrapSDKContext(ctx) - return sdkCtx.EventManager().EmitTypedEvent(&authz.EventRevoke{ + return k.environment.EventService.EventManager(ctx).Emit(&authz.EventRevoke{ MsgTypeUrl: msgType, Granter: granter.String(), Grantee: grantee.String(), @@ -261,7 +258,7 @@ func (k Keeper) DeleteGrant(ctx context.Context, grantee, granter sdk.AccAddress // GetAuthorizations Returns list of `Authorizations` granted to the grantee by the granter. func (k Keeper) GetAuthorizations(ctx context.Context, grantee, granter sdk.AccAddress) ([]authz.Authorization, error) { - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx)) key := grantStoreKey(grantee, granter, "") iter := storetypes.KVStorePrefixIterator(store, key) defer iter.Close() @@ -290,9 +287,8 @@ func (k Keeper) GetAuthorizations(ctx context.Context, grantee, granter sdk.AccA // - A grant is found, but it is expired. // - There was an error getting the authorization from the grant. func (k Keeper) GetAuthorization(ctx context.Context, grantee, granter sdk.AccAddress, msgType string) (authz.Authorization, *time.Time) { - sdkCtx := sdk.UnwrapSDKContext(ctx) grant, found := k.getGrant(ctx, grantStoreKey(grantee, granter, msgType)) - if !found || (grant.Expiration != nil && grant.Expiration.Before(sdkCtx.HeaderInfo().Time)) { + if !found || (grant.Expiration != nil && grant.Expiration.Before(k.environment.HeaderService.GetHeaderInfo(ctx).Time)) { return nil, nil } @@ -311,7 +307,7 @@ func (k Keeper) GetAuthorization(ctx context.Context, grantee, granter sdk.AccAd func (k Keeper) IterateGrants(ctx context.Context, handler func(granterAddr, granteeAddr sdk.AccAddress, grant authz.Grant) bool, ) { - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx)) iter := storetypes.KVStorePrefixIterator(store, GrantKey) defer iter.Close() for ; iter.Valid(); iter.Next() { @@ -325,7 +321,7 @@ func (k Keeper) IterateGrants(ctx context.Context, } func (k Keeper) getGrantQueueItem(ctx context.Context, expiration time.Time, granter, grantee sdk.AccAddress) (*authz.GrantQueueItem, error) { - store := k.storeService.OpenKVStore(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) bz, err := store.Get(GrantQueueKey(expiration, granter, grantee)) if err != nil { return nil, err @@ -345,7 +341,7 @@ func (k Keeper) getGrantQueueItem(ctx context.Context, expiration time.Time, gra func (k Keeper) setGrantQueueItem(ctx context.Context, expiration time.Time, granter, grantee sdk.AccAddress, queueItems *authz.GrantQueueItem, ) error { - store := k.storeService.OpenKVStore(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) bz, err := k.cdc.Marshal(queueItems) if err != nil { return err @@ -366,7 +362,7 @@ func (k Keeper) insertIntoGrantQueue(ctx context.Context, granter, grantee sdk.A // removeFromGrantQueue removes a grant key from the grant queue func (k Keeper) removeFromGrantQueue(ctx context.Context, grantKey []byte, granter, grantee sdk.AccAddress, expiration time.Time) error { - store := k.storeService.OpenKVStore(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) key := GrantQueueKey(expiration, granter, grantee) bz, err := store.Get(key) if err != nil { @@ -385,9 +381,8 @@ func (k Keeper) removeFromGrantQueue(ctx context.Context, grantKey []byte, grant _, _, msgType := parseGrantStoreKey(grantKey) queueItems := queueItem.MsgTypeUrls - sdkCtx := sdk.UnwrapSDKContext(ctx) for index, typeURL := range queueItems { - sdkCtx.GasMeter().ConsumeGas(gasCostPerIteration, "grant queue") + k.environment.GasService.GetGasMeter(ctx).Consume(gasCostPerIteration, "grant queue") if typeURL == msgType { end := len(queueItem.MsgTypeUrls) - 1 @@ -408,10 +403,9 @@ func (k Keeper) removeFromGrantQueue(ctx context.Context, grantKey []byte, grant // DequeueAndDeleteExpiredGrants deletes expired grants from the state and grant queue. func (k Keeper) DequeueAndDeleteExpiredGrants(ctx context.Context, limit int) error { - store := k.storeService.OpenKVStore(ctx) - sdkCtx := sdk.UnwrapSDKContext(ctx) + store := k.environment.KVStoreService.OpenKVStore(ctx) - iterator, err := store.Iterator(GrantQueuePrefix, storetypes.InclusiveEndBytes(GrantQueueTimePrefix(sdkCtx.HeaderInfo().Time))) + iterator, err := store.Iterator(GrantQueuePrefix, storetypes.InclusiveEndBytes(GrantQueueTimePrefix(k.environment.HeaderService.GetHeaderInfo(ctx).Time))) if err != nil { return err } diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 0e7c563585..b984aeac2a 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -52,6 +52,7 @@ func (s *TestSuite) SetupTest() { testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now().Round(0).UTC()}) s.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + env := runtime.NewEnvironment(storeService, log.NewNopLogger()) s.baseApp = baseapp.NewBaseApp( "authz", @@ -74,7 +75,7 @@ func (s *TestSuite) SetupTest() { banktypes.RegisterInterfaces(s.encCfg.InterfaceRegistry) banktypes.RegisterMsgServer(s.baseApp.MsgServiceRouter(), s.bankKeeper) - s.authzKeeper = authzkeeper.NewKeeper(storeService, s.encCfg.Codec, s.baseApp.MsgServiceRouter(), s.accountKeeper) + s.authzKeeper = authzkeeper.NewKeeper(env, s.encCfg.Codec, s.baseApp.MsgServiceRouter(), s.accountKeeper) queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.encCfg.InterfaceRegistry) authz.RegisterQueryServer(queryHelper, s.authzKeeper) diff --git a/x/authz/keeper/migrations.go b/x/authz/keeper/migrations.go index b67e16433b..34cf0bdd45 100644 --- a/x/authz/keeper/migrations.go +++ b/x/authz/keeper/migrations.go @@ -18,5 +18,5 @@ func NewMigrator(keeper Keeper) Migrator { // Migrate1to2 migrates from version 1 to 2. func (m Migrator) Migrate1to2(ctx context.Context) error { - return v2.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc) + return v2.MigrateStore(ctx, m.keeper.environment, m.keeper.cdc) } diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 7d3ef08cd7..1a3e5f29f0 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -117,8 +117,9 @@ func (k Keeper) PruneExpiredGrants(ctx context.Context, msg *authz.MsgPruneExpir return nil, err } - sdkCtx := sdk.UnwrapSDKContext(ctx) - _ = sdkCtx.EventManager().EmitTypedEvent(&authz.EventPruneExpiredGrants{Pruner: msg.Pruner}) + if err := k.environment.EventService.EventManager(ctx).Emit(&authz.EventPruneExpiredGrants{Pruner: msg.Pruner}); err != nil { + return nil, err + } return &authz.MsgPruneExpiredGrantsResponse{}, nil } diff --git a/x/authz/migrations/v2/store.go b/x/authz/migrations/v2/store.go index 4443e989b5..b32cf92fcb 100644 --- a/x/authz/migrations/v2/store.go +++ b/x/authz/migrations/v2/store.go @@ -3,15 +3,13 @@ package v2 import ( "context" - corestoretypes "cosmossdk.io/core/store" + "cosmossdk.io/core/appmodule" "cosmossdk.io/store/prefix" - storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/authz" "cosmossdk.io/x/authz/internal/conv" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" ) // MigrateStore performs in-place store migrations from v0.45 to v0.46. The @@ -19,10 +17,8 @@ import ( // // - pruning expired authorizations // - create secondary index for pruning expired authorizations -func MigrateStore(ctx context.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error { - store := storeService.OpenKVStore(ctx) - sdkCtx := sdk.UnwrapSDKContext(ctx) - err := addExpiredGrantsIndex(sdkCtx, runtime.KVStoreAdapter(store), cdc) +func MigrateStore(ctx context.Context, env appmodule.Environment, cdc codec.BinaryCodec) error { + err := addExpiredGrantsIndex(ctx, env, cdc) if err != nil { return err } @@ -30,14 +26,15 @@ func MigrateStore(ctx context.Context, storeService corestoretypes.KVStoreServic return nil } -func addExpiredGrantsIndex(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error { +func addExpiredGrantsIndex(ctx context.Context, env appmodule.Environment, cdc codec.BinaryCodec) error { + store := runtime.KVStoreAdapter(env.KVStoreService.OpenKVStore(ctx)) grantsStore := prefix.NewStore(store, GrantPrefix) grantsIter := grantsStore.Iterator(nil, nil) defer grantsIter.Close() queueItems := make(map[string][]string) - now := ctx.HeaderInfo().Time + now := env.HeaderService.GetHeaderInfo(ctx).Time for ; grantsIter.Valid(); grantsIter.Next() { var grant authz.Grant bz := grantsIter.Value() diff --git a/x/authz/migrations/v2/store_test.go b/x/authz/migrations/v2/store_test.go index d41f33cb6f..00cdc53071 100644 --- a/x/authz/migrations/v2/store_test.go +++ b/x/authz/migrations/v2/store_test.go @@ -8,6 +8,7 @@ import ( govtypes "cosmossdk.io/api/cosmos/gov/v1beta1" "cosmossdk.io/core/header" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/authz" v2 "cosmossdk.io/x/authz/migrations/v2" @@ -104,6 +105,7 @@ func TestMigration(t *testing.T) { storeService := runtime.NewKVStoreService(authzKey) store := storeService.OpenKVStore(ctx) + env := runtime.NewEnvironment(storeService, log.NewNopLogger()) for _, g := range grants { grant := g.authorization() @@ -112,7 +114,7 @@ func TestMigration(t *testing.T) { } ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.Add(1 * time.Hour)}) - require.NoError(t, v2.MigrateStore(ctx, storeService, cdc)) + require.NoError(t, v2.MigrateStore(ctx, env, cdc)) bz, err := store.Get(v2.GrantStoreKey(grantee1, granter2, genericMsgType)) require.NoError(t, err) diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index a73423f533..f0494f267c 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -32,6 +32,7 @@ func TestExpiredGrantsQueue(t *testing.T) { testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) ctx := testCtx.Ctx + env := runtime.NewEnvironment(storeService, log.NewNopLogger()) baseApp := baseapp.NewBaseApp( "authz", @@ -65,7 +66,7 @@ func TestExpiredGrantsQueue(t *testing.T) { accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() - authzKeeper := keeper.NewKeeper(storeService, encCfg.Codec, baseApp.MsgServiceRouter(), accountKeeper) + authzKeeper := keeper.NewKeeper(env, encCfg.Codec, baseApp.MsgServiceRouter(), accountKeeper) save := func(grantee sdk.AccAddress, exp *time.Time) { err := authzKeeper.SaveGrant(ctx, grantee, granter, sendAuthz, exp) diff --git a/x/authz/module/depinject.go b/x/authz/module/depinject.go index 29d5a347d4..e3b11f50fe 100644 --- a/x/authz/module/depinject.go +++ b/x/authz/module/depinject.go @@ -3,7 +3,6 @@ package module import ( modulev1 "cosmossdk.io/api/cosmos/authz/module/v1" "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/store" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" "cosmossdk.io/x/authz" @@ -34,7 +33,7 @@ type ModuleInputs struct { BankKeeper authz.BankKeeper Registry cdctypes.InterfaceRegistry MsgServiceRouter baseapp.MessageRouter - StoreService store.KVStoreService + Environment appmodule.Environment } type ModuleOutputs struct { @@ -45,7 +44,7 @@ type ModuleOutputs struct { } func ProvideModule(in ModuleInputs) ModuleOutputs { - k := keeper.NewKeeper(in.StoreService, in.Cdc, in.MsgServiceRouter, in.AccountKeeper) + k := keeper.NewKeeper(in.Environment, in.Cdc, in.MsgServiceRouter, in.AccountKeeper) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) return ModuleOutputs{AuthzKeeper: k, Module: m} } diff --git a/x/authz/testutil/bank_helpers.go b/x/authz/testutil/bank_helpers.go index c3d6985945..b818ea8f80 100644 --- a/x/authz/testutil/bank_helpers.go +++ b/x/authz/testutil/bank_helpers.go @@ -8,22 +8,22 @@ import ( var _ bank.MsgServer = MockBankKeeper{} -func (k MockBankKeeper) Send(goCtx context.Context, msg *bank.MsgSend) (*bank.MsgSendResponse, error) { +func (k MockBankKeeper) Send(ctx context.Context, msg *bank.MsgSend) (*bank.MsgSendResponse, error) { return nil, nil } -func (k MockBankKeeper) Burn(goCtx context.Context, msg *bank.MsgBurn) (*bank.MsgBurnResponse, error) { +func (k MockBankKeeper) Burn(ctx context.Context, msg *bank.MsgBurn) (*bank.MsgBurnResponse, error) { return nil, nil } -func (k MockBankKeeper) MultiSend(goCtx context.Context, msg *bank.MsgMultiSend) (*bank.MsgMultiSendResponse, error) { +func (k MockBankKeeper) MultiSend(ctx context.Context, msg *bank.MsgMultiSend) (*bank.MsgMultiSendResponse, error) { return nil, nil } -func (k MockBankKeeper) UpdateParams(goCtx context.Context, req *bank.MsgUpdateParams) (*bank.MsgUpdateParamsResponse, error) { +func (k MockBankKeeper) UpdateParams(ctx context.Context, req *bank.MsgUpdateParams) (*bank.MsgUpdateParamsResponse, error) { return nil, nil } -func (k MockBankKeeper) SetSendEnabled(goCtx context.Context, req *bank.MsgSetSendEnabled) (*bank.MsgSetSendEnabledResponse, error) { +func (k MockBankKeeper) SetSendEnabled(ctx context.Context, req *bank.MsgSetSendEnabled) (*bank.MsgSetSendEnabledResponse, error) { return nil, nil }