Skip to content

Commit c883624

Browse files
authored
refactor(auth): migrate to use env (#19476)
1 parent 72eae6d commit c883624

File tree

23 files changed

+51
-46
lines changed

23 files changed

+51
-46
lines changed

simapp/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func NewSimApp(
305305
}
306306
app.AccountsKeeper = accountsKeeper
307307

308-
app.AuthKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, addressCodec, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
308+
app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, addressCodec, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
309309

310310
app.BankKeeper = bankkeeper.NewBaseKeeper(
311311
appCodec,

tests/integration/bank/keeper/deterministic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
7777
}
7878

7979
accountKeeper := authkeeper.NewAccountKeeper(
80+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
8081
cdc,
81-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
8282
authtypes.ProtoBaseAccount,
8383
maccPerms,
8484
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),

tests/integration/distribution/keeper/msg_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ func initFixture(t *testing.T) *fixture {
8484
}
8585

8686
accountKeeper := authkeeper.NewAccountKeeper(
87+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
8788
cdc,
88-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
8989
authtypes.ProtoBaseAccount,
9090
maccPerms,
9191
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),

tests/integration/evidence/keeper/infraction_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func initFixture(tb testing.TB) *fixture {
104104
}
105105

106106
accountKeeper := authkeeper.NewAccountKeeper(
107+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
107108
cdc,
108-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
109109
authtypes.ProtoBaseAccount,
110110
maccPerms,
111111
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),

tests/integration/example/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func Example() {
4040
newCtx := sdk.NewContext(cms, true, logger)
4141

4242
accountKeeper := authkeeper.NewAccountKeeper(
43+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
4344
encodingCfg.Codec,
44-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
4545
authtypes.ProtoBaseAccount,
4646
map[string][]string{minttypes.ModuleName: {authtypes.Minter}},
4747
addresscodec.NewBech32Codec("cosmos"),
@@ -129,8 +129,8 @@ func Example_oneModule() {
129129
newCtx := sdk.NewContext(cms, true, logger)
130130

131131
accountKeeper := authkeeper.NewAccountKeeper(
132+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
132133
encodingCfg.Codec,
133-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
134134
authtypes.ProtoBaseAccount,
135135
map[string][]string{minttypes.ModuleName: {authtypes.Minter}},
136136
addresscodec.NewBech32Codec("cosmos"),

tests/integration/gov/keeper/keeper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func initFixture(tb testing.TB) *fixture {
7171
}
7272

7373
accountKeeper := authkeeper.NewAccountKeeper(
74+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
7475
cdc,
75-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
7676
authtypes.ProtoBaseAccount,
7777
maccPerms,
7878
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),

tests/integration/slashing/keeper/keeper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func initFixture(tb testing.TB) *fixture {
7272
}
7373

7474
accountKeeper := authkeeper.NewAccountKeeper(
75+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
7576
cdc,
76-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
7777
authtypes.ProtoBaseAccount,
7878
maccPerms,
7979
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),

tests/integration/staking/keeper/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func initFixture(tb testing.TB) *fixture {
121121
}
122122

123123
accountKeeper := authkeeper.NewAccountKeeper(
124+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
124125
cdc,
125-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
126126
authtypes.ProtoBaseAccount,
127127
maccPerms,
128128
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),

tests/integration/staking/keeper/deterministic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
8585
}
8686

8787
accountKeeper := authkeeper.NewAccountKeeper(
88+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
8889
cdc,
89-
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
9090
authtypes.ProtoBaseAccount,
9191
maccPerms,
9292
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),

x/auth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4646
* [#17985](https://github.com/cosmos/cosmos-sdk/pull/17985) Remove `StdTxConfig`
4747
* [#19161](https://github.com/cosmos/cosmos-sdk/pull/19161) Remove `simulate` from `SetGasMeter`
4848
* [#19363](https://github.com/cosmos/cosmos-sdk/pull/19363) Remove `IterateAccounts` and `GetAllAccounts` methods from the AccountKeeper interface and Keeper.
49+
* [#19290](https://github.com/cosmos/cosmos-sdk/issues/19290) Pass `appmodule.Environment` to NewKeeper instead of passing individual services.
4950

5051
### Consensus Breaking Changes
5152

x/auth/ante/testutil_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// ref: https://github.com/cosmos/cosmos-sdk/issues/14647
1212
_ "cosmossdk.io/api/cosmos/bank/v1beta1"
1313
_ "cosmossdk.io/api/cosmos/crypto/secp256k1"
14+
"cosmossdk.io/log"
1415
storetypes "cosmossdk.io/store/types"
1516
"cosmossdk.io/x/auth"
1617
"cosmossdk.io/x/auth/ante"
@@ -78,7 +79,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
7879
}
7980

8081
suite.accountKeeper = keeper.NewAccountKeeper(
81-
suite.encCfg.Codec, runtime.NewKVStoreService(key), types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"),
82+
runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"),
8283
sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(),
8384
)
8485
suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName)

x/auth/depinject.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
modulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
55
"cosmossdk.io/core/address"
66
"cosmossdk.io/core/appmodule"
7-
"cosmossdk.io/core/store"
87
"cosmossdk.io/depinject"
98
"cosmossdk.io/depinject/appconfig"
109
"cosmossdk.io/x/auth/keeper"
@@ -29,9 +28,9 @@ func init() {
2928
type ModuleInputs struct {
3029
depinject.In
3130

32-
Config *modulev1.Module
33-
StoreService store.KVStoreService
34-
Cdc codec.Codec
31+
Config *modulev1.Module
32+
Environment appmodule.Environment
33+
Cdc codec.Codec
3534

3635
AddressCodec address.Codec
3736
RandomGenesisAccountsFn types.RandomGenesisAccountsFn `optional:"true"`
@@ -70,7 +69,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
7069
panic(err)
7170
}
7271

73-
k := keeper.NewAccountKeeper(in.Cdc, in.StoreService, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth)
72+
k := keeper.NewAccountKeeper(in.Environment, in.Cdc, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth)
7473
m := NewAppModule(in.Cdc, k, in.RandomGenesisAccountsFn)
7574

7675
return ModuleOutputs{AccountKeeper: k, Module: m}

x/auth/keeper/deterministic_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"github.com/stretchr/testify/suite"
1010
"pgregory.net/rapid"
1111

12+
"cosmossdk.io/core/appmodule"
1213
"cosmossdk.io/core/header"
13-
corestore "cosmossdk.io/core/store"
14+
"cosmossdk.io/log"
1415
storetypes "cosmossdk.io/store/types"
1516
"cosmossdk.io/x/auth"
1617
authcodec "cosmossdk.io/x/auth/codec"
@@ -32,7 +33,7 @@ type DeterministicTestSuite struct {
3233
accountNumberLanes uint64
3334

3435
key *storetypes.KVStoreKey
35-
storeService corestore.KVStoreService
36+
environment appmodule.Environment
3637
ctx sdk.Context
3738
queryClient types.QueryClient
3839
accountKeeper keeper.AccountKeeper
@@ -56,6 +57,7 @@ func (suite *DeterministicTestSuite) SetupTest() {
5657
suite.Require()
5758
key := storetypes.NewKVStoreKey(types.StoreKey)
5859
storeService := runtime.NewKVStoreService(key)
60+
env := runtime.NewEnvironment(storeService, log.NewNopLogger())
5961
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
6062
suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{})
6163

@@ -69,8 +71,8 @@ func (suite *DeterministicTestSuite) SetupTest() {
6971
}
7072

7173
suite.accountKeeper = keeper.NewAccountKeeper(
74+
env,
7275
suite.encCfg.Codec,
73-
storeService,
7476
types.ProtoBaseAccount,
7577
maccPerms,
7678
authcodec.NewBech32Codec("cosmos"),
@@ -83,7 +85,7 @@ func (suite *DeterministicTestSuite) SetupTest() {
8385
suite.queryClient = types.NewQueryClient(queryHelper)
8486

8587
suite.key = key
86-
suite.storeService = storeService
88+
suite.environment = env
8789
suite.maccPerms = maccPerms
8890
suite.accountNumberLanes = 1
8991
}
@@ -289,8 +291,8 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccounts() {
289291
}
290292

291293
ak := keeper.NewAccountKeeper(
294+
suite.environment,
292295
suite.encCfg.Codec,
293-
suite.storeService,
294296
types.ProtoBaseAccount,
295297
maccPerms,
296298
authcodec.NewBech32Codec("cosmos"),
@@ -336,8 +338,8 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() {
336338
maccPerms[mName] = mPerms
337339

338340
ak := keeper.NewAccountKeeper(
341+
suite.environment,
339342
suite.encCfg.Codec,
340-
suite.storeService,
341343
types.ProtoBaseAccount,
342344
maccPerms,
343345
authcodec.NewBech32Codec("cosmos"),

x/auth/keeper/keeper.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"cosmossdk.io/collections"
99
"cosmossdk.io/collections/indexes"
1010
"cosmossdk.io/core/address"
11-
"cosmossdk.io/core/store"
11+
"cosmossdk.io/core/appmodule"
1212
errorsmod "cosmossdk.io/errors"
1313
"cosmossdk.io/log"
1414
"cosmossdk.io/x/auth/types"
@@ -82,7 +82,7 @@ func (a AccountsIndexes) IndexesList() []collections.Index[sdk.AccAddress, sdk.A
8282
type AccountKeeper struct {
8383
addressCodec address.Codec
8484

85-
storeService store.KVStoreService
85+
Environment appmodule.Environment
8686
cdc codec.BinaryCodec
8787
permAddrs map[string]types.PermissionsForAddress
8888
bech32Prefix string
@@ -111,20 +111,20 @@ var _ AccountKeeperI = &AccountKeeper{}
111111
// and don't have to fit into any predefined structure. This auth module does not use account permissions internally, though other modules
112112
// may use auth.Keeper to access the accounts permissions map.
113113
func NewAccountKeeper(
114-
cdc codec.BinaryCodec, storeService store.KVStoreService, proto func() sdk.AccountI,
114+
env appmodule.Environment, cdc codec.BinaryCodec, proto func() sdk.AccountI,
115115
maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string,
116116
) AccountKeeper {
117117
permAddrs := make(map[string]types.PermissionsForAddress)
118118
for name, perms := range maccPerms {
119119
permAddrs[name] = types.NewPermissionsForAddress(name, perms)
120120
}
121121

122-
sb := collections.NewSchemaBuilder(storeService)
122+
sb := collections.NewSchemaBuilder(env.KVStoreService)
123123

124124
ak := AccountKeeper{
125125
addressCodec: ac,
126126
bech32Prefix: bech32Prefix,
127-
storeService: storeService,
127+
Environment: env,
128128
proto: proto,
129129
cdc: cdc,
130130
permAddrs: permAddrs,
@@ -154,7 +154,7 @@ func (ak AccountKeeper) AddressCodec() address.Codec {
154154

155155
// Logger returns a module-specific logger.
156156
func (ak AccountKeeper) Logger(ctx context.Context) log.Logger {
157-
return sdk.UnwrapSDKContext(ctx).Logger().With("module", "x/"+types.ModuleName)
157+
return ak.Environment.Logger.With("module", "x/"+types.ModuleName)
158158
}
159159

160160
// GetPubKey Returns the PubKey of the account at address

x/auth/keeper/keeper_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/stretchr/testify/suite"
88

99
"cosmossdk.io/core/header"
10+
"cosmossdk.io/log"
1011
storetypes "cosmossdk.io/store/types"
1112
"cosmossdk.io/x/auth"
1213
authcodec "cosmossdk.io/x/auth/codec"
@@ -49,6 +50,7 @@ func (suite *KeeperTestSuite) SetupTest() {
4950

5051
key := storetypes.NewKVStoreKey(types.StoreKey)
5152
storeService := runtime.NewKVStoreService(key)
53+
env := runtime.NewEnvironment(storeService, log.NewNopLogger())
5254
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
5355
suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{})
5456

@@ -62,8 +64,8 @@ func (suite *KeeperTestSuite) SetupTest() {
6264
}
6365

6466
suite.accountKeeper = keeper.NewAccountKeeper(
67+
env,
6568
suite.encCfg.Codec,
66-
storeService,
6769
types.ProtoBaseAccount,
6870
maccPerms,
6971
authcodec.NewBech32Codec("cosmos"),

x/auth/keeper/migrations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (m Migrator) Migrate3to4(ctx context.Context) error {
4242
// It migrates the GlobalAccountNumber from being a protobuf defined value to a
4343
// big-endian encoded uint64, it also migrates it to use a more canonical prefix.
4444
func (m Migrator) Migrate4To5(ctx context.Context) error {
45-
return v5.Migrate(ctx, m.keeper.storeService, m.keeper.AccountNumber)
45+
return v5.Migrate(ctx, m.keeper.Environment.KVStoreService, m.keeper.AccountNumber)
4646
}
4747

4848
// V45_SetAccount implements V45_SetAccount
@@ -51,7 +51,7 @@ func (m Migrator) Migrate4To5(ctx context.Context) error {
5151
// NOTE: This is used for testing purposes only.
5252
func (m Migrator) V45SetAccount(ctx context.Context, acc sdk.AccountI) error {
5353
addr := acc.GetAddress()
54-
store := m.keeper.storeService.OpenKVStore(ctx)
54+
store := m.keeper.Environment.KVStoreService.OpenKVStore(ctx)
5555

5656
bz, err := m.keeper.Accounts.ValueCodec().Encode(acc)
5757
if err != nil {

x/auth/keeper/msg_server.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66

77
"cosmossdk.io/x/auth/types"
8-
9-
sdk "github.com/cosmos/cosmos-sdk/types"
108
)
119

1210
var _ types.MsgServer = msgServer{}
@@ -22,7 +20,7 @@ func NewMsgServerImpl(ak AccountKeeper) types.MsgServer {
2220
}
2321
}
2422

25-
func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
23+
func (ms msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
2624
if ms.ak.authority != msg.Authority {
2725
return nil, fmt.Errorf(
2826
"expected authority account as only signer for proposal message; invalid authority; expected %s, got %s",
@@ -33,7 +31,6 @@ func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdatePara
3331
return nil, err
3432
}
3533

36-
ctx := sdk.UnwrapSDKContext(goCtx)
3734
if err := ms.ak.Params.Set(ctx, msg.Params); err != nil {
3835
return nil, err
3936
}

x/auth/vesting/fuzz_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ func FuzzMsgServerCreateVestingAccount(f *testing.F) {
7777
}
7878

7979
key := storetypes.NewKVStoreKey(authtypes.StoreKey)
80-
storeService := runtime.NewKVStoreService(key)
81-
80+
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())
8281
maccPerms := map[string][]string{}
8382

8483
encCfg := moduletestutil.MakeTestEncodingConfig()
8584
accountKeeper := authkeeper.NewAccountKeeper(
85+
env,
8686
encCfg.Codec,
87-
storeService,
8887
authtypes.ProtoBaseAccount,
8988
maccPerms,
9089
address.NewBech32Codec("cosmos"),
@@ -103,6 +102,7 @@ func FuzzMsgServerCreateVestingAccount(f *testing.F) {
103102
return
104103
}
105104

105+
storeService := runtime.NewKVStoreService(key)
106106
ctrl := gomock.NewController(t)
107107
authKeeper := banktestutil.NewMockAccountKeeper(ctrl)
108108
authKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()

x/auth/vesting/msg_server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ func (s msgServer) CreateVestingAccount(ctx context.Context, msg *types.MsgCreat
8080
} else {
8181
start := msg.StartTime
8282
if msg.StartTime == 0 {
83-
sdkctx := sdk.UnwrapSDKContext(ctx)
84-
start = sdkctx.HeaderInfo().Time.Unix()
83+
start = s.AccountKeeper.Environment.HeaderService.GetHeaderInfo(ctx).Time.Unix()
8584
}
8685
vestingAccount = types.NewContinuousVestingAccountRaw(baseVestingAccount, start)
8786
}

0 commit comments

Comments
 (0)