From 34f03df4aa59935b75281cf2724a5b4ed34997be Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 31 Mar 2022 22:07:32 +0200 Subject: [PATCH] some changes from review comments --- .../controller/ibc_module_test.go | 4 ++-- .../host/ibc_module_test.go | 4 ++-- modules/core/middleware/middleware.go | 4 ++-- modules/core/middleware/middleware_test.go | 4 ++-- testing/simapp/app.go | 16 ++++++++-------- testing/simapp/middleware.go | 6 +++++- testing/utils.go | 4 +++- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_module_test.go b/modules/apps/27-interchain-accounts/controller/ibc_module_test.go index b1567625b1e..2f78f436131 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_module_test.go @@ -233,7 +233,7 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenTry() { // use chainA (controller) for ChanOpenTry msg := channeltypes.NewMsgChannelOpenTry(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, TestVersion, channeltypes.ORDERED, []string{path.EndpointA.ConnectionID}, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, TestVersion, proofInit, proofHeight, icatypes.ModuleName) - handler := suite.chainA.GetSimApp().MsgSvcRouter.Handler(msg) + handler := suite.chainA.GetSimApp().MsgServiceRouter.Handler(msg) _, err = handler(suite.chainA.GetContext(), msg) suite.Require().Error(err) @@ -359,7 +359,7 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenConfirm() { // use chainA (controller) for ChanOpenConfirm msg := channeltypes.NewMsgChannelOpenConfirm(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, proofAck, proofHeight, icatypes.ModuleName) - handler := suite.chainA.GetSimApp().MsgSvcRouter.Handler(msg) + handler := suite.chainA.GetSimApp().MsgServiceRouter.Handler(msg) _, err = handler(suite.chainA.GetContext(), msg) suite.Require().Error(err) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index 9001565efbd..6fffb68fe37 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -129,7 +129,7 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenInit() { // use chainB (host) for ChanOpenInit msg := channeltypes.NewMsgChannelOpenInit(path.EndpointB.ChannelConfig.PortID, icatypes.Version, channeltypes.ORDERED, []string{path.EndpointB.ConnectionID}, path.EndpointA.ChannelConfig.PortID, icatypes.ModuleName) - handler := suite.chainB.GetSimApp().MsgSvcRouter.Handler(msg) + handler := suite.chainB.GetSimApp().MsgServiceRouter.Handler(msg) _, err := handler(suite.chainB.GetContext(), msg) suite.Require().Error(err) @@ -255,7 +255,7 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenAck() { // use chainB (host) for ChanOpenAck msg := channeltypes.NewMsgChannelOpenAck(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointA.ChannelID, TestVersion, proofTry, proofHeight, icatypes.ModuleName) - handler := suite.chainB.GetSimApp().MsgSvcRouter.Handler(msg) + handler := suite.chainB.GetSimApp().MsgServiceRouter.Handler(msg) _, err = handler(suite.chainB.GetContext(), msg) suite.Require().Error(err) diff --git a/modules/core/middleware/middleware.go b/modules/core/middleware/middleware.go index 020e5a9713a..703c2385b4c 100644 --- a/modules/core/middleware/middleware.go +++ b/modules/core/middleware/middleware.go @@ -18,8 +18,8 @@ type ibcTxHandler struct { next tx.Handler } -// IbcTxMiddleware implements ibc tx handling middleware -func IbcTxMiddleware(IBCKeeper *keeper.Keeper) tx.Middleware { +// IBCTxMiddleware implements ibc tx handling middleware +func IBCTxMiddleware(IBCKeeper *keeper.Keeper) tx.Middleware { return func(txh tx.Handler) tx.Handler { return ibcTxHandler{ k: IBCKeeper, diff --git a/modules/core/middleware/middleware_test.go b/modules/core/middleware/middleware_test.go index 77cec4f2d4b..7030107fca6 100644 --- a/modules/core/middleware/middleware_test.go +++ b/modules/core/middleware/middleware_test.go @@ -436,7 +436,7 @@ func (suite *MiddlewareTestSuite) TestMiddleware() { // commiting it to a block, so that the when check tx runs with the redundant // message they are both in the same block k := suite.chainB.App.GetIBCKeeper() - mw := ibcmiddleware.IbcTxMiddleware(k) + mw := ibcmiddleware.IBCTxMiddleware(k) checkCtx := suite.chainB.GetContext().WithIsCheckTx(true) txHandler := middleware.ComposeMiddlewares(noopTxHandler, mw) @@ -462,7 +462,7 @@ func (suite *MiddlewareTestSuite) TestMiddleware() { suite.SetupTest() k := suite.chainB.App.GetIBCKeeper() - mw := ibcmiddleware.IbcTxMiddleware(k) + mw := ibcmiddleware.IBCTxMiddleware(k) msgs := tc.malleate(suite) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 8f84d6d26ae..502f389a22d 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -179,7 +179,7 @@ type SimApp struct { legacyAmino *codec.LegacyAmino appCodec codec.Codec interfaceRegistry types.InterfaceRegistry - MsgSvcRouter *authmiddleware.MsgServiceRouter + MsgServiceRouter *authmiddleware.MsgServiceRouter legacyRouter sdk.Router invCheckPeriod uint @@ -272,7 +272,7 @@ func NewSimApp( appCodec: appCodec, interfaceRegistry: interfaceRegistry, legacyRouter: authmiddleware.NewLegacyRouter(), - MsgSvcRouter: authmiddleware.NewMsgServiceRouter(interfaceRegistry), + MsgServiceRouter: authmiddleware.NewMsgServiceRouter(interfaceRegistry), invCheckPeriod: invCheckPeriod, keys: keys, tkeys: tkeys, @@ -338,7 +338,7 @@ func NewSimApp( appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, ) - app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgSvcRouter, app.AccountKeeper) + app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter, app.AccountKeeper) // register the proposal types govRouter := govv1beta1.NewRouter() @@ -350,7 +350,7 @@ func NewSimApp( govConfig := govtypes.DefaultConfig() app.GovKeeper = govkeeper.NewKeeper( appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, govRouter, app.MsgSvcRouter, govConfig, + &stakingKeeper, govRouter, app.MsgServiceRouter, govConfig, ) // Create Transfer Keepers @@ -371,13 +371,13 @@ func NewSimApp( appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, - scopedICAControllerKeeper, app.MsgSvcRouter, + scopedICAControllerKeeper, app.MsgServiceRouter, ) app.ICAHostKeeper = icahostkeeper.NewKeeper( appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, - app.AccountKeeper, scopedICAHostKeeper, app.MsgSvcRouter, + app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter, ) icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper) @@ -471,7 +471,7 @@ func NewSimApp( app.mm.RegisterInvariants(&app.CrisisKeeper) app.mm.RegisterRoutes(app.legacyRouter, app.QueryRouter(), encodingConfig.Amino) - app.configurator = module.NewConfigurator(app.appCodec, app.MsgSvcRouter, app.GRPCQueryRouter()) + app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter, app.GRPCQueryRouter()) app.mm.RegisterServices(app.configurator) // add test gRPC service for testing gRPC queries in isolation @@ -540,7 +540,7 @@ func (app *SimApp) setTxHandler(txConfig client.TxConfig, indexEventsStr []strin Debug: app.Trace(), IndexEvents: indexEvents, LegacyRouter: app.legacyRouter, - MsgServiceRouter: app.MsgSvcRouter, + MsgServiceRouter: app.MsgServiceRouter, AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper, FeegrantKeeper: app.FeeGrantKeeper, diff --git a/testing/simapp/middleware.go b/testing/simapp/middleware.go index 3755c22fab2..b9cc58204f3 100644 --- a/testing/simapp/middleware.go +++ b/testing/simapp/middleware.go @@ -54,6 +54,10 @@ func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for middlewares") } + if options.IBCKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for middlewares") + } + var sigGasConsumer = options.SigGasConsumer if sigGasConsumer == nil { sigGasConsumer = authmiddleware.DefaultSigVerificationGasConsumer @@ -102,6 +106,6 @@ func NewDefaultTxHandler(options TxHandlerOptions) (tx.Handler, error) { // should be accounted for, should go below this authmiddleware. authmiddleware.ConsumeBlockGasMiddleware, authmiddleware.NewTipMiddleware(options.BankKeeper), - ibcmiddleware.IbcTxMiddleware(options.IBCKeeper), + ibcmiddleware.IBCTxMiddleware(options.IBCKeeper), ), nil } diff --git a/testing/utils.go b/testing/utils.go index ee4a0cb043b..f955a813696 100644 --- a/testing/utils.go +++ b/testing/utils.go @@ -31,7 +31,9 @@ func ABCIResponsesResultsHash(ar *tmprotostate.ABCIResponses) []byte { return tmtypes.NewResults(ar.DeliverTxs).Hash() } -// MakeCommit commits a block +// MakeCommit iterates over the provided validator set, creating a Precommit vote for each +// participant at the provided height and round. Each vote is signed and added to the VoteSet. +// Finally, the VoteSet is committed finalizing the block. func MakeCommit(ctx context.Context, blockID tmtypes.BlockID, height int64, round int32, voteSet *tmtypes.VoteSet, validators []tmtypes.PrivValidator, now time.Time) (*tmtypes.Commit, error) { // all sign for i := 0; i < len(validators); i++ {