Skip to content

Commit

Permalink
Merge branch 'main' into AXE-6259-Fix-IBC-transfer-retry-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx authored Nov 5, 2024
2 parents e8a959f + d8e91da commit e3ac476
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ type AxelarApp struct {

interfaceRegistry types.InterfaceRegistry

mm *module.Manager
mm *FilteredModuleManager
}

// NewAxelarApp is a constructor function for axelar
Expand Down Expand Up @@ -309,7 +309,7 @@ func NewAxelarApp(
),
)

mm := module.NewManager(appModules...)
mm := NewFilteredModuleManager(appModules, []string{vestingtypes.ModuleName})
mm.SetOrderMigrations(orderMigrations()...)
mm.SetOrderBeginBlockers(orderBeginBlockers()...)
mm.SetOrderEndBlockers(orderEndBlockers()...)
Expand Down
57 changes: 57 additions & 0 deletions app/module_manager.go
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
})
}
57 changes: 57 additions & 0 deletions app/module_manager_test.go
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"))
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/ethereum/go-ethereum v1.10.26
github.com/go-errors/errors v1.5.1
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand Down

0 comments on commit e3ac476

Please sign in to comment.