-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into AXE-6259-Fix-IBC-transfer-retry-logic
- Loading branch information
Showing
4 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"github.com/axelarnetwork/utils/slices" | ||
) | ||
|
||
type FilteredModuleManager struct { | ||
*module.Manager | ||
filteredModules []string | ||
} | ||
|
||
func NewFilteredModuleManager(appModules []module.AppModule, filteredModules []string) *FilteredModuleManager { | ||
manager := module.NewManager(appModules...) | ||
|
||
return &FilteredModuleManager{ | ||
manager, | ||
filteredModules, | ||
} | ||
} | ||
|
||
// RegisterRoutes registers all module routes and module querier routes | ||
func (m *FilteredModuleManager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter, legacyQuerierCdc *codec.LegacyAmino) { | ||
for _, module := range m.Modules { | ||
if m.isModuleFiltered(module.Name()) { | ||
continue | ||
} | ||
|
||
if r := module.Route(); !r.Empty() { | ||
router.AddRoute(r) | ||
} | ||
if r := module.QuerierRoute(); r != "" { | ||
queryRouter.AddRoute(r, module.LegacyQuerierHandler(legacyQuerierCdc)) | ||
} | ||
|
||
} | ||
} | ||
|
||
// RegisterServices registers all module services | ||
func (m *FilteredModuleManager) RegisterServices(cfg module.Configurator) { | ||
for _, module := range m.Modules { | ||
if m.isModuleFiltered(module.Name()) { | ||
continue | ||
} | ||
|
||
module.RegisterServices(cfg) | ||
} | ||
} | ||
|
||
func (m *FilteredModuleManager) isModuleFiltered(moduleName string) bool { | ||
return slices.Any(m.filteredModules, func(s string) bool { | ||
return s == moduleName | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package app_test | ||
|
||
import ( | ||
"testing" | ||
|
||
bam "github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/tests/mocks" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/axelarnetwork/axelar-core/app" | ||
) | ||
|
||
func TestFilteredModuleManager_RegisterServices(t *testing.T) { | ||
encodingConfig := app.MakeEncodingConfig() | ||
configurator := module.NewConfigurator(encodingConfig.Codec, bam.NewMsgServiceRouter(), bam.NewGRPCQueryRouter()) | ||
mockCtrl := gomock.NewController(t) | ||
|
||
mockAppModule1 := mocks.NewMockAppModule(mockCtrl) | ||
mockAppModule2 := mocks.NewMockAppModule(mockCtrl) | ||
|
||
mockAppModule1.EXPECT().Name().Times(3).Return("module1") | ||
mockAppModule2.EXPECT().Name().Times(3).Return("module2") | ||
|
||
mockAppModule1.EXPECT().RegisterServices(configurator).Times(1) | ||
mockAppModule2.EXPECT().RegisterServices(configurator).Times(0) | ||
|
||
mm := app.NewFilteredModuleManager([]module.AppModule{mockAppModule1, mockAppModule2}, []string{"module2"}) | ||
mm.RegisterServices(configurator) | ||
|
||
} | ||
|
||
func TestFilteredModuleManager_RegisterRoutes(t *testing.T) { | ||
encodingConfig := app.MakeEncodingConfig() | ||
mockCtrl := gomock.NewController(t) | ||
|
||
mockAppModule1 := mocks.NewMockAppModule(mockCtrl) | ||
mockAppModule2 := mocks.NewMockAppModule(mockCtrl) | ||
|
||
mockAppModule1.EXPECT().Name().Times(3).Return("module1") | ||
mockAppModule2.EXPECT().Name().Times(3).Return("module2") | ||
|
||
mm := app.NewFilteredModuleManager([]module.AppModule{mockAppModule1, mockAppModule2}, []string{"module2"}) | ||
|
||
router := bam.NewRouter() | ||
queryRouter := bam.NewQueryRouter() | ||
noopHandler := sdk.Handler(func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { return nil, nil }) | ||
|
||
mockAppModule1.EXPECT().QuerierRoute().Times(1) | ||
mockAppModule1.EXPECT().Route().Times(1).Return(sdk.NewRoute("route1", noopHandler)) | ||
mockAppModule2.EXPECT().Route().Times(0) | ||
|
||
mm.RegisterRoutes(router, queryRouter, encodingConfig.Amino) | ||
assert.Nil(t, router.Route(sdk.Context{}, "route2")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters