SDK Core Audit - simapp updates (#9315)
* Make package imports consistent * Update comment * Update FundAccount/FundModuleAccount * Fix bench test Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
This commit is contained in:
co-authored by
atheeshp
parent
321aed823c
commit
9d0504808a
+5
-5
@@ -47,7 +47,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||
authz_m "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
|
||||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
@@ -115,7 +115,7 @@ var (
|
||||
feegrantmodule.AppModuleBasic{},
|
||||
upgrade.AppModuleBasic{},
|
||||
evidence.AppModuleBasic{},
|
||||
authz_m.AppModuleBasic{},
|
||||
authzmodule.AppModuleBasic{},
|
||||
vesting.AppModuleBasic{},
|
||||
)
|
||||
|
||||
@@ -173,7 +173,7 @@ type SimApp struct {
|
||||
// simulation manager
|
||||
sm *module.SimulationManager
|
||||
|
||||
// the configurator
|
||||
// module configurator
|
||||
configurator module.Configurator
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ func NewSimApp(
|
||||
upgrade.NewAppModule(app.UpgradeKeeper),
|
||||
evidence.NewAppModule(app.EvidenceKeeper),
|
||||
params.NewAppModule(app.ParamsKeeper),
|
||||
authz_m.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
|
||||
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
|
||||
)
|
||||
|
||||
// During begin block slashing happens after distr.BeginBlocker so that
|
||||
@@ -366,7 +366,7 @@ func NewSimApp(
|
||||
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
|
||||
params.NewAppModule(app.ParamsKeeper),
|
||||
evidence.NewAppModule(app.EvidenceKeeper),
|
||||
authz_m.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
|
||||
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
|
||||
)
|
||||
|
||||
app.sm.RegisterStoreDecoders()
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||
authz_m "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
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"
|
||||
@@ -168,7 +168,7 @@ func TestRunMigrations(t *testing.T) {
|
||||
module.VersionMap{
|
||||
"bank": 1,
|
||||
"auth": auth.AppModule{}.ConsensusVersion(),
|
||||
"authz": authz_m.AppModule{}.ConsensusVersion(),
|
||||
"authz": authzmodule.AppModule{}.ConsensusVersion(),
|
||||
"staking": staking.AppModule{}.ConsensusVersion(),
|
||||
"mint": mint.AppModule{}.ConsensusVersion(),
|
||||
"distribution": distribution.AppModule{}.ConsensusVersion(),
|
||||
@@ -219,7 +219,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
|
||||
module.VersionMap{
|
||||
"bank": bank.AppModule{}.ConsensusVersion(),
|
||||
"auth": auth.AppModule{}.ConsensusVersion(),
|
||||
"authz": authz_m.AppModule{}.ConsensusVersion(),
|
||||
"authz": authzmodule.AppModule{}.ConsensusVersion(),
|
||||
"staking": staking.AppModule{}.ConsensusVersion(),
|
||||
"mint": mint.AppModule{}.ConsensusVersion(),
|
||||
"distribution": distribution.AppModule{}.ConsensusVersion(),
|
||||
|
||||
+14
-4
@@ -108,10 +108,20 @@ func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simty
|
||||
panic(err)
|
||||
}
|
||||
|
||||
bankState.Balances = append(bankState.Balances, banktypes.Balance{
|
||||
Address: authtypes.NewModuleAddress(stakingtypes.NotBondedPoolName).String(),
|
||||
Coins: sdk.NewCoins(notBondedCoins),
|
||||
})
|
||||
stakingAddr := authtypes.NewModuleAddress(stakingtypes.NotBondedPoolName).String()
|
||||
var found bool
|
||||
for _, balance := range bankState.Balances {
|
||||
if balance.Address == stakingAddr {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
bankState.Balances = append(bankState.Balances, banktypes.Balance{
|
||||
Address: stakingAddr,
|
||||
Coins: sdk.NewCoins(notBondedCoins),
|
||||
})
|
||||
}
|
||||
|
||||
// change appState back
|
||||
rawState[stakingtypes.ModuleName] = cdc.MustMarshalJSON(stakingState)
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
@@ -443,12 +444,12 @@ func (ao EmptyAppOptions) Get(o string) interface{} {
|
||||
//
|
||||
// TODO: Instead of using the mint module account, which has the
|
||||
// permission of minting, create a "faucet" account. (@fdymylja)
|
||||
func FundAccount(app *SimApp, ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins) error {
|
||||
if err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
|
||||
func FundAccount(bankKeeper bankkeeper.Keeper, ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins) error {
|
||||
if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts)
|
||||
return bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts)
|
||||
}
|
||||
|
||||
// FundModuleAccount is a utility function that funds a module account by
|
||||
@@ -457,10 +458,10 @@ func FundAccount(app *SimApp, ctx sdk.Context, addr sdk.AccAddress, amounts sdk.
|
||||
//
|
||||
// TODO: Instead of using the mint module account, which has the
|
||||
// permission of minting, create a "faucet" account. (@fdymylja)
|
||||
func FundModuleAccount(app *SimApp, ctx sdk.Context, recipientMod string, amounts sdk.Coins) error {
|
||||
if err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
|
||||
func FundModuleAccount(bankKeeper bankkeeper.Keeper, ctx sdk.Context, recipientMod string, amounts sdk.Coins) error {
|
||||
if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, recipientMod, amounts)
|
||||
return bankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, recipientMod, amounts)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user