Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-duplicate sim module setup #1664

Merged
merged 3 commits into from
Jun 20, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -237,35 +236,26 @@ func simulationModules(
) []module.AppModuleSimulation {
appCodec := encodingConfig.Marshaler

return []module.AppModuleSimulation{
auth.NewAppModule(appCodec, *app.AccountKeeper, authsims.RandomGenesisAccounts),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, *app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper, app.BankKeeper),
slashing.NewAppModule(appCodec, *app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper),
distr.NewAppModule(appCodec, *app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper),
staking.NewAppModule(appCodec, *app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
params.NewAppModule(*app.ParamsKeeper),
evidence.NewAppModule(*app.EvidenceKeeper),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
ibc.NewAppModule(app.IBCKeeper),
incentives.NewAppModule(appCodec, *app.IncentivesKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper),
lockup.NewAppModule(appCodec, *app.LockupKeeper, app.AccountKeeper, app.BankKeeper),
poolincentives.NewAppModule(appCodec, *app.PoolIncentivesKeeper),
superfluid.NewAppModule(
appCodec,
*app.SuperfluidKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.LockupKeeper,
app.GAMMKeeper,
app.EpochsKeeper,
),
app.TransferModule,
// recreate list of modules, to ensure no issues with overriding prior module structs.
modules := appModules(app, encodingConfig, skipGenesisInvariants)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the modules returned from appModules is different from the existing modules that were hard coded? Is this change intended / is there context that I missed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prior ones that weren't here were just forgotten tbh, because this was too much of a pain to maintain

overrideModules := map[string]module.AppModuleSimulation{
authtypes.ModuleName: auth.NewAppModule(appCodec, *app.AccountKeeper, authsims.RandomGenesisAccounts),
mattverse marked this conversation as resolved.
Show resolved Hide resolved
}

simModules := []module.AppModuleSimulation{}
for _, appModule := range modules {
// for every module, see if we override it. If so, use override.
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
// Else, if we can cast the app module into a simulation module add it.
// otherwise no simulation module.
if simModule, ok := overrideModules[appModule.Name()]; ok {
simModules = append(simModules, simModule)
} else {
if simModule, ok := appModule.(module.AppModuleSimulation); ok {
simModules = append(simModules, simModule)
}
}
}
return simModules
}

// ModuleAccountAddrs returns all the app's module account addresses.
Expand Down