Make app keepers public (#951)

* use ecosystem convention for keeper names in app.go

* fix linting

* Revert variable renaming

* Deprecate attribute access helper

* Formatting only

* Replace usage of deprecated test helper

* Address linter report

Co-authored-by: faddat <jacobgadikian@gmail.com>
This commit is contained in:
Alexander Peters
2022-08-23 17:01:04 +02:00
committed by GitHub
parent f14c46988a
commit 00082a25b8
18 changed files with 252 additions and 295 deletions

View File

@@ -243,33 +243,33 @@ type WasmApp struct {
memKeys map[string]*sdk.MemoryStoreKey memKeys map[string]*sdk.MemoryStoreKey
// keepers // keepers
accountKeeper authkeeper.AccountKeeper AccountKeeper authkeeper.AccountKeeper
bankKeeper bankkeeper.Keeper BankKeeper bankkeeper.Keeper
capabilityKeeper *capabilitykeeper.Keeper CapabilityKeeper *capabilitykeeper.Keeper
stakingKeeper stakingkeeper.Keeper StakingKeeper stakingkeeper.Keeper
slashingKeeper slashingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper
mintKeeper mintkeeper.Keeper MintKeeper mintkeeper.Keeper
distrKeeper distrkeeper.Keeper DistrKeeper distrkeeper.Keeper
govKeeper govkeeper.Keeper GovKeeper govkeeper.Keeper
crisisKeeper crisiskeeper.Keeper CrisisKeeper crisiskeeper.Keeper
upgradeKeeper upgradekeeper.Keeper UpgradeKeeper upgradekeeper.Keeper
paramsKeeper paramskeeper.Keeper ParamsKeeper paramskeeper.Keeper
evidenceKeeper evidencekeeper.Keeper EvidenceKeeper evidencekeeper.Keeper
ibcKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
icaControllerKeeper icacontrollerkeeper.Keeper ICAControllerKeeper icacontrollerkeeper.Keeper
icaHostKeeper icahostkeeper.Keeper ICAHostKeeper icahostkeeper.Keeper
interTxKeeper intertxkeeper.Keeper InterTxKeeper intertxkeeper.Keeper
transferKeeper ibctransferkeeper.Keeper TransferKeeper ibctransferkeeper.Keeper
feeGrantKeeper feegrantkeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper
authzKeeper authzkeeper.Keeper AuthzKeeper authzkeeper.Keeper
wasmKeeper wasm.Keeper WasmKeeper wasm.Keeper
scopedIBCKeeper capabilitykeeper.ScopedKeeper ScopedIBCKeeper capabilitykeeper.ScopedKeeper
scopedICAHostKeeper capabilitykeeper.ScopedKeeper ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
scopedICAControllerKeeper capabilitykeeper.ScopedKeeper ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
scopedInterTxKeeper capabilitykeeper.ScopedKeeper ScopedInterTxKeeper capabilitykeeper.ScopedKeeper
scopedTransferKeeper capabilitykeeper.ScopedKeeper ScopedTransferKeeper capabilitykeeper.ScopedKeeper
scopedWasmKeeper capabilitykeeper.ScopedKeeper ScopedWasmKeeper capabilitykeeper.ScopedKeeper
// the module manager // the module manager
mm *module.Manager mm *module.Manager
@@ -324,7 +324,7 @@ func NewWasmApp(
memKeys: memKeys, memKeys: memKeys,
} }
app.paramsKeeper = initParamsKeeper( app.ParamsKeeper = initParamsKeeper(
appCodec, appCodec,
legacyAmino, legacyAmino,
keys[paramstypes.StoreKey], keys[paramstypes.StoreKey],
@@ -332,86 +332,86 @@ func NewWasmApp(
) )
// set the BaseApp's parameter store // set the BaseApp's parameter store
bApp.SetParamStore(app.paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable())) bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
// add capability keeper and ScopeToModule for ibc module // add capability keeper and ScopeToModule for ibc module
app.capabilityKeeper = capabilitykeeper.NewKeeper( app.CapabilityKeeper = capabilitykeeper.NewKeeper(
appCodec, appCodec,
keys[capabilitytypes.StoreKey], keys[capabilitytypes.StoreKey],
memKeys[capabilitytypes.MemStoreKey], memKeys[capabilitytypes.MemStoreKey],
) )
scopedIBCKeeper := app.capabilityKeeper.ScopeToModule(ibchost.ModuleName) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedICAHostKeeper := app.capabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAControllerKeeper := app.capabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedInterTxKeeper := app.capabilityKeeper.ScopeToModule(intertxtypes.ModuleName) scopedInterTxKeeper := app.CapabilityKeeper.ScopeToModule(intertxtypes.ModuleName)
scopedTransferKeeper := app.capabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.capabilityKeeper.ScopeToModule(wasm.ModuleName) scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.capabilityKeeper.Seal() app.CapabilityKeeper.Seal()
// add keepers // add keepers
app.accountKeeper = authkeeper.NewAccountKeeper( app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, appCodec,
keys[authtypes.StoreKey], keys[authtypes.StoreKey],
app.getSubspace(authtypes.ModuleName), app.getSubspace(authtypes.ModuleName),
authtypes.ProtoBaseAccount, authtypes.ProtoBaseAccount,
maccPerms, maccPerms,
) )
app.bankKeeper = bankkeeper.NewBaseKeeper( app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, appCodec,
keys[banktypes.StoreKey], keys[banktypes.StoreKey],
app.accountKeeper, app.AccountKeeper,
app.getSubspace(banktypes.ModuleName), app.getSubspace(banktypes.ModuleName),
app.ModuleAccountAddrs(), app.ModuleAccountAddrs(),
) )
app.authzKeeper = authzkeeper.NewKeeper( app.AuthzKeeper = authzkeeper.NewKeeper(
keys[authzkeeper.StoreKey], keys[authzkeeper.StoreKey],
appCodec, appCodec,
app.BaseApp.MsgServiceRouter(), app.BaseApp.MsgServiceRouter(),
) )
app.feeGrantKeeper = feegrantkeeper.NewKeeper( app.FeeGrantKeeper = feegrantkeeper.NewKeeper(
appCodec, appCodec,
keys[feegrant.StoreKey], keys[feegrant.StoreKey],
app.accountKeeper, app.AccountKeeper,
) )
stakingKeeper := stakingkeeper.NewKeeper( stakingKeeper := stakingkeeper.NewKeeper(
appCodec, appCodec,
keys[stakingtypes.StoreKey], keys[stakingtypes.StoreKey],
app.accountKeeper, app.AccountKeeper,
app.bankKeeper, app.BankKeeper,
app.getSubspace(stakingtypes.ModuleName), app.getSubspace(stakingtypes.ModuleName),
) )
app.mintKeeper = mintkeeper.NewKeeper( app.MintKeeper = mintkeeper.NewKeeper(
appCodec, appCodec,
keys[minttypes.StoreKey], keys[minttypes.StoreKey],
app.getSubspace(minttypes.ModuleName), app.getSubspace(minttypes.ModuleName),
&stakingKeeper, &stakingKeeper,
app.accountKeeper, app.AccountKeeper,
app.bankKeeper, app.BankKeeper,
authtypes.FeeCollectorName, authtypes.FeeCollectorName,
) )
app.distrKeeper = distrkeeper.NewKeeper( app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, appCodec,
keys[distrtypes.StoreKey], keys[distrtypes.StoreKey],
app.getSubspace(distrtypes.ModuleName), app.getSubspace(distrtypes.ModuleName),
app.accountKeeper, app.AccountKeeper,
app.bankKeeper, app.BankKeeper,
&stakingKeeper, &stakingKeeper,
authtypes.FeeCollectorName, authtypes.FeeCollectorName,
app.ModuleAccountAddrs(), app.ModuleAccountAddrs(),
) )
app.slashingKeeper = slashingkeeper.NewKeeper( app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, appCodec,
keys[slashingtypes.StoreKey], keys[slashingtypes.StoreKey],
&stakingKeeper, &stakingKeeper,
app.getSubspace(slashingtypes.ModuleName), app.getSubspace(slashingtypes.ModuleName),
) )
app.crisisKeeper = crisiskeeper.NewKeeper( app.CrisisKeeper = crisiskeeper.NewKeeper(
app.getSubspace(crisistypes.ModuleName), app.getSubspace(crisistypes.ModuleName),
invCheckPeriod, invCheckPeriod,
app.bankKeeper, app.BankKeeper,
authtypes.FeeCollectorName, authtypes.FeeCollectorName,
) )
app.upgradeKeeper = upgradekeeper.NewKeeper( app.UpgradeKeeper = upgradekeeper.NewKeeper(
skipUpgradeHeights, skipUpgradeHeights,
keys[upgradetypes.StoreKey], keys[upgradetypes.StoreKey],
appCodec, appCodec,
@@ -421,16 +421,16 @@ func NewWasmApp(
// register the staking hooks // register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.stakingKeeper = *stakingKeeper.SetHooks( app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.distrKeeper.Hooks(), app.slashingKeeper.Hooks()), stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
) )
app.ibcKeeper = ibckeeper.NewKeeper( app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, appCodec,
keys[ibchost.StoreKey], keys[ibchost.StoreKey],
app.getSubspace(ibchost.ModuleName), app.getSubspace(ibchost.ModuleName),
app.stakingKeeper, app.StakingKeeper,
app.upgradeKeeper, app.UpgradeKeeper,
scopedIBCKeeper, scopedIBCKeeper,
) )
@@ -438,66 +438,66 @@ func NewWasmApp(
govRouter := govtypes.NewRouter() govRouter := govtypes.NewRouter()
govRouter. govRouter.
AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper)). AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.upgradeKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper)) AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
// Create Transfer Keepers // Create Transfer Keepers
app.transferKeeper = ibctransferkeeper.NewKeeper( app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, appCodec,
keys[ibctransfertypes.StoreKey], keys[ibctransfertypes.StoreKey],
app.getSubspace(ibctransfertypes.ModuleName), app.getSubspace(ibctransfertypes.ModuleName),
app.ibcKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper,
app.ibcKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper, &app.IBCKeeper.PortKeeper,
app.accountKeeper, app.AccountKeeper,
app.bankKeeper, app.BankKeeper,
scopedTransferKeeper, scopedTransferKeeper,
) )
transferModule := transfer.NewAppModule(app.transferKeeper) transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.transferKeeper) transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
app.icaHostKeeper = icahostkeeper.NewKeeper( app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, appCodec,
keys[icahosttypes.StoreKey], keys[icahosttypes.StoreKey],
app.getSubspace(icahosttypes.SubModuleName), app.getSubspace(icahosttypes.SubModuleName),
app.ibcKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper, &app.IBCKeeper.PortKeeper,
app.accountKeeper, app.AccountKeeper,
scopedICAHostKeeper, scopedICAHostKeeper,
app.MsgServiceRouter(), app.MsgServiceRouter(),
) )
app.icaControllerKeeper = icacontrollerkeeper.NewKeeper( app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, appCodec,
keys[icacontrollertypes.StoreKey], keys[icacontrollertypes.StoreKey],
app.getSubspace(icacontrollertypes.SubModuleName), app.getSubspace(icacontrollertypes.SubModuleName),
app.ibcKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
app.ibcKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper, &app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper, scopedICAControllerKeeper,
app.MsgServiceRouter(), app.MsgServiceRouter(),
) )
icaModule := ica.NewAppModule(&app.icaControllerKeeper, &app.icaHostKeeper) icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)
icaHostIBCModule := icahost.NewIBCModule(app.icaHostKeeper) icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper)
// For wasmd we use the demo controller from https://github.com/cosmos/interchain-accounts but see notes below // For wasmd we use the demo controller from https://github.com/cosmos/interchain-accounts but see notes below
app.interTxKeeper = intertxkeeper.NewKeeper(appCodec, keys[intertxtypes.StoreKey], app.icaControllerKeeper, scopedInterTxKeeper) app.InterTxKeeper = intertxkeeper.NewKeeper(appCodec, keys[intertxtypes.StoreKey], app.ICAControllerKeeper, scopedInterTxKeeper)
// Note: please do your research before using this in production app, this is a demo and not an officially // Note: please do your research before using this in production app, this is a demo and not an officially
// supported IBC team implementation. Do your own research before using it. // supported IBC team implementation. Do your own research before using it.
interTxModule := intertx.NewAppModule(appCodec, app.interTxKeeper) interTxModule := intertx.NewAppModule(appCodec, app.InterTxKeeper)
interTxIBCModule := intertx.NewIBCModule(app.interTxKeeper) interTxIBCModule := intertx.NewIBCModule(app.InterTxKeeper)
// You will likely want to swap out the second argument with your own reviewed and maintained ica auth module // You will likely want to swap out the second argument with your own reviewed and maintained ica auth module
icaControllerIBCModule := icacontroller.NewIBCModule(app.icaControllerKeeper, interTxIBCModule) icaControllerIBCModule := icacontroller.NewIBCModule(app.ICAControllerKeeper, interTxIBCModule)
// create evidence keeper with router // create evidence keeper with router
evidenceKeeper := evidencekeeper.NewKeeper( evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, appCodec,
keys[evidencetypes.StoreKey], keys[evidencetypes.StoreKey],
&app.stakingKeeper, &app.StakingKeeper,
app.slashingKeeper, app.SlashingKeeper,
) )
app.evidenceKeeper = *evidenceKeeper app.EvidenceKeeper = *evidenceKeeper
wasmDir := filepath.Join(homePath, "wasm") wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts) wasmConfig, err := wasm.ReadWasmConfig(appOpts)
@@ -508,18 +508,18 @@ func NewWasmApp(
// The last arguments can contain custom message handlers, and custom query handlers, // The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks // if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate" supportedFeatures := "iterator,staking,stargate"
app.wasmKeeper = wasm.NewKeeper( app.WasmKeeper = wasm.NewKeeper(
appCodec, appCodec,
keys[wasm.StoreKey], keys[wasm.StoreKey],
app.getSubspace(wasm.ModuleName), app.getSubspace(wasm.ModuleName),
app.accountKeeper, app.AccountKeeper,
app.bankKeeper, app.BankKeeper,
app.stakingKeeper, app.StakingKeeper,
app.distrKeeper, app.DistrKeeper,
app.ibcKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper, &app.IBCKeeper.PortKeeper,
scopedWasmKeeper, scopedWasmKeeper,
app.transferKeeper, app.TransferKeeper,
app.MsgServiceRouter(), app.MsgServiceRouter(),
app.GRPCQueryRouter(), app.GRPCQueryRouter(),
wasmDir, wasmDir,
@@ -533,22 +533,22 @@ func NewWasmApp(
// The gov proposal types can be individually enabled // The gov proposal types can be individually enabled
if len(enabledProposals) != 0 { if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals)) govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
} }
ibcRouter. ibcRouter.
AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.wasmKeeper, app.ibcKeeper.ChannelKeeper)). AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper)).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule). AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule). AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(intertxtypes.ModuleName, icaControllerIBCModule) AddRoute(intertxtypes.ModuleName, icaControllerIBCModule)
app.ibcKeeper.SetRouter(ibcRouter) app.IBCKeeper.SetRouter(ibcRouter)
app.govKeeper = govkeeper.NewKeeper( app.GovKeeper = govkeeper.NewKeeper(
appCodec, appCodec,
keys[govtypes.StoreKey], keys[govtypes.StoreKey],
app.getSubspace(govtypes.ModuleName), app.getSubspace(govtypes.ModuleName),
app.accountKeeper, app.AccountKeeper,
app.bankKeeper, app.BankKeeper,
&stakingKeeper, &stakingKeeper,
govRouter, govRouter,
) )
@@ -562,31 +562,31 @@ func NewWasmApp(
// must be passed by reference here. // must be passed by reference here.
app.mm = module.NewManager( app.mm = module.NewManager(
genutil.NewAppModule( genutil.NewAppModule(
app.accountKeeper, app.AccountKeeper,
app.stakingKeeper, app.StakingKeeper,
app.BaseApp.DeliverTx, app.BaseApp.DeliverTx,
encodingConfig.TxConfig, encodingConfig.TxConfig,
), ),
auth.NewAppModule(appCodec, app.accountKeeper, nil), auth.NewAppModule(appCodec, app.AccountKeeper, nil),
vesting.NewAppModule(app.accountKeeper, app.bankKeeper), vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.bankKeeper, app.accountKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.capabilityKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper),
gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.bankKeeper), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.distrKeeper, 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), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
upgrade.NewAppModule(app.upgradeKeeper), upgrade.NewAppModule(app.UpgradeKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.stakingKeeper, app.accountKeeper, app.bankKeeper), wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
evidence.NewAppModule(app.evidenceKeeper), evidence.NewAppModule(app.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.accountKeeper, app.bankKeeper, app.feeGrantKeeper, app.interfaceRegistry), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.bankKeeper, app.interfaceRegistry), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.ibcKeeper), ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.paramsKeeper), params.NewAppModule(app.ParamsKeeper),
transferModule, transferModule,
icaModule, icaModule,
interTxModule, interTxModule,
crisis.NewAppModule(&app.crisisKeeper, skipGenesisInvariants), // always be last to make sure that it checks for all invariants and not only part of them crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), // always be last to make sure that it checks for all invariants and not only part of them
) )
// During begin block slashing happens after distr.BeginBlocker so that // During begin block slashing happens after distr.BeginBlocker so that
@@ -679,7 +679,7 @@ func NewWasmApp(
// Uncomment if you want to set a custom migration order here. // Uncomment if you want to set a custom migration order here.
// app.mm.SetOrderMigrations(custom order) // app.mm.SetOrderMigrations(custom order)
app.mm.RegisterInvariants(&app.crisisKeeper) app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
@@ -690,20 +690,20 @@ func NewWasmApp(
// NOTE: this is not required apps that don't use the simulator for fuzz testing // NOTE: this is not required apps that don't use the simulator for fuzz testing
// transactions // transactions
app.sm = module.NewSimulationManager( app.sm = module.NewSimulationManager(
auth.NewAppModule(appCodec, app.accountKeeper, authsims.RandomGenesisAccounts), auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
bank.NewAppModule(appCodec, app.bankKeeper, app.accountKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.capabilityKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.accountKeeper, app.bankKeeper, app.feeGrantKeeper, app.interfaceRegistry), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.bankKeeper, app.interfaceRegistry), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.bankKeeper), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.bankKeeper), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
params.NewAppModule(app.paramsKeeper), params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.evidenceKeeper), evidence.NewAppModule(app.EvidenceKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.stakingKeeper, app.accountKeeper, app.bankKeeper), wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
ibc.NewAppModule(app.ibcKeeper), ibc.NewAppModule(app.IBCKeeper),
transferModule, transferModule,
) )
@@ -716,13 +716,13 @@ func NewWasmApp(
anteHandler, err := NewAnteHandler( anteHandler, err := NewAnteHandler(
HandlerOptions{ HandlerOptions{
HandlerOptions: ante.HandlerOptions{ HandlerOptions: ante.HandlerOptions{
AccountKeeper: app.accountKeeper, AccountKeeper: app.AccountKeeper,
BankKeeper: app.bankKeeper, BankKeeper: app.BankKeeper,
FeegrantKeeper: app.feeGrantKeeper, FeegrantKeeper: app.FeeGrantKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer, SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
}, },
IBCKeeper: app.ibcKeeper, IBCKeeper: app.IBCKeeper,
WasmConfig: &wasmConfig, WasmConfig: &wasmConfig,
TXCounterStoreKey: keys[wasm.StoreKey], TXCounterStoreKey: keys[wasm.StoreKey],
}, },
@@ -741,19 +741,19 @@ func NewWasmApp(
// see cmd/wasmd/root.go: 206 - 214 approx // see cmd/wasmd/root.go: 206 - 214 approx
if manager := app.SnapshotManager(); manager != nil { if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions( err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.wasmKeeper), wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
) )
if err != nil { if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err)) panic(fmt.Errorf("failed to register snapshot extension: %s", err))
} }
} }
app.scopedIBCKeeper = scopedIBCKeeper app.ScopedIBCKeeper = scopedIBCKeeper
app.scopedTransferKeeper = scopedTransferKeeper app.ScopedTransferKeeper = scopedTransferKeeper
app.scopedWasmKeeper = scopedWasmKeeper app.ScopedWasmKeeper = scopedWasmKeeper
app.scopedICAHostKeeper = scopedICAHostKeeper app.ScopedICAHostKeeper = scopedICAHostKeeper
app.scopedICAControllerKeeper = scopedICAControllerKeeper app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.scopedInterTxKeeper = scopedInterTxKeeper app.ScopedInterTxKeeper = scopedInterTxKeeper
if loadLatest { if loadLatest {
if err := app.LoadLatestVersion(); err != nil { if err := app.LoadLatestVersion(); err != nil {
@@ -762,7 +762,7 @@ func NewWasmApp(
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
// Initialize pinned codes in wasmvm as they are not persisted there // Initialize pinned codes in wasmvm as they are not persisted there
if err := app.wasmKeeper.InitializePinnedCodes(ctx); err != nil { if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err)) tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
} }
} }
@@ -790,7 +790,7 @@ func (app *WasmApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci
panic(err) panic(err)
} }
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()) app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState) return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
} }
@@ -822,7 +822,7 @@ func (app *WasmApp) LegacyAmino() *codec.LegacyAmino { //nolint:staticcheck
// //
// NOTE: This is solely to be used for testing purposes. // NOTE: This is solely to be used for testing purposes.
func (app *WasmApp) getSubspace(moduleName string) paramstypes.Subspace { func (app *WasmApp) getSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.paramsKeeper.GetSubspace(moduleName) subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace return subspace
} }

View File

@@ -47,7 +47,7 @@ func TestBlockedAddrs(t *testing.T) {
for acc := range maccPerms { for acc := range maccPerms {
t.Run(acc, func(t *testing.T) { t.Run(acc, func(t *testing.T) {
require.True(t, gapp.bankKeeper.BlockedAddr(gapp.accountKeeper.GetModuleAddress(acc)), require.True(t, gapp.BankKeeper.BlockedAddr(gapp.AccountKeeper.GetModuleAddress(acc)),
"ensure that blocked addresses are properly set in bank keeper", "ensure that blocked addresses are properly set in bank keeper",
) )
}) })

View File

@@ -35,7 +35,7 @@ func (app *WasmApp) ExportAppStateAndValidators(
return servertypes.ExportedApp{}, err return servertypes.ExportedApp{}, err
} }
validators, err := staking.WriteValidators(ctx, app.stakingKeeper) validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
return servertypes.ExportedApp{ return servertypes.ExportedApp{
AppState: appState, AppState: appState,
Validators: validators, Validators: validators,
@@ -46,7 +46,8 @@ func (app *WasmApp) ExportAppStateAndValidators(
// prepare for fresh start at zero height // prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated // NOTE zero height genesis is a temporary feature which will be deprecated
// in favour of export at a block height //
// in favour of export at a block height
func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false applyAllowedAddrs := false
@@ -66,18 +67,18 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
} }
/* Just to be safe, assert the invariants on current state. */ /* Just to be safe, assert the invariants on current state. */
app.crisisKeeper.AssertInvariants(ctx) app.CrisisKeeper.AssertInvariants(ctx)
/* Handle fee distribution state. */ /* Handle fee distribution state. */
// withdraw all validator commission // withdraw all validator commission
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.distrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint:errcheck _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint:errcheck
return false return false
}) })
// withdraw all delegator rewards // withdraw all delegator rewards
dels := app.stakingKeeper.GetAllDelegations(ctx) dels := app.StakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels { for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil { if err != nil {
@@ -88,28 +89,28 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
if err != nil { if err != nil {
panic(err) panic(err)
} }
_, _ = app.distrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) //nolint:errcheck _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) //nolint:errcheck
} }
// clear validator slash events // clear validator slash events
app.distrKeeper.DeleteAllValidatorSlashEvents(ctx) app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
// clear validator historical rewards // clear validator historical rewards
app.distrKeeper.DeleteAllValidatorHistoricalRewards(ctx) app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
// set context height to zero // set context height to zero
height := ctx.BlockHeight() height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0) ctx = ctx.WithBlockHeight(0)
// reinitialize all validators // reinitialize all validators
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool // donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.distrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.distrKeeper.GetFeePool(ctx) feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.distrKeeper.SetFeePool(ctx, feePool) app.DistrKeeper.SetFeePool(ctx, feePool)
app.distrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
return false return false
}) })
@@ -123,8 +124,8 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
if err != nil { if err != nil {
panic(err) panic(err)
} }
app.distrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr) app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
app.distrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr) app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
} }
// reset context height // reset context height
@@ -133,20 +134,20 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
/* Handle staking state. */ /* Handle staking state. */
// iterate through redelegations, reset creation height // iterate through redelegations, reset creation height
app.stakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries { for i := range red.Entries {
red.Entries[i].CreationHeight = 0 red.Entries[i].CreationHeight = 0
} }
app.stakingKeeper.SetRedelegation(ctx, red) app.StakingKeeper.SetRedelegation(ctx, red)
return false return false
}) })
// iterate through unbonding delegations, reset creation height // iterate through unbonding delegations, reset creation height
app.stakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries { for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0 ubd.Entries[i].CreationHeight = 0
} }
app.stakingKeeper.SetUnbondingDelegation(ctx, ubd) app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
return false return false
}) })
@@ -158,7 +159,7 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
for ; iter.Valid(); iter.Next() { for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:]) addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.stakingKeeper.GetValidator(ctx, addr) validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found { if !found {
panic("expected validator, not found") panic("expected validator, not found")
} }
@@ -168,13 +169,13 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
validator.Jailed = true validator.Jailed = true
} }
app.stakingKeeper.SetValidator(ctx, validator) app.StakingKeeper.SetValidator(ctx, validator)
counter++ counter++
} }
iter.Close() iter.Close()
_, err := app.stakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -182,11 +183,11 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
/* Handle slashing state. */ /* Handle slashing state. */
// reset start height on signing infos // reset start height on signing infos
app.slashingKeeper.IterateValidatorSigningInfos( app.SlashingKeeper.IterateValidatorSigningInfos(
ctx, ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0 info.StartHeight = 0
app.slashingKeeper.SetValidatorSigningInfo(ctx, addr, info) app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
return false return false
}, },
) )

View File

@@ -213,7 +213,7 @@ func TestAppImportExport(t *testing.T) {
normalizeContractInfo := func(ctx sdk.Context, app *WasmApp) { normalizeContractInfo := func(ctx sdk.Context, app *WasmApp) {
var index uint64 var index uint64
app.wasmKeeper.IterateContractInfo(ctx, func(address sdk.AccAddress, info wasmtypes.ContractInfo) bool { app.WasmKeeper.IterateContractInfo(ctx, func(address sdk.AccAddress, info wasmtypes.ContractInfo) bool {
created := &wasmtypes.AbsoluteTxPosition{ created := &wasmtypes.AbsoluteTxPosition{
BlockHeight: uint64(0), BlockHeight: uint64(0),
TxIndex: index, TxIndex: index,

View File

@@ -18,6 +18,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm" "github.com/CosmWasm/wasmd/x/wasm"
) )
// Deprecated: use public app attributes directly
type TestSupport struct { type TestSupport struct {
t testing.TB t testing.TB
app *WasmApp app *WasmApp
@@ -28,11 +29,11 @@ func NewTestSupport(t testing.TB, app *WasmApp) *TestSupport {
} }
func (s TestSupport) IBCKeeper() *ibckeeper.Keeper { func (s TestSupport) IBCKeeper() *ibckeeper.Keeper {
return s.app.ibcKeeper return s.app.IBCKeeper
} }
func (s TestSupport) WasmKeeper() wasm.Keeper { func (s TestSupport) WasmKeeper() wasm.Keeper {
return s.app.wasmKeeper return s.app.WasmKeeper
} }
func (s TestSupport) AppCodec() codec.Codec { func (s TestSupport) AppCodec() codec.Codec {
@@ -40,27 +41,27 @@ func (s TestSupport) AppCodec() codec.Codec {
} }
func (s TestSupport) ScopedWasmIBCKeeper() capabilitykeeper.ScopedKeeper { func (s TestSupport) ScopedWasmIBCKeeper() capabilitykeeper.ScopedKeeper {
return s.app.scopedWasmKeeper return s.app.ScopedWasmKeeper
} }
func (s TestSupport) ScopeIBCKeeper() capabilitykeeper.ScopedKeeper { func (s TestSupport) ScopeIBCKeeper() capabilitykeeper.ScopedKeeper {
return s.app.scopedIBCKeeper return s.app.ScopedIBCKeeper
} }
func (s TestSupport) ScopedTransferKeeper() capabilitykeeper.ScopedKeeper { func (s TestSupport) ScopedTransferKeeper() capabilitykeeper.ScopedKeeper {
return s.app.scopedTransferKeeper return s.app.ScopedTransferKeeper
} }
func (s TestSupport) StakingKeeper() stakingkeeper.Keeper { func (s TestSupport) StakingKeeper() stakingkeeper.Keeper {
return s.app.stakingKeeper return s.app.StakingKeeper
} }
func (s TestSupport) BankKeeper() bankkeeper.Keeper { func (s TestSupport) BankKeeper() bankkeeper.Keeper {
return s.app.bankKeeper return s.app.BankKeeper
} }
func (s TestSupport) TransferKeeper() ibctransferkeeper.Keeper { func (s TestSupport) TransferKeeper() ibctransferkeeper.Keeper {
return s.app.transferKeeper return s.app.TransferKeeper
} }
func (s TestSupport) GetBaseApp() *baseapp.BaseApp { func (s TestSupport) GetBaseApp() *baseapp.BaseApp {

View File

@@ -201,7 +201,7 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress {
// AddTestAddrsFromPubKeys adds the addresses into the WasmApp providing only the public keys. // AddTestAddrsFromPubKeys adds the addresses into the WasmApp providing only the public keys.
func AddTestAddrsFromPubKeys(app *WasmApp, ctx sdk.Context, pubKeys []cryptotypes.PubKey, accAmt sdk.Int) { func AddTestAddrsFromPubKeys(app *WasmApp, ctx sdk.Context, pubKeys []cryptotypes.PubKey, accAmt sdk.Int) {
initCoins := sdk.NewCoins(sdk.NewCoin(app.stakingKeeper.BondDenom(ctx), accAmt)) initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
for _, pk := range pubKeys { for _, pk := range pubKeys {
initAccountWithCoins(app, ctx, sdk.AccAddress(pk.Address()), initCoins) initAccountWithCoins(app, ctx, sdk.AccAddress(pk.Address()), initCoins)
@@ -223,7 +223,7 @@ func AddTestAddrsIncremental(app *WasmApp, ctx sdk.Context, accNum int, accAmt s
func addTestAddrs(app *WasmApp, ctx sdk.Context, accNum int, accAmt sdk.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { func addTestAddrs(app *WasmApp, ctx sdk.Context, accNum int, accAmt sdk.Int, strategy GenerateAccountStrategy) []sdk.AccAddress {
testAddrs := strategy(accNum) testAddrs := strategy(accNum)
initCoins := sdk.NewCoins(sdk.NewCoin(app.stakingKeeper.BondDenom(ctx), accAmt)) initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
// fill all the addresses with some coins, set the loose pool tokens simultaneously // fill all the addresses with some coins, set the loose pool tokens simultaneously
for _, addr := range testAddrs { for _, addr := range testAddrs {
@@ -234,12 +234,12 @@ func addTestAddrs(app *WasmApp, ctx sdk.Context, accNum int, accAmt sdk.Int, str
} }
func initAccountWithCoins(app *WasmApp, ctx sdk.Context, addr sdk.AccAddress, coins sdk.Coins) { func initAccountWithCoins(app *WasmApp, ctx sdk.Context, addr sdk.AccAddress, coins sdk.Coins) {
err := app.bankKeeper.MintCoins(ctx, minttypes.ModuleName, coins) err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins)
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = app.bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, coins) err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, coins)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -280,7 +280,7 @@ func TestAddr(addr string, bech string) (sdk.AccAddress, error) {
// CheckBalance checks the balance of an account. // CheckBalance checks the balance of an account.
func CheckBalance(t *testing.T, app *WasmApp, addr sdk.AccAddress, balances sdk.Coins) { func CheckBalance(t *testing.T, app *WasmApp, addr sdk.AccAddress, balances sdk.Coins) {
ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{})
require.True(t, balances.IsEqual(app.bankKeeper.GetAllBalances(ctxCheck, addr))) require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr)))
} }
const DefaultGas = 1200000 const DefaultGas = 1200000

View File

@@ -7,7 +7,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"strconv" "strconv"
wasmvm "github.com/CosmWasm/wasmvm" wasmvm "github.com/CosmWasm/wasmvm"
@@ -174,7 +174,7 @@ func GetCmdQueryCode() *cobra.Command {
} }
fmt.Printf("Downloading wasm code to %s\n", args[1]) fmt.Printf("Downloading wasm code to %s\n", args[1])
return ioutil.WriteFile(args[1], res.Data, 0o600) return os.WriteFile(args[1], res.Data, 0o600)
}, },
} }
flags.AddQueryFlagsToCmd(cmd) flags.AddQueryFlagsToCmd(cmd)

View File

@@ -3,7 +3,7 @@ package cli
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"strconv" "strconv"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
@@ -81,7 +81,7 @@ func StoreCodeCmd() *cobra.Command {
} }
func parseStoreCodeArgs(file string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgStoreCode, error) { func parseStoreCodeArgs(file string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgStoreCode, error) {
wasm, err := ioutil.ReadFile(file) wasm, err := os.ReadFile(file)
if err != nil { if err != nil {
return types.MsgStoreCode{}, err return types.MsgStoreCode{}, err
} }

View File

@@ -6,7 +6,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
@@ -17,7 +16,6 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking" "github.com/cosmos/cosmos-sdk/x/staking/teststaking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
@@ -25,10 +23,8 @@ import (
commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host" host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"github.com/cosmos/ibc-go/v3/modules/core/exported" "github.com/cosmos/ibc-go/v3/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
"github.com/cosmos/ibc-go/v3/modules/core/types" "github.com/cosmos/ibc-go/v3/modules/core/types"
ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
"github.com/cosmos/ibc-go/v3/testing/mock" "github.com/cosmos/ibc-go/v3/testing/mock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
@@ -38,7 +34,9 @@ import (
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
tmversion "github.com/tendermint/tendermint/version" tmversion "github.com/tendermint/tendermint/version"
wasmd "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/app/params"
"github.com/CosmWasm/wasmd/x/wasm" "github.com/CosmWasm/wasmd/x/wasm"
) )
@@ -51,7 +49,7 @@ type TestChain struct {
t *testing.T t *testing.T
Coordinator *Coordinator Coordinator *Coordinator
App ibctesting.TestingApp App *app.WasmApp
ChainID string ChainID string
LastHeader *ibctmtypes.Header // header for last block height committed LastHeader *ibctmtypes.Header // header for last block height committed
CurrentHeader tmproto.Header // header for current block height CurrentHeader tmproto.Header // header for current block height
@@ -104,7 +102,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string, opts ...wasm
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)), Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)),
} }
app := NewTestingAppDecorator(t, wasmd.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, opts, balance)) wasmApp := app.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, opts, balance)
// create current header and call begin block // create current header and call begin block
header := tmproto.Header{ header := tmproto.Header{
@@ -113,18 +111,18 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string, opts ...wasm
Time: coord.CurrentTime.UTC(), Time: coord.CurrentTime.UTC(),
} }
txConfig := app.GetTxConfig() txConfig := params.MakeEncodingConfig().TxConfig
// create an account to send transactions from // create an account to send transactions from
chain := &TestChain{ chain := &TestChain{
t: t, t: t,
Coordinator: coord, Coordinator: coord,
ChainID: chainID, ChainID: chainID,
App: app, App: wasmApp,
CurrentHeader: header, CurrentHeader: header,
QueryServer: app.GetIBCKeeper(), QueryServer: wasmApp.IBCKeeper,
TxConfig: txConfig, TxConfig: txConfig,
Codec: app.AppCodec(), Codec: wasmApp.AppCodec(),
Vals: valSet, Vals: valSet,
Signers: signers, Signers: signers,
senderPrivKey: senderPrivKey, senderPrivKey: senderPrivKey,
@@ -138,7 +136,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string, opts ...wasm
// GetContext returns the current context for the application. // GetContext returns the current context for the application.
func (chain *TestChain) GetContext() sdk.Context { func (chain *TestChain) GetContext() sdk.Context {
return chain.App.GetBaseApp().NewContext(false, chain.CurrentHeader) return chain.App.BaseApp.NewContext(false, chain.CurrentHeader)
} }
// QueryProof performs an abci query with the given key and returns the proto encoded merkle proof // QueryProof performs an abci query with the given key and returns the proto encoded merkle proof
@@ -244,10 +242,10 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
// ensure the chain has the latest time // ensure the chain has the latest time
chain.Coordinator.UpdateTimeForChain(chain) chain.Coordinator.UpdateTimeForChain(chain)
_, r, err := wasmd.SignAndDeliver( _, r, err := app.SignAndDeliver(
chain.t, chain.t,
chain.TxConfig, chain.TxConfig,
chain.App.GetBaseApp(), chain.App.BaseApp,
chain.GetContext().BlockHeader(), chain.GetContext().BlockHeader(),
msgs, msgs,
chain.ChainID, chain.ChainID,
@@ -291,7 +289,7 @@ func (chain *TestChain) captureIBCEvents(r *sdk.Result) {
// GetClientState retrieves the client state for the provided clientID. The client is // GetClientState retrieves the client state for the provided clientID. The client is
// expected to exist otherwise testing will fail. // expected to exist otherwise testing will fail.
func (chain *TestChain) GetClientState(clientID string) exported.ClientState { func (chain *TestChain) GetClientState(clientID string) exported.ClientState {
clientState, found := chain.App.GetIBCKeeper().ClientKeeper.GetClientState(chain.GetContext(), clientID) clientState, found := chain.App.IBCKeeper.ClientKeeper.GetClientState(chain.GetContext(), clientID)
require.True(chain.t, found) require.True(chain.t, found)
return clientState return clientState
@@ -300,13 +298,13 @@ func (chain *TestChain) GetClientState(clientID string) exported.ClientState {
// GetConsensusState retrieves the consensus state for the provided clientID and height. // GetConsensusState retrieves the consensus state for the provided clientID and height.
// It will return a success boolean depending on if consensus state exists or not. // It will return a success boolean depending on if consensus state exists or not.
func (chain *TestChain) GetConsensusState(clientID string, height exported.Height) (exported.ConsensusState, bool) { func (chain *TestChain) GetConsensusState(clientID string, height exported.Height) (exported.ConsensusState, bool) {
return chain.App.GetIBCKeeper().ClientKeeper.GetClientConsensusState(chain.GetContext(), clientID, height) return chain.App.IBCKeeper.ClientKeeper.GetClientConsensusState(chain.GetContext(), clientID, height)
} }
// GetValsAtHeight will return the validator set of the chain at a given height. It will return // GetValsAtHeight will return the validator set of the chain at a given height. It will return
// a success boolean depending on if the validator set exists or not at that height. // a success boolean depending on if the validator set exists or not at that height.
func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bool) { func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bool) {
histInfo, ok := chain.App.GetStakingKeeper().GetHistoricalInfo(chain.GetContext(), height) histInfo, ok := chain.App.StakingKeeper.GetHistoricalInfo(chain.GetContext(), height)
if !ok { if !ok {
return nil, false return nil, false
} }
@@ -323,7 +321,7 @@ func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bo
// GetAcknowledgement retrieves an acknowledgement for the provided packet. If the // GetAcknowledgement retrieves an acknowledgement for the provided packet. If the
// acknowledgement does not exist then testing will fail. // acknowledgement does not exist then testing will fail.
func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte { func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte {
ack, found := chain.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(chain.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) ack, found := chain.App.IBCKeeper.ChannelKeeper.GetPacketAcknowledgement(chain.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
require.True(chain.t, found) require.True(chain.t, found)
return ack return ack
@@ -331,7 +329,7 @@ func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte {
// GetPrefix returns the prefix for used by a chain in connection creation // GetPrefix returns the prefix for used by a chain in connection creation
func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix { func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix {
return commitmenttypes.NewMerklePrefix(chain.App.GetIBCKeeper().ConnectionKeeper.GetCommitmentPrefix().Bytes()) return commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())
} }
// ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the // ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the
@@ -490,10 +488,10 @@ func CreateSortedSignerArray(altPrivVal, suitePrivVal tmtypes.PrivValidator,
// Other applications must bind to the port in InitGenesis or modify this code. // Other applications must bind to the port in InitGenesis or modify this code.
func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID string) { func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID string) {
// check if the portId is already binded, if not bind it // check if the portId is already binded, if not bind it
_, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.PortPath(portID)) _, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.PortPath(portID))
if !ok { if !ok {
// create capability using the IBC capability keeper // create capability using the IBC capability keeper
cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), host.PortPath(portID)) cap, err := chain.App.ScopedIBCKeeper.NewCapability(chain.GetContext(), host.PortPath(portID))
require.NoError(chain.t, err) require.NoError(chain.t, err)
// claim capability using the scopedKeeper // claim capability using the scopedKeeper
@@ -509,7 +507,7 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope
// GetPortCapability returns the port capability for the given portID. The capability must // GetPortCapability returns the port capability for the given portID. The capability must
// exist, otherwise testing will fail. // exist, otherwise testing will fail.
func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability { func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability {
cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.PortPath(portID)) cap, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.PortPath(portID))
require.True(chain.t, ok) require.True(chain.t, ok)
return cap return cap
@@ -521,9 +519,9 @@ func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capabi
func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID, channelID string) { func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID, channelID string) {
capName := host.ChannelCapabilityPath(portID, channelID) capName := host.ChannelCapabilityPath(portID, channelID)
// check if the portId is already binded, if not bind it // check if the portId is already binded, if not bind it
_, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), capName) _, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), capName)
if !ok { if !ok {
cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), capName) cap, err := chain.App.ScopedIBCKeeper.NewCapability(chain.GetContext(), capName)
require.NoError(chain.t, err) require.NoError(chain.t, err)
err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, capName) err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, capName)
require.NoError(chain.t, err) require.NoError(chain.t, err)
@@ -537,55 +535,16 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc
// GetChannelCapability returns the channel capability for the given portID and channelID. // GetChannelCapability returns the channel capability for the given portID and channelID.
// The capability must exist, otherwise testing will fail. // The capability must exist, otherwise testing will fail.
func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability { func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability {
cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.ChannelCapabilityPath(portID, channelID)) cap, ok := chain.App.ScopedIBCKeeper.GetCapability(chain.GetContext(), host.ChannelCapabilityPath(portID, channelID))
require.True(chain.t, ok) require.True(chain.t, ok)
return cap return cap
} }
func (chain *TestChain) Balance(acc sdk.AccAddress, denom string) sdk.Coin { func (chain *TestChain) Balance(acc sdk.AccAddress, denom string) sdk.Coin {
return chain.GetTestSupport().BankKeeper().GetBalance(chain.GetContext(), acc, denom) return chain.App.BankKeeper.GetBalance(chain.GetContext(), acc, denom)
} }
func (chain *TestChain) AllBalances(acc sdk.AccAddress) sdk.Coins { func (chain *TestChain) AllBalances(acc sdk.AccAddress) sdk.Coins {
return chain.GetTestSupport().BankKeeper().GetAllBalances(chain.GetContext(), acc) return chain.App.BankKeeper.GetAllBalances(chain.GetContext(), acc)
}
func (chain TestChain) GetTestSupport() *wasmd.TestSupport {
return chain.App.(*TestingAppDecorator).TestSupport()
}
var _ ibctesting.TestingApp = TestingAppDecorator{}
type TestingAppDecorator struct {
*wasmd.WasmApp
t *testing.T
}
func NewTestingAppDecorator(t *testing.T, wasmApp *wasmd.WasmApp) *TestingAppDecorator {
return &TestingAppDecorator{WasmApp: wasmApp, t: t}
}
func (a TestingAppDecorator) GetBaseApp() *baseapp.BaseApp {
return a.TestSupport().GetBaseApp()
}
func (a TestingAppDecorator) GetStakingKeeper() stakingkeeper.Keeper {
return a.TestSupport().StakingKeeper()
}
func (a TestingAppDecorator) GetIBCKeeper() *ibckeeper.Keeper {
return a.TestSupport().IBCKeeper()
}
func (a TestingAppDecorator) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return a.TestSupport().ScopeIBCKeeper()
}
func (a TestingAppDecorator) GetTxConfig() client.TxConfig {
return a.TestSupport().GetTxConfig()
}
func (a TestingAppDecorator) TestSupport() *wasmd.TestSupport {
return wasmd.NewTestSupport(a.t, a.WasmApp)
} }

View File

@@ -381,7 +381,7 @@ func (endpoint *Endpoint) SendPacket(packet exported.PacketI) error {
channelCap := endpoint.Chain.GetChannelCapability(packet.GetSourcePort(), packet.GetSourceChannel()) channelCap := endpoint.Chain.GetChannelCapability(packet.GetSourcePort(), packet.GetSourceChannel())
// no need to send message, acting as a module // no need to send message, acting as a module
err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, packet) err := endpoint.Chain.App.IBCKeeper.ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, packet)
if err != nil { if err != nil {
return err return err
} }
@@ -415,7 +415,7 @@ func (endpoint *Endpoint) WriteAcknowledgement(ack exported.Acknowledgement, pac
channelCap := endpoint.Chain.GetChannelCapability(packet.GetDestPort(), packet.GetDestChannel()) channelCap := endpoint.Chain.GetChannelCapability(packet.GetDestPort(), packet.GetDestChannel())
// no need to send message, acting as a handler // no need to send message, acting as a handler
err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.WriteAcknowledgement(endpoint.Chain.GetContext(), channelCap, packet, ack) err := endpoint.Chain.App.IBCKeeper.ChannelKeeper.WriteAcknowledgement(endpoint.Chain.GetContext(), channelCap, packet, ack)
if err != nil { if err != nil {
return err return err
} }
@@ -452,7 +452,7 @@ func (endpoint *Endpoint) TimeoutPacket(packet channeltypes.Packet) error {
} }
proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey)
nextSeqRecv, found := endpoint.Counterparty.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceRecv(endpoint.Counterparty.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID) nextSeqRecv, found := endpoint.Counterparty.Chain.App.IBCKeeper.ChannelKeeper.GetNextSequenceRecv(endpoint.Counterparty.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID)
require.True(endpoint.Chain.t, found) require.True(endpoint.Chain.t, found)
timeoutMsg := channeltypes.NewMsgTimeout( timeoutMsg := channeltypes.NewMsgTimeout(
@@ -468,7 +468,7 @@ func (endpoint *Endpoint) SetChannelClosed() error {
channel := endpoint.GetChannel() channel := endpoint.GetChannel()
channel.State = channeltypes.CLOSED channel.State = channeltypes.CLOSED
endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID, channel) endpoint.Chain.App.IBCKeeper.ChannelKeeper.SetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID, channel)
endpoint.Chain.Coordinator.CommitBlock(endpoint.Chain) endpoint.Chain.Coordinator.CommitBlock(endpoint.Chain)
@@ -483,7 +483,7 @@ func (endpoint *Endpoint) GetClientState() exported.ClientState {
// SetClientState sets the client state for this endpoint. // SetClientState sets the client state for this endpoint.
func (endpoint *Endpoint) SetClientState(clientState exported.ClientState) { func (endpoint *Endpoint) SetClientState(clientState exported.ClientState) {
endpoint.Chain.App.GetIBCKeeper().ClientKeeper.SetClientState(endpoint.Chain.GetContext(), endpoint.ClientID, clientState) endpoint.Chain.App.IBCKeeper.ClientKeeper.SetClientState(endpoint.Chain.GetContext(), endpoint.ClientID, clientState)
} }
// GetConsensusState retrieves the Consensus State for this endpoint at the provided height. // GetConsensusState retrieves the Consensus State for this endpoint at the provided height.
@@ -497,13 +497,13 @@ func (endpoint *Endpoint) GetConsensusState(height exported.Height) exported.Con
// SetConsensusState sets the consensus state for this endpoint. // SetConsensusState sets the consensus state for this endpoint.
func (endpoint *Endpoint) SetConsensusState(consensusState exported.ConsensusState, height exported.Height) { func (endpoint *Endpoint) SetConsensusState(consensusState exported.ConsensusState, height exported.Height) {
endpoint.Chain.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState(endpoint.Chain.GetContext(), endpoint.ClientID, height, consensusState) endpoint.Chain.App.IBCKeeper.ClientKeeper.SetClientConsensusState(endpoint.Chain.GetContext(), endpoint.ClientID, height, consensusState)
} }
// GetConnection retrieves an IBC Connection for the endpoint. The // GetConnection retrieves an IBC Connection for the endpoint. The
// connection is expected to exist otherwise testing will fail. // connection is expected to exist otherwise testing will fail.
func (endpoint *Endpoint) GetConnection() connectiontypes.ConnectionEnd { func (endpoint *Endpoint) GetConnection() connectiontypes.ConnectionEnd {
connection, found := endpoint.Chain.App.GetIBCKeeper().ConnectionKeeper.GetConnection(endpoint.Chain.GetContext(), endpoint.ConnectionID) connection, found := endpoint.Chain.App.IBCKeeper.ConnectionKeeper.GetConnection(endpoint.Chain.GetContext(), endpoint.ConnectionID)
require.True(endpoint.Chain.t, found) require.True(endpoint.Chain.t, found)
return connection return connection
@@ -511,13 +511,13 @@ func (endpoint *Endpoint) GetConnection() connectiontypes.ConnectionEnd {
// SetConnection sets the connection for this endpoint. // SetConnection sets the connection for this endpoint.
func (endpoint *Endpoint) SetConnection(connection connectiontypes.ConnectionEnd) { func (endpoint *Endpoint) SetConnection(connection connectiontypes.ConnectionEnd) {
endpoint.Chain.App.GetIBCKeeper().ConnectionKeeper.SetConnection(endpoint.Chain.GetContext(), endpoint.ConnectionID, connection) endpoint.Chain.App.IBCKeeper.ConnectionKeeper.SetConnection(endpoint.Chain.GetContext(), endpoint.ConnectionID, connection)
} }
// GetChannel retrieves an IBC Channel for the endpoint. The channel // GetChannel retrieves an IBC Channel for the endpoint. The channel
// is expected to exist otherwise testing will fail. // is expected to exist otherwise testing will fail.
func (endpoint *Endpoint) GetChannel() channeltypes.Channel { func (endpoint *Endpoint) GetChannel() channeltypes.Channel {
channel, found := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID) channel, found := endpoint.Chain.App.IBCKeeper.ChannelKeeper.GetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID)
require.True(endpoint.Chain.t, found) require.True(endpoint.Chain.t, found)
return channel return channel
@@ -525,7 +525,7 @@ func (endpoint *Endpoint) GetChannel() channeltypes.Channel {
// SetChannel sets the channel for this endpoint. // SetChannel sets the channel for this endpoint.
func (endpoint *Endpoint) SetChannel(channel channeltypes.Channel) { func (endpoint *Endpoint) SetChannel(channel channeltypes.Channel) {
endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID, channel) endpoint.Chain.App.IBCKeeper.ChannelKeeper.SetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID, channel)
} }
// QueryClientStateProof performs and abci query for a client stat associated // QueryClientStateProof performs and abci query for a client stat associated

View File

@@ -40,7 +40,7 @@ func (path *Path) SetChannelOrdered() {
// if EndpointA does not contain a packet commitment for that packet. An error is returned // if EndpointA does not contain a packet commitment for that packet. An error is returned
// if a relay step fails or the packet commitment does not exist on either endpoint. // if a relay step fails or the packet commitment does not exist on either endpoint.
func (path *Path) RelayPacket(packet channeltypes.Packet, ack []byte) error { func (path *Path) RelayPacket(packet channeltypes.Packet, ack []byte) error {
pc := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointA.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) pc := path.EndpointA.Chain.App.IBCKeeper.ChannelKeeper.GetPacketCommitment(path.EndpointA.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointA.Chain.App.AppCodec(), packet)) { if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointA.Chain.App.AppCodec(), packet)) {
// packet found, relay from A to B // packet found, relay from A to B
@@ -59,7 +59,7 @@ func (path *Path) RelayPacket(packet channeltypes.Packet, ack []byte) error {
} }
pc = path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointB.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) pc = path.EndpointB.Chain.App.IBCKeeper.ChannelKeeper.GetPacketCommitment(path.EndpointB.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointB.Chain.App.AppCodec(), packet)) { if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointB.Chain.App.AppCodec(), packet)) {
// packet found, relay B to A // packet found, relay B to A

View File

@@ -5,11 +5,9 @@ import (
"compress/gzip" "compress/gzip"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
wasmd "github.com/CosmWasm/wasmd/app"
ibctesting "github.com/cosmos/ibc-go/v3/testing" ibctesting "github.com/cosmos/ibc-go/v3/testing"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
@@ -37,7 +35,7 @@ func (chain *TestChain) SeedNewContractInstance() sdk.AccAddress {
} }
func (chain *TestChain) StoreCodeFile(filename string) types.MsgStoreCodeResponse { func (chain *TestChain) StoreCodeFile(filename string) types.MsgStoreCodeResponse {
wasmCode, err := ioutil.ReadFile(filename) wasmCode, err := os.ReadFile(filename)
require.NoError(chain.t, err) require.NoError(chain.t, err)
if strings.HasSuffix(filename, "wasm") { // compress for gas limit if strings.HasSuffix(filename, "wasm") { // compress for gas limit
var buf bytes.Buffer var buf bytes.Buffer
@@ -135,8 +133,5 @@ func (chain *TestChain) parseSDKResultData(r *sdk.Result) sdk.TxMsgData {
// ContractInfo is a helper function to returns the ContractInfo for the given contract address // ContractInfo is a helper function to returns the ContractInfo for the given contract address
func (chain *TestChain) ContractInfo(contractAddr sdk.AccAddress) *types.ContractInfo { func (chain *TestChain) ContractInfo(contractAddr sdk.AccAddress) *types.ContractInfo {
type testSupporter interface { return chain.App.WasmKeeper.GetContractInfo(chain.GetContext(), contractAddr)
TestSupport() *wasmd.TestSupport
}
return chain.App.(testSupporter).TestSupport().WasmKeeper().GetContractInfo(chain.GetContext(), contractAddr)
} }

View File

@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"io" "io"
"io/ioutil"
"github.com/CosmWasm/wasmd/x/wasm/types" "github.com/CosmWasm/wasmd/x/wasm/types"
) )
@@ -26,7 +25,7 @@ func Uncompress(src []byte, limit uint64) ([]byte, error) {
} }
zr.Multistream(false) zr.Multistream(false)
defer zr.Close() defer zr.Close()
return ioutil.ReadAll(LimitReader(zr, int64(limit))) return io.ReadAll(LimitReader(zr, int64(limit)))
} }
// LimitReader returns a Reader that reads from r // LimitReader returns a Reader that reads from r

View File

@@ -4,7 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"testing" "testing"
"time" "time"
@@ -558,7 +558,7 @@ func StoreExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers, wa
creator, _, creatorAddr := keyPubAddr() creator, _, creatorAddr := keyPubAddr()
fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount)
wasmCode, err := ioutil.ReadFile(wasmFile) wasmCode, err := os.ReadFile(wasmFile)
require.NoError(t, err) require.NoError(t, err)
codeID, err := keepers.ContractKeeper.Create(ctx, creatorAddr, wasmCode, nil) codeID, err := keepers.ContractKeeper.Create(ctx, creatorAddr, wasmCode, nil)

View File

@@ -326,7 +326,7 @@ func (p player) incrementCounter(key []byte, store wasmvm.KVStore) uint64 {
} }
func (p player) QueryState(key []byte) uint64 { func (p player) QueryState(key []byte) uint64 {
raw := p.chain.GetTestSupport().WasmKeeper().QueryRaw(p.chain.GetContext(), p.contractAddr, key) raw := p.chain.App.WasmKeeper.QueryRaw(p.chain.GetContext(), p.contractAddr, key)
return sdk.BigEndianToUint64(raw) return sdk.BigEndianToUint64(raw)
} }

View File

@@ -193,7 +193,7 @@ func TestContractCanInitiateIBCTransferMsg(t *testing.T) {
require.Equal(t, 0, len(chainB.PendingSendPackets)) require.Equal(t, 0, len(chainB.PendingSendPackets))
// and dest chain balance contains voucher // and dest chain balance contains voucher
bankKeeperB := chainB.GetTestSupport().BankKeeper() bankKeeperB := chainB.App.BankKeeper
expBalance := ibctransfertypes.GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinToSendToB.Denom, coinToSendToB.Amount) expBalance := ibctransfertypes.GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinToSendToB.Denom, coinToSendToB.Amount)
gotBalance := chainB.Balance(chainB.SenderAccount.GetAddress(), expBalance.Denom) gotBalance := chainB.Balance(chainB.SenderAccount.GetAddress(), expBalance.Denom)
assert.Equal(t, expBalance, gotBalance, "got total balance: %s", bankKeeperB.GetAllBalances(chainB.GetContext(), chainB.SenderAccount.GetAddress())) assert.Equal(t, expBalance, gotBalance, "got total balance: %s", bankKeeperB.GetAllBalances(chainB.GetContext(), chainB.SenderAccount.GetAddress()))
@@ -268,7 +268,7 @@ func TestContractCanEmulateIBCTransferMessage(t *testing.T) {
require.Equal(t, 0, len(chainB.PendingSendPackets)) require.Equal(t, 0, len(chainB.PendingSendPackets))
// and dest chain balance contains voucher // and dest chain balance contains voucher
bankKeeperB := chainB.GetTestSupport().BankKeeper() bankKeeperB := chainB.App.BankKeeper
expBalance := ibctransfertypes.GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinToSendToB.Denom, coinToSendToB.Amount) expBalance := ibctransfertypes.GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinToSendToB.Denom, coinToSendToB.Amount)
gotBalance := chainB.Balance(chainB.SenderAccount.GetAddress(), expBalance.Denom) gotBalance := chainB.Balance(chainB.SenderAccount.GetAddress(), expBalance.Denom)
assert.Equal(t, expBalance, gotBalance, "got total balance: %s", bankKeeperB.GetAllBalances(chainB.GetContext(), chainB.SenderAccount.GetAddress())) assert.Equal(t, expBalance, gotBalance, "got total balance: %s", bankKeeperB.GetAllBalances(chainB.GetContext(), chainB.SenderAccount.GetAddress()))
@@ -535,7 +535,7 @@ func (c *ackReceiverContract) IBCPacketReceive(codeID wasmvm.Checksum, env wasmv
// call original ibctransfer keeper to not copy all code into this // call original ibctransfer keeper to not copy all code into this
ibcPacket := toIBCPacket(packet) ibcPacket := toIBCPacket(packet)
ctx := c.chain.GetContext() // HACK: please note that this is not reverted after checkTX ctx := c.chain.GetContext() // HACK: please note that this is not reverted after checkTX
err := c.chain.GetTestSupport().TransferKeeper().OnRecvPacket(ctx, ibcPacket, src) err := c.chain.App.TransferKeeper.OnRecvPacket(ctx, ibcPacket, src)
if err != nil { if err != nil {
return nil, 0, sdkerrors.Wrap(err, "within our smart contract") return nil, 0, sdkerrors.Wrap(err, "within our smart contract")
} }
@@ -560,7 +560,7 @@ func (c *ackReceiverContract) IBCPacketAck(codeID wasmvm.Checksum, env wasmvmtyp
// call original ibctransfer keeper to not copy all code into this // call original ibctransfer keeper to not copy all code into this
ctx := c.chain.GetContext() // HACK: please note that this is not reverted after checkTX ctx := c.chain.GetContext() // HACK: please note that this is not reverted after checkTX
ibcPacket := toIBCPacket(msg.OriginalPacket) ibcPacket := toIBCPacket(msg.OriginalPacket)
err := c.chain.GetTestSupport().TransferKeeper().OnAcknowledgementPacket(ctx, ibcPacket, data, ack) err := c.chain.App.TransferKeeper.OnAcknowledgementPacket(ctx, ibcPacket, data, ack)
if err != nil { if err != nil {
return nil, 0, sdkerrors.Wrap(err, "within our smart contract") return nil, 0, sdkerrors.Wrap(err, "within our smart contract")
} }

View File

@@ -2,8 +2,8 @@ package simulation
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"math/rand" "math/rand"
"os"
wasmvmtypes "github.com/CosmWasm/wasmvm/types" wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/baseapp"
@@ -21,6 +21,7 @@ import (
) )
// Simulation operation weights constants // Simulation operation weights constants
//
//nolint:gosec //nolint:gosec
const ( const (
OpWeightMsgStoreCode = "op_weight_msg_store_code" OpWeightMsgStoreCode = "op_weight_msg_store_code"
@@ -83,7 +84,7 @@ func WeightedOperations(
wasmBz = testdata.ReflectContractWasm() wasmBz = testdata.ReflectContractWasm()
} else { } else {
var err error var err error
wasmBz, err = ioutil.ReadFile(wasmContractPath) wasmBz, err = os.ReadFile(wasmContractPath)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -128,10 +128,11 @@ func (c *ContractInfo) SetExtension(ext ContractInfoExtension) error {
// ReadExtension copies the extension value to the pointer passed as argument so that there is no need to cast // ReadExtension copies the extension value to the pointer passed as argument so that there is no need to cast
// For example with a custom extension of type `MyContractDetails` it will look as following: // For example with a custom extension of type `MyContractDetails` it will look as following:
// var d MyContractDetails //
// if err := info.ReadExtension(&d); err != nil { // var d MyContractDetails
// return nil, sdkerrors.Wrap(err, "extension") // if err := info.ReadExtension(&d); err != nil {
// } // return nil, sdkerrors.Wrap(err, "extension")
// }
func (c *ContractInfo) ReadExtension(e ContractInfoExtension) error { func (c *ContractInfo) ReadExtension(e ContractInfoExtension) error {
rv := reflect.ValueOf(e) rv := reflect.ValueOf(e)
if rv.Kind() != reflect.Ptr || rv.IsNil() { if rv.Kind() != reflect.Ptr || rv.IsNil() {