diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index f2050b9f010..24e602227d4 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -24,10 +24,10 @@ type IBCMiddleware struct { } // IBCMiddleware creates a new IBCMiddleware given the associated keeper and underlying application -func NewIBCMiddleware(k keeper.Keeper, app porttypes.IBCModule) IBCMiddleware { +func NewIBCMiddleware(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware { return IBCMiddleware{ - keeper: k, app: app, + keeper: k, } } diff --git a/testing/simapp/app.go b/testing/simapp/app.go index f073c658ffb..1f088bd0683 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -356,8 +356,11 @@ func NewSimApp( ) // IBC Fee Module keeper - app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(appCodec, keys[ibcfeetypes.StoreKey], app.GetSubspace(ibcfeetypes.ModuleName), - app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, + app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( + appCodec, keys[ibcfeetypes.StoreKey], app.GetSubspace(ibcfeetypes.ModuleName), + app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, ) // ICA Controller keeper @@ -389,6 +392,17 @@ func NewSimApp( app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, ) + // Mock Module Stack + + // Mock Module setup for testing IBC and also acts as the interchain accounts authentication module + // NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do + // not replicate if you do not need to test core IBC or light clients. + mockModule := ibcmock.NewAppModule(&app.IBCKeeper.PortKeeper) + + // The mock module is used for testing IBC + mockIBCModule := ibcmock.NewIBCModule(&mockModule, ibcmock.NewMockIBCApp(ibcmock.ModuleName, scopedIBCMockKeeper)) + ibcRouter.AddRoute(ibcmock.ModuleName, mockIBCModule) + // Create Transfer Stack // SendPacket, since it is originating from the application to core IBC: // transferKeeper.SendPacket -> fee.SendPacket -> channel.SendPacket @@ -396,8 +410,6 @@ func NewSimApp( // RecvPacket, message that originates from core IBC and goes down to app, the flow is the otherway // channel.RecvPacket -> fee.OnRecvPacket -> transfer.OnRecvPacket - transferModule := transfer.NewAppModule(app.TransferKeeper) - // transfer stack contains (from top to bottom): // - IBC Fee Middleware // - Transfer @@ -410,20 +422,19 @@ func NewSimApp( // Add transfer stack to IBC Router ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) - // Mock Module setup for testing IBC and acts as the interchain accounts authentication module - // NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do - // not replicate if you do not need to test core IBC or light clients. - mockModule := ibcmock.NewAppModule(&app.IBCKeeper.PortKeeper) - // Create Interchain Accounts Stack // SendPacket, since it is originating from the application to core IBC: - // icaAuthModuleKeeper.SendPacket -> icaControllerKeeper.SendPacket -> channel.SendPacket + // icaAuthModuleKeeper.SendPacket -> fee.SendPacket -> icaControllerKeeper.SendPacket -> channel.SendPacket + + // OnAckPacket as this is where fee's are paid out + // mockModule.OnAcknowledgementPacket -> fee.OnAcknowledgementPacket -> channel.OnAcknowledgementPacket // initialize ICA module with mock module as the authentication module on the controller side var icaControllerStack porttypes.IBCModule icaControllerStack = ibcmock.NewIBCModule(&mockModule, ibcmock.NewMockIBCApp("", scopedICAMockKeeper)) app.ICAAuthModule = icaControllerStack.(ibcmock.IBCModule) - icaControllerStack = icacontroller.NewIBCMiddleware(app.ICAControllerKeeper, icaControllerStack) + icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper) + icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper) icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) @@ -450,13 +461,7 @@ func NewSimApp( feeMockModule := ibcmock.NewIBCModule(&mockModule, ibcmock.NewMockIBCApp(MockFeePort, scopedFeeMockKeeper)) app.FeeMockModule = feeMockModule feeWithMockModule := ibcfee.NewIBCMiddleware(feeMockModule, app.IBCFeeKeeper) - - mockIBCModule := ibcmock.NewIBCModule(&mockModule, ibcmock.NewMockIBCApp(ibcmock.ModuleName, scopedIBCMockKeeper)) - - // Add Mock Module & Mock Fee Module to IBC Router - ibcRouter. - AddRoute(ibcmock.ModuleName, mockIBCModule). - AddRoute(MockFeePort, feeWithMockModule) + ibcRouter.AddRoute(MockFeePort, feeWithMockModule) // Seal the IBC Router app.IBCKeeper.SetRouter(ibcRouter) @@ -500,7 +505,7 @@ func NewSimApp( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), // IBC modules - transferModule, + transfer.NewAppModule(app.TransferKeeper), ibcfee.NewAppModule(app.IBCFeeKeeper), ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), mockModule, @@ -562,7 +567,7 @@ func NewSimApp( evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), - transferModule, + transfer.NewAppModule(app.TransferKeeper), ) app.sm.RegisterStoreDecoders()