Skip to content

Commit

Permalink
chore: Code alignment 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Feb 18, 2025
1 parent 3f03bd5 commit 7cab890
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 154 deletions.
35 changes: 0 additions & 35 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
ibccallbacks "github.com/cosmos/ibc-go/modules/apps/callbacks"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ica "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller"
Expand Down Expand Up @@ -202,7 +200,6 @@ type WasmApp struct {
// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.BaseKeeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
Expand All @@ -226,13 +223,6 @@ type WasmApp struct {
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

// the module manager
ModuleManager *module.Manager
BasicModuleManager module.BasicManager
Expand Down Expand Up @@ -361,20 +351,6 @@ func NewWasmApp(
)
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(
appCodec,
keys[capabilitytypes.StoreKey],
memKeys[capabilitytypes.MemStoreKey],
)

scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
app.CapabilityKeeper.Seal()

// add keepers

app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -609,8 +585,6 @@ func NewWasmApp(
app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper,
app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
Expand All @@ -632,8 +606,6 @@ func NewWasmApp(
distrkeeper.NewQuerier(app.DistrKeeper),
app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
scopedWasmKeeper,
app.TransferKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
Expand Down Expand Up @@ -728,7 +700,6 @@ func NewWasmApp(
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
circuit.NewAppModule(appCodec, app.CircuitKeeper),
// non sdk modules
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
Expand Down Expand Up @@ -885,12 +856,6 @@ func NewWasmApp(
}
}

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedWasmKeeper = scopedWasmKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper

// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
// defined as a chain, and have the same signature as antehandlers.
Expand Down
5 changes: 0 additions & 5 deletions app/test_support.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -16,10 +15,6 @@ func (app *WasmApp) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

func (app *WasmApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.ScopedIBCKeeper
}

func (app *WasmApp) GetBaseApp() *baseapp.BaseApp {
return app.BaseApp
}
Expand Down
1 change: 0 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (app *WasmApp) RegisterUpgradeHandlers() {
AccountKeeper: &app.AccountKeeper,
ParamsKeeper: &app.ParamsKeeper,
ConsensusParamsKeeper: &app.ConsensusParamsKeeper,
CapabilityKeeper: app.CapabilityKeeper,
IBCKeeper: app.IBCKeeper,
Codec: app.appCodec,
GetStoreKey: app.GetKey,
Expand Down
2 changes: 0 additions & 2 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package upgrades
import (
"context"

capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"

storetypes "cosmossdk.io/store/types"
Expand All @@ -22,7 +21,6 @@ type AppKeepers struct {
ConsensusParamsKeeper *consensusparamkeeper.Keeper
Codec codec.Codec
GetStoreKey func(storeKey string) *storetypes.KVStoreKey
CapabilityKeeper *capabilitykeeper.Keeper
IBCKeeper *ibckeeper.Keeper
}
type ModuleManager interface {
Expand Down
2 changes: 0 additions & 2 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,6 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context) {
nil,
nil,
nil,
nil,
nil,
tempDir,
nodeConfig,
wasmtypes.VMConfig{},
Expand Down
19 changes: 8 additions & 11 deletions x/wasm/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func NewDefaultMessageHandler(
router MessageRouter,
ics4Wrapper types.ICS4Wrapper,
channelKeeper types.ChannelKeeper,
capabilityKeeper types.CapabilityKeeper,
bankKeeper types.Burner,
cdc codec.Codec,
portSource types.ICS20TransferPortSource,
Expand All @@ -53,7 +52,7 @@ func NewDefaultMessageHandler(
}
return NewMessageHandlerChain(
NewSDKMessageHandler(cdc, router, encoders),
NewIBCRawPacketHandler(ics4Wrapper, keeper, channelKeeper, capabilityKeeper),
NewIBCRawPacketHandler(ics4Wrapper, keeper, channelKeeper),
NewBurnCoinMessageHandler(bankKeeper),
)
}
Expand Down Expand Up @@ -173,19 +172,17 @@ func (m MessageHandlerChain) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAd

// IBCRawPacketHandler handles IBC.SendPacket messages which are published to an IBC channel.
type IBCRawPacketHandler struct {
ics4Wrapper types.ICS4Wrapper
wasmKeeper types.IBCContractKeeper
channelKeeper types.ChannelKeeper
capabilityKeeper types.CapabilityKeeper
ics4Wrapper types.ICS4Wrapper
wasmKeeper types.IBCContractKeeper
channelKeeper types.ChannelKeeper
}

// NewIBCRawPacketHandler constructor
func NewIBCRawPacketHandler(ics4Wrapper types.ICS4Wrapper, wasmKeeper types.IBCContractKeeper, channelKeeper types.ChannelKeeper, capabilityKeeper types.CapabilityKeeper) IBCRawPacketHandler {
func NewIBCRawPacketHandler(ics4Wrapper types.ICS4Wrapper, wasmKeeper types.IBCContractKeeper, channelKeeper types.ChannelKeeper) IBCRawPacketHandler {
return IBCRawPacketHandler{
ics4Wrapper: ics4Wrapper,
wasmKeeper: wasmKeeper,
channelKeeper: channelKeeper,
capabilityKeeper: capabilityKeeper,
ics4Wrapper: ics4Wrapper,
wasmKeeper: wasmKeeper,
channelKeeper: channelKeeper,
}
}

Expand Down
11 changes: 1 addition & 10 deletions x/wasm/keeper/handler_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
wasmvm "github.com/CosmWasm/wasmvm/v2"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
"github.com/cosmos/gogoproto/proto"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types" //nolint:staticcheck
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
Expand Down Expand Up @@ -279,11 +278,6 @@ func TestIBCRawPacketHandler(t *testing.T) {
}, true
},
}
capKeeper := &wasmtesting.MockCapabilityKeeper{
GetCapabilityFn: func(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool) {
return &capabilitytypes.Capability{}, true
},
}
contractKeeper := wasmtesting.IBCContractKeeperMock{}
// also store a packet to be acked
ackPacket := channeltypes.Packet{
Expand All @@ -304,7 +298,6 @@ func TestIBCRawPacketHandler(t *testing.T) {
specs := map[string]struct {
srcMsg wasmvmtypes.IBCMsg
chanKeeper types.ChannelKeeper
capKeeper types.CapabilityKeeper
expPacketSent *CapturedPacket
expPacketAck *CapturedPacket
expAck []byte
Expand All @@ -320,7 +313,6 @@ func TestIBCRawPacketHandler(t *testing.T) {
},
},
chanKeeper: chanKeeper,
capKeeper: capKeeper,
expPacketSent: &CapturedPacket{
sourcePort: ibcPort,
sourceChannel: "channel-1",
Expand All @@ -338,7 +330,6 @@ func TestIBCRawPacketHandler(t *testing.T) {
},
},
chanKeeper: chanKeeper,
capKeeper: capKeeper,
expPacketAck: &CapturedPacket{
sourcePort: ackPacket.SourcePort,
sourceChannel: ackPacket.SourceChannel,
Expand All @@ -357,7 +348,7 @@ func TestIBCRawPacketHandler(t *testing.T) {
capturedPacketAck = nil

// when
h := NewIBCRawPacketHandler(capturingICS4Mock, &contractKeeper, spec.chanKeeper, spec.capKeeper)
h := NewIBCRawPacketHandler(capturingICS4Mock, &contractKeeper, spec.chanKeeper)
evts, data, msgResponses, gotErr := h.DispatchMsg(ctx, RandomAccountAddress(t), ibcPort, wasmvmtypes.CosmosMsg{IBC: &spec.srcMsg}) //nolint:gosec

// then
Expand Down
13 changes: 0 additions & 13 deletions x/wasm/keeper/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package keeper
import (
"strings"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -24,14 +22,3 @@ func ContractFromPortID(portID string) (sdk.AccAddress, error) {
}
return sdk.AccAddressFromBech32(portID[len(portIDPrefix):])
}

// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool {
return k.capabilityKeeper.AuthenticateCapability(ctx, cap, name)
}

// ClaimCapability allows the transfer module to claim a capability
// that IBC module passes to it
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
return k.capabilityKeeper.ClaimCapability(ctx, cap, name)
}
1 change: 0 additions & 1 deletion x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ type Keeper struct {
cdc codec.Codec
accountKeeper types.AccountKeeper
bank CoinTransferrer
capabilityKeeper types.CapabilityKeeper
wasmVM types.WasmEngine
wasmVMQueryHandler WasmVMQueryHandler
wasmVMResponseHandler WasmVMResponseHandler
Expand Down
3 changes: 1 addition & 2 deletions x/wasm/keeper/keeper_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func NewKeeper(
accountKeeper: accountKeeper,
bank: NewBankCoinTransferrer(bankKeeper),
accountPruner: NewVestingCoinBurner(bankKeeper),
capabilityKeeper: capabilityKeeper,
queryGasLimit: nodeConfig.SmartQueryGasLimit,
gasRegister: types.NewDefaultWasmGasRegister(),
maxQueryStackSize: types.DefaultMaxQueryStackSize,
Expand All @@ -58,7 +57,7 @@ func NewKeeper(
authority: authority,
wasmLimits: vmConfig.WasmLimits,
}
keeper.messenger = NewDefaultMessageHandler(keeper, router, ics4Wrapper, channelKeeper, capabilityKeeper, bankKeeper, cdc, portSource)
keeper.messenger = NewDefaultMessageHandler(keeper, router, ics4Wrapper, channelKeeper, bankKeeper, cdc, portSource)
keeper.wasmVMQueryHandler = DefaultQueryPlugins(bankKeeper, stakingKeeper, distrKeeper, channelKeeper, keeper)
preOpts, postOpts := splitOpts(opts)
for _, o := range preOpts {
Expand Down
1 change: 0 additions & 1 deletion x/wasm/keeper/keeper_no_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func NewKeeper(
distrKeeper types.DistributionKeeper,
ics4Wrapper types.ICS4Wrapper,
channelKeeper types.ChannelKeeper,
capabilityKeeper types.CapabilityKeeper,
portSource types.ICS20TransferPortSource,
router MessageRouter,
_ GRPCQueryRouter,
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ func TestInstantiateWithContractFactoryChildQueriesParent(t *testing.T) {
router := baseapp.NewMsgServiceRouter()
router.SetInterfaceRegistry(keepers.EncodingConfig.InterfaceRegistry)
types.RegisterMsgServer(router, NewMsgServerImpl(keeper))
keeper.messenger = NewDefaultMessageHandler(nil, router, nil, nil, nil, nil, keepers.EncodingConfig.Codec, nil)
keeper.messenger = NewDefaultMessageHandler(nil, router, nil, nil, nil, keepers.EncodingConfig.Codec, nil)
// overwrite wasmvm in response handler
keeper.wasmVMResponseHandler = NewDefaultWasmVMContractResponseHandler(NewMessageDispatcher(keeper.messenger, keeper))

Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestConstructorOptions(t *testing.T) {
opt := spec.srcOpt
_, gotPostOptMarker := opt.(postOptsFn)
require.Equal(t, spec.isPostOpt, gotPostOptMarker)
k := NewKeeper(codec, runtime.NewKVStoreService(storeKey), authkeeper.AccountKeeper{}, &bankkeeper.BaseKeeper{}, stakingkeeper.Keeper{}, nil, nil, nil, nil, nil, nil, nil, nil, tempDir, types.DefaultNodeConfig(), types.VMConfig{}, AvailableCapabilities, "", spec.srcOpt)
k := NewKeeper(codec, runtime.NewKVStoreService(storeKey), authkeeper.AccountKeeper{}, &bankkeeper.BaseKeeper{}, stakingkeeper.Keeper{}, nil, nil, nil, nil, nil, nil, tempDir, types.DefaultNodeConfig(), types.VMConfig{}, AvailableCapabilities, "", spec.srcOpt)
spec.verify(t, k)
})
}
Expand Down
46 changes: 18 additions & 28 deletions x/wasm/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
"github.com/cosmos/ibc-go/v9/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v9/modules/core"
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper"
"github.com/cosmos/ibc-go/v10/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v10/modules/core"
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
"github.com/stretchr/testify/require"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -366,13 +366,6 @@ func createTestInput(
faucet.Fund(ctx, distrAcc.GetAddress(), sdk.NewCoin("stake", sdkmath.NewInt(2000000)))
accountKeeper.SetModuleAccount(ctx, distrAcc)

capabilityKeeper := capabilitykeeper.NewKeeper(
appCodec,
keys[capabilitytypes.StoreKey],
memKeys[capabilitytypes.MemStoreKey],
)
scopedWasmKeeper := capabilityKeeper.ScopeToModule(types.ModuleName)

ibcKeeper := ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
Expand All @@ -397,8 +390,6 @@ func createTestInput(
distributionkeeper.NewQuerier(distKeeper),
ibcKeeper.ChannelKeeper, // ICS4Wrapper
ibcKeeper.ChannelKeeper,
ibcKeeper.PortKeeper,
scopedWasmKeeper,
wasmtesting.MockIBCTransferKeeper{},
msgRouter,
querier,
Expand Down Expand Up @@ -438,20 +429,19 @@ func createTestInput(
types.RegisterQueryServer(querier, NewGrpcQuerier(appCodec, runtime.NewKVStoreService(keys[types.ModuleName]), keeper, keeper.queryGasLimit))

keepers := TestKeepers{
AccountKeeper: accountKeeper,
StakingKeeper: stakingKeeper,
DistKeeper: distKeeper,
ContractKeeper: contractKeeper,
WasmKeeper: &keeper,
BankKeeper: bankKeeper,
GovKeeper: govKeeper,
IBCKeeper: ibcKeeper,
Router: msgRouter,
EncodingConfig: encodingConfig,
Faucet: faucet,
MultiStore: ms,
ScopedWasmKeeper: scopedWasmKeeper,
WasmStoreKey: keys[types.StoreKey],
AccountKeeper: accountKeeper,
StakingKeeper: stakingKeeper,
DistKeeper: distKeeper,
ContractKeeper: contractKeeper,
WasmKeeper: &keeper,
BankKeeper: bankKeeper,
GovKeeper: govKeeper,
IBCKeeper: ibcKeeper,
Router: msgRouter,
EncodingConfig: encodingConfig,
Faucet: faucet,
MultiStore: ms,
WasmStoreKey: keys[types.StoreKey],
}
return ctx, keepers
}
Expand Down
Loading

0 comments on commit 7cab890

Please sign in to comment.