Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions modules/apps/27-interchain-accounts/controller/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,37 @@
// ICA controller keeper and the underlying application.
type IBCMiddleware struct {
app porttypes.IBCModule
keeper keeper.Keeper
keeper *keeper.Keeper
}

// NewIBCMiddleware creates a new IBCMiddleware given the associated keeper.
// The underlying application is set to nil and authentication is assumed to
// be performed by a Cosmos SDK module that sends messages to controller message server.
func NewIBCMiddleware(k keeper.Keeper) IBCMiddleware {
return IBCMiddleware{
func NewIBCMiddleware(k *keeper.Keeper) *IBCMiddleware {
return &IBCMiddleware{
app: nil,
keeper: k,
}
}

// NewIBCMiddlewareWithAuth creates a new IBCMiddleware given the associated keeper and underlying application
func NewIBCMiddlewareWithAuth(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware {
return IBCMiddleware{
func NewIBCMiddlewareWithAuth(app porttypes.IBCModule, k *keeper.Keeper) *IBCMiddleware {
return &IBCMiddleware{
app: app,
keeper: k,
}
}

// SetUnderlyingApplication sets the underlying application for the middleware.
func (im *IBCMiddleware) SetUnderlyingApplication(app porttypes.IBCModule) {
im.app = app

Check warning on line 52 in modules/apps/27-interchain-accounts/controller/ibc_middleware.go

View check run for this annotation

Codecov / codecov/patch

modules/apps/27-interchain-accounts/controller/ibc_middleware.go#L51-L52

Added lines #L51 - L52 were not covered by tests
}

// SetICS4Wrapper sets the ICS4Wrapper for the middleware.
func (im *IBCMiddleware) SetICS4Wrapper(ics4Wrapper porttypes.ICS4Wrapper) {
im.keeper.WithICS4Wrapper(ics4Wrapper)

Check warning on line 57 in modules/apps/27-interchain-accounts/controller/ibc_middleware.go

View check run for this annotation

Codecov / codecov/patch

modules/apps/27-interchain-accounts/controller/ibc_middleware.go#L56-L57

Added lines #L56 - L57 were not covered by tests
}

// OnChanOpenInit implements the IBCMiddleware interface
//
// Interchain Accounts is implemented to act as middleware for connected authentication modules on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ func (suite *InterchainAccountsTestSuite) TestInFlightHandshakeRespectsGoAPICall
suite.Require().NoError(err)

// attempt to start a second handshake via the controller msg server
msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper)
msgServer := controllerkeeper.NewMsgServerImpl(suite.chainA.GetSimApp().ICAControllerKeeper)
msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion, ordering)

res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount)
Expand All @@ -846,7 +846,7 @@ func (suite *InterchainAccountsTestSuite) TestInFlightHandshakeRespectsMsgServer
path.SetupConnections()

// initiate a channel handshake such that channel.State == INIT
msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper)
msgServer := controllerkeeper.NewMsgServerImpl(suite.chainA.GetSimApp().ICAControllerKeeper)
msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion, ordering)

res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount)
Expand Down Expand Up @@ -881,7 +881,7 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer(
channelSeq := suite.chainA.GetSimApp().GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(suite.chainA.GetContext())

// route a new MsgRegisterInterchainAccount in order to reopen the
msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper)
msgServer := controllerkeeper.NewMsgServerImpl(suite.chainA.GetSimApp().ICAControllerKeeper)
msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), path.EndpointA.ChannelConfig.Version, ordering)

res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {

tc.malleate()

keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper, genesisState)
keeper.InitGenesis(suite.chainA.GetContext(), *suite.chainA.GetSimApp().ICAControllerKeeper, genesisState)

channelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID)
suite.Require().True(found)
Expand Down Expand Up @@ -93,7 +93,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() {
interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(exists)

genesisState := keeper.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper)
genesisState := keeper.ExportGenesis(suite.chainA.GetContext(), *suite.chainA.GetSimApp().ICAControllerKeeper)

suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ type Keeper struct {
// NewKeeper creates a new interchain accounts controller Keeper instance
func NewKeeper(
cdc codec.Codec, storeService corestore.KVStoreService,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper,
channelKeeper icatypes.ChannelKeeper,
msgRouter icatypes.MessageRouter, authority string,
) Keeper {
) *Keeper {
if strings.TrimSpace(authority) == "" {
panic(errors.New("authority must be non-empty"))
}

return Keeper{
return &Keeper{
storeService: storeService,
cdc: cdc,
ics4Wrapper: ics4Wrapper,
ics4Wrapper: channelKeeper,
channelKeeper: channelKeeper,
msgRouter: msgRouter,
authority: authority,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AppCodec(),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().MsgServiceRouter(),
suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(),
)
Expand All @@ -130,7 +129,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AppCodec(),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().MsgServiceRouter(),
"", // authority
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount_MsgServer() {
tc.malleate()

ctx := suite.chainA.GetContext()
msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper)
msgServer := keeper.NewMsgServerImpl(suite.chainA.GetSimApp().ICAControllerKeeper)
res, err := msgServer.RegisterInterchainAccount(ctx, msg)

if tc.expErr == nil {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (suite *KeeperTestSuite) TestSubmitTx() {
tc.malleate() // malleate mutates test data

ctx := suite.chainA.GetContext()
msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper)
msgServer := keeper.NewMsgServerImpl(suite.chainA.GetSimApp().ICAControllerKeeper)
res, err := msgServer.SendTx(ctx, msg)

if tc.expErr == nil {
Expand Down
14 changes: 11 additions & 3 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

// IBCModule implements the ICS26 interface for interchain accounts host chains
type IBCModule struct {
keeper keeper.Keeper
keeper *keeper.Keeper
}

// NewIBCModule creates a new IBCModule given the associated keeper
func NewIBCModule(k keeper.Keeper) IBCModule {
return IBCModule{
func NewIBCModule(k *keeper.Keeper) *IBCModule {
return &IBCModule{
keeper: k,
}
}
Expand Down Expand Up @@ -173,3 +173,11 @@

return data, version, nil
}

// SetICS4Wrapper sets the ICS4Wrapper for the IBCModule.
func (im *IBCModule) SetICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
if wrapper == nil {
panic("ICS4Wrapper cannot be nil")

Check warning on line 180 in modules/apps/27-interchain-accounts/host/ibc_module.go

View check run for this annotation

Codecov / codecov/patch

modules/apps/27-interchain-accounts/host/ibc_module.go#L178-L180

Added lines #L178 - L180 were not covered by tests
}
im.keeper.WithICS4Wrapper(wrapper)

Check warning on line 182 in modules/apps/27-interchain-accounts/host/ibc_module.go

View check run for this annotation

Codecov / codecov/patch

modules/apps/27-interchain-accounts/host/ibc_module.go#L182

Added line #L182 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
Port: icatypes.HostPortID,
}

keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState)
keeper.InitGenesis(suite.chainA.GetContext(), *suite.chainA.GetSimApp().ICAHostKeeper, genesisState)

channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID)
suite.Require().True(found)
Expand Down Expand Up @@ -83,7 +83,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() {
Params: tc.input,
}
if tc.expPanicMsg == "" {
keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState)
keeper.InitGenesis(suite.chainA.GetContext(), *suite.chainA.GetSimApp().ICAHostKeeper, genesisState)

channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID)
suite.Require().True(found)
Expand All @@ -98,7 +98,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() {
suite.Require().Equal(expParams, params)
} else {
suite.PanicsWithError(tc.expPanicMsg, func() {
keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState)
keeper.InitGenesis(suite.chainA.GetContext(), *suite.chainA.GetSimApp().ICAHostKeeper, genesisState)
})
}
})
Expand All @@ -118,7 +118,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() {
interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(exists)

genesisState := keeper.ExportGenesis(suite.chainB.GetContext(), suite.chainB.GetSimApp().ICAHostKeeper)
genesisState := keeper.ExportGenesis(suite.chainB.GetContext(), *suite.chainB.GetSimApp().ICAHostKeeper)

suite.Require().Equal(path.EndpointB.ChannelID, genesisState.ActiveChannels[0].ChannelId)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId)
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ type Keeper struct {
// NewKeeper creates a new interchain accounts host Keeper instance
func NewKeeper(
cdc codec.Codec, storeService corestore.KVStoreService,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper,
channelKeeper icatypes.ChannelKeeper,
accountKeeper icatypes.AccountKeeper, msgRouter icatypes.MessageRouter, queryRouter icatypes.QueryRouter, authority string,
) Keeper {
) *Keeper {
// ensure ibc interchain accounts module account is set
if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil {
panic(errors.New("the Interchain Accounts module account has not been set"))
Expand All @@ -64,10 +64,10 @@ func NewKeeper(
panic(errors.New("authority must be non-empty"))
}

return Keeper{
return &Keeper{
storeService: storeService,
cdc: cdc,
ics4Wrapper: ics4Wrapper,
ics4Wrapper: channelKeeper,
channelKeeper: channelKeeper,
accountKeeper: accountKeeper,
msgRouter: msgRouter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AppCodec(),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().AccountKeeper,
suite.chainA.GetSimApp().MsgServiceRouter(),
suite.chainA.GetSimApp().GRPCQueryRouter(),
Expand All @@ -155,7 +154,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AppCodec(),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
authkeeper.AccountKeeper{}, // empty account keeper
suite.chainA.GetSimApp().MsgServiceRouter(),
suite.chainA.GetSimApp().GRPCQueryRouter(),
Expand All @@ -167,7 +165,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AppCodec(),
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().AccountKeeper,
suite.chainA.GetSimApp().MsgServiceRouter(),
suite.chainA.GetSimApp().GRPCQueryRouter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (suite *KeeperTestSuite) TestModuleQuerySafe() {
tc.malleate()

ctx := suite.chainA.GetContext()
msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAHostKeeper)
msgServer := keeper.NewMsgServerImpl(suite.chainA.GetSimApp().ICAHostKeeper)
res, err := msgServer.ModuleQuerySafe(ctx, msg)

if tc.expErr == nil {
Expand Down Expand Up @@ -173,7 +173,7 @@ func (suite *KeeperTestSuite) TestUpdateParams() {
suite.SetupTest()

ctx := suite.chainA.GetContext()
msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAHostKeeper)
msgServer := keeper.NewMsgServerImpl(suite.chainA.GetSimApp().ICAHostKeeper)
res, err := msgServer.UpdateParams(ctx, tc.msg)

if tc.expErr == nil {
Expand Down
2 changes: 2 additions & 0 deletions modules/apps/27-interchain-accounts/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

connectiontypes "github.com/cosmos/ibc-go/v10/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
)

// AccountKeeper defines the expected account keeper
Expand All @@ -20,6 +21,7 @@ type AccountKeeper interface {

// ChannelKeeper defines the expected IBC channel keeper
type ChannelKeeper interface {
porttypes.ICS4Wrapper
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool)
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, error)
Expand Down
39 changes: 22 additions & 17 deletions modules/apps/callbacks/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// IBCMiddleware implements the ICS26 callbacks for the ibc-callbacks middleware given
// the underlying application.
type IBCMiddleware struct {
app porttypes.PacketUnmarshalarModule
app porttypes.PacketUnmarshalerModule
ics4Wrapper porttypes.ICS4Wrapper

contractKeeper types.ContractKeeper
Expand All @@ -37,18 +37,8 @@
// NewIBCMiddleware creates a new IBCMiddleware given the keeper and underlying application.
// The underlying application must implement the required callback interfaces.
func NewIBCMiddleware(
app porttypes.IBCModule, ics4Wrapper porttypes.ICS4Wrapper,
contractKeeper types.ContractKeeper, maxCallbackGas uint64,
) IBCMiddleware {
packetDataUnmarshalerApp, ok := app.(porttypes.PacketUnmarshalarModule)
if !ok {
panic(fmt.Errorf("underlying application does not implement %T", (*porttypes.PacketUnmarshalarModule)(nil)))
}

if ics4Wrapper == nil {
panic(errors.New("ICS4Wrapper cannot be nil"))
}

) *IBCMiddleware {
if contractKeeper == nil {
panic(errors.New("contract keeper cannot be nil"))
}
Expand All @@ -57,21 +47,36 @@
panic(errors.New("maxCallbackGas cannot be zero"))
}

return IBCMiddleware{
app: packetDataUnmarshalerApp,
ics4Wrapper: ics4Wrapper,
return &IBCMiddleware{
contractKeeper: contractKeeper,
maxCallbackGas: maxCallbackGas,
}
}

// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after the
// SetICS4Wrapper sets the ICS4Wrapper. This function may be used after the
// middleware's creation to set the middleware which is above this module in
// the IBC application stack.
func (im *IBCMiddleware) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
func (im *IBCMiddleware) SetICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
im.ics4Wrapper = wrapper
}

// SetUnderlyingApplication sets the underlying IBC module. This function may be used after
// the middleware's creation to set the ibc module which is below this middleware.
func (im *IBCMiddleware) SetUnderlyingApplication(app porttypes.IBCModule) {
if app == nil {
panic(errors.New("underlying application cannot be nil"))

Check warning on line 67 in modules/apps/callbacks/ibc_middleware.go

View check run for this annotation

Codecov / codecov/patch

modules/apps/callbacks/ibc_middleware.go#L67

Added line #L67 was not covered by tests
}
if im.app != nil {
panic(errors.New("underlying application already set"))

Check warning on line 70 in modules/apps/callbacks/ibc_middleware.go

View check run for this annotation

Codecov / codecov/patch

modules/apps/callbacks/ibc_middleware.go#L70

Added line #L70 was not covered by tests
}
// the underlying application must implement the PacketUnmarshalerModule interface
pdApp, ok := app.(porttypes.PacketUnmarshalerModule)
if !ok {
panic(fmt.Errorf("underlying application must implement PacketUnmarshalerModule, got %T", app))

Check warning on line 75 in modules/apps/callbacks/ibc_middleware.go

View check run for this annotation

Codecov / codecov/patch

modules/apps/callbacks/ibc_middleware.go#L75

Added line #L75 was not covered by tests
}
im.app = pdApp
}

// GetICS4Wrapper returns the ICS4Wrapper.
func (im *IBCMiddleware) GetICS4Wrapper() porttypes.ICS4Wrapper {
return im.ics4Wrapper
Expand Down
Loading
Loading