Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app)!: deregister handlers for vesting module #2201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -308,7 +308,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
Loading