Skip to content

Commit

Permalink
fix(simulator): account keeper only used for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Jun 26, 2024
1 parent f2b3a4a commit d4eea29
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
10 changes: 6 additions & 4 deletions keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Keeper struct {
cdc codec.BinaryCodec

stakingKeeper *stakingkeeper.Keeper
accountKeeper AccountKeeper
accountKeeper AccountKeeper // for testing
slashKeeper SlashingKeeper
bankKeeper BankKeeper

Expand All @@ -47,7 +47,6 @@ func NewKeeper(
sk *stakingkeeper.Keeper,
slk SlashingKeeper,
bk BankKeeper,
ak AccountKeeper,
logger log.Logger,
) Keeper {
logger = logger.With(log.ModuleKey, "x/"+poa.ModuleName)
Expand All @@ -59,7 +58,6 @@ func NewKeeper(
stakingKeeper: sk,
slashKeeper: slk,
bankKeeper: bk,
accountKeeper: ak,
logger: logger,

// Stores
Expand Down Expand Up @@ -99,10 +97,14 @@ func (k Keeper) GetBankKeeper() BankKeeper {
return k.bankKeeper
}

func (k Keeper) GetAccountKeeper() AccountKeeper {
func (k *Keeper) GetTestAccountKeeper() AccountKeeper {
return k.accountKeeper
}

func (k *Keeper) SetTestAccountKeeper(ak AccountKeeper) {
k.accountKeeper = ak
}

// GetAdmins returns the module's administrators with delegation of power control.
func (k Keeper) GetAdmins(ctx context.Context) []string {
p, err := k.GetParams(ctx)
Expand Down
3 changes: 2 additions & 1 deletion keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func SetupTest(t *testing.T, baseValShares int64) *testFixture {
registerBaseSDKModules(f, encCfg, storeService, logger, require)

// Setup POA Keeper.
f.k = keeper.NewKeeper(encCfg.Codec, storeService, f.stakingKeeper, f.slashingKeeper, f.bankkeeper, f.accountkeeper, logger)
f.k = keeper.NewKeeper(encCfg.Codec, storeService, f.stakingKeeper, f.slashingKeeper, f.bankkeeper, logger)
f.k.SetTestAccountKeeper(f.accountkeeper)
f.msgServer = keeper.NewMsgServerImpl(f.k)
f.queryServer = keeper.NewQueryServerImpl(f.k)
f.appModule = poamodule.NewAppModule(encCfg.Codec, f.k)
Expand Down
4 changes: 1 addition & 3 deletions module/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
accountkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
Expand Down Expand Up @@ -48,7 +47,6 @@ type ModuleInputs struct {
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
BankKeeper bankkeeper.Keeper
AccountKeeper accountkeeper.AccountKeeper
}

type ModuleOutputs struct {
Expand All @@ -59,7 +57,7 @@ type ModuleOutputs struct {
}

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

return ModuleOutputs{Module: m, Keeper: k, Out: depinject.Out{}}
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ func NewSimApp(
app.StakingKeeper,
app.SlashingKeeper,
app.BankKeeper,
app.AccountKeeper,
logger,
)
app.POAKeeper.SetTestAccountKeeper(app.AccountKeeper)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down
2 changes: 1 addition & 1 deletion simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func newOperationInput(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, txGe
Msg: msg,
Context: ctx,
SimAccount: simAccount,
AccountKeeper: k.GetAccountKeeper(),
AccountKeeper: k.GetTestAccountKeeper(),
Bankkeeper: k.GetBankKeeper(),
ModuleName: poatypes.ModuleName,
}
Expand Down

0 comments on commit d4eea29

Please sign in to comment.