Skip to content

Commit d4eea29

Browse files
committed
fix(simulator): account keeper only used for testing
1 parent f2b3a4a commit d4eea29

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

keeper/keeper.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Keeper struct {
2424
cdc codec.BinaryCodec
2525

2626
stakingKeeper *stakingkeeper.Keeper
27-
accountKeeper AccountKeeper
27+
accountKeeper AccountKeeper // for testing
2828
slashKeeper SlashingKeeper
2929
bankKeeper BankKeeper
3030

@@ -47,7 +47,6 @@ func NewKeeper(
4747
sk *stakingkeeper.Keeper,
4848
slk SlashingKeeper,
4949
bk BankKeeper,
50-
ak AccountKeeper,
5150
logger log.Logger,
5251
) Keeper {
5352
logger = logger.With(log.ModuleKey, "x/"+poa.ModuleName)
@@ -59,7 +58,6 @@ func NewKeeper(
5958
stakingKeeper: sk,
6059
slashKeeper: slk,
6160
bankKeeper: bk,
62-
accountKeeper: ak,
6361
logger: logger,
6462

6563
// Stores
@@ -99,10 +97,14 @@ func (k Keeper) GetBankKeeper() BankKeeper {
9997
return k.bankKeeper
10098
}
10199

102-
func (k Keeper) GetAccountKeeper() AccountKeeper {
100+
func (k *Keeper) GetTestAccountKeeper() AccountKeeper {
103101
return k.accountKeeper
104102
}
105103

104+
func (k *Keeper) SetTestAccountKeeper(ak AccountKeeper) {
105+
k.accountKeeper = ak
106+
}
107+
106108
// GetAdmins returns the module's administrators with delegation of power control.
107109
func (k Keeper) GetAdmins(ctx context.Context) []string {
108110
p, err := k.GetParams(ctx)

keeper/keeper_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func SetupTest(t *testing.T, baseValShares int64) *testFixture {
9090
registerBaseSDKModules(f, encCfg, storeService, logger, require)
9191

9292
// Setup POA Keeper.
93-
f.k = keeper.NewKeeper(encCfg.Codec, storeService, f.stakingKeeper, f.slashingKeeper, f.bankkeeper, f.accountkeeper, logger)
93+
f.k = keeper.NewKeeper(encCfg.Codec, storeService, f.stakingKeeper, f.slashingKeeper, f.bankkeeper, logger)
94+
f.k.SetTestAccountKeeper(f.accountkeeper)
9495
f.msgServer = keeper.NewMsgServerImpl(f.k)
9596
f.queryServer = keeper.NewQueryServerImpl(f.k)
9697
f.appModule = poamodule.NewAppModule(encCfg.Codec, f.k)

module/depinject.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/cosmos/cosmos-sdk/codec"
77
"github.com/cosmos/cosmos-sdk/types/module"
88
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
9-
accountkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
109
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
1110
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
1211
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
@@ -48,7 +47,6 @@ type ModuleInputs struct {
4847
StakingKeeper stakingkeeper.Keeper
4948
SlashingKeeper slashingkeeper.Keeper
5049
BankKeeper bankkeeper.Keeper
51-
AccountKeeper accountkeeper.AccountKeeper
5250
}
5351

5452
type ModuleOutputs struct {
@@ -59,7 +57,7 @@ type ModuleOutputs struct {
5957
}
6058

6159
func ProvideModule(in ModuleInputs) ModuleOutputs {
62-
k := keeper.NewKeeper(in.Cdc, in.StoreService, &in.StakingKeeper, in.SlashingKeeper, in.BankKeeper, in.AccountKeeper, log.NewLogger(os.Stderr))
60+
k := keeper.NewKeeper(in.Cdc, in.StoreService, &in.StakingKeeper, in.SlashingKeeper, in.BankKeeper, log.NewLogger(os.Stderr))
6361
m := NewAppModule(in.Cdc, k)
6462

6563
return ModuleOutputs{Module: m, Keeper: k, Out: depinject.Out{}}

simapp/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ func NewSimApp(
320320
app.StakingKeeper,
321321
app.SlashingKeeper,
322322
app.BankKeeper,
323-
app.AccountKeeper,
324323
logger,
325324
)
325+
app.POAKeeper.SetTestAccountKeeper(app.AccountKeeper)
326326

327327
// register the staking hooks
328328
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks

simulation/operations.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func newOperationInput(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, txGe
373373
Msg: msg,
374374
Context: ctx,
375375
SimAccount: simAccount,
376-
AccountKeeper: k.GetAccountKeeper(),
376+
AccountKeeper: k.GetTestAccountKeeper(),
377377
Bankkeeper: k.GetBankKeeper(),
378378
ModuleName: poatypes.ModuleName,
379379
}

0 commit comments

Comments
 (0)