Add RegisterQueryService to AppModule (#6336)
* Add RegisterQueryService to AppModule * Update CHANGELOG.md * Update CHANGELOG.md * Wire up BaseApp, fix tests * Add mock test * add missing file * Update types/module/module.go * Update CHANGELOG.md Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
7eeb086d3a
commit
43947ca2ef
@ -114,6 +114,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa
|
||||
- TxBuilder.SignStdTx
|
||||
* (client) [\#6290](https://github.com/cosmos/cosmos-sdk/pull/6290) `CLIContext` is renamed to `Context`. `Context` and all related methods have been moved from package context to client.
|
||||
* (modules) [\#6326](https://github.com/cosmos/cosmos-sdk/pull/6326) `AppModuleBasic.GetQueryCmd` now takes a single `CLIContext` parameter.
|
||||
* (modules) [\#6336](https://github.com/cosmos/cosmos-sdk/pull/6336) `AppModuleBasic.RegisterQueryService` method was added to support gRPC queries, and `QuerierRoute` and `NewQuerierHandler` were deprecated.
|
||||
|
||||
Migration guide:
|
||||
|
||||
|
||||
1
Makefile
1
Makefile
@ -42,6 +42,7 @@ mocks: $(MOCKS_DIR)
|
||||
mockgen -source=types/invariant.go -package mocks -destination tests/mocks/types_invariant.go
|
||||
mockgen -source=types/router.go -package mocks -destination tests/mocks/types_router.go
|
||||
mockgen -source=types/handler.go -package mocks -destination tests/mocks/types_handler.go
|
||||
mockgen -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server
|
||||
.PHONY: mocks
|
||||
|
||||
$(MOCKS_DIR):
|
||||
|
||||
@ -304,6 +304,7 @@ func NewSimApp(
|
||||
|
||||
app.mm.RegisterInvariants(&app.CrisisKeeper)
|
||||
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())
|
||||
app.mm.RegisterQueryServices(app.GRPCQueryRouter())
|
||||
|
||||
// create the simulation manager and define the order of the modules for deterministic simulations
|
||||
//
|
||||
|
||||
46
tests/mocks/grpc_server.go
Normal file
46
tests/mocks/grpc_server.go
Normal file
@ -0,0 +1,46 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/gogo/protobuf/grpc (interfaces: Server)
|
||||
|
||||
// Package mocks is a generated GoMock package.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
grpc "google.golang.org/grpc"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockServer is a mock of Server interface
|
||||
type MockServer struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockServerMockRecorder
|
||||
}
|
||||
|
||||
// MockServerMockRecorder is the mock recorder for MockServer
|
||||
type MockServerMockRecorder struct {
|
||||
mock *MockServer
|
||||
}
|
||||
|
||||
// NewMockServer creates a new mock instance
|
||||
func NewMockServer(ctrl *gomock.Controller) *MockServer {
|
||||
mock := &MockServer{ctrl: ctrl}
|
||||
mock.recorder = &MockServerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockServer) EXPECT() *MockServerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// RegisterService mocks base method
|
||||
func (m *MockServer) RegisterService(arg0 *grpc.ServiceDesc, arg1 interface{}) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "RegisterService", arg0, arg1)
|
||||
}
|
||||
|
||||
// RegisterService indicates an expected call of RegisterService
|
||||
func (mr *MockServerMockRecorder) RegisterService(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterService", reflect.TypeOf((*MockServer)(nil).RegisterService), arg0, arg1)
|
||||
}
|
||||
@ -9,6 +9,7 @@ import (
|
||||
client "github.com/cosmos/cosmos-sdk/client"
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
types "github.com/cosmos/cosmos-sdk/types"
|
||||
grpc "github.com/gogo/protobuf/grpc"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
mux "github.com/gorilla/mux"
|
||||
cobra "github.com/spf13/cobra"
|
||||
@ -491,6 +492,18 @@ func (mr *MockAppModuleMockRecorder) NewQuerierHandler() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewQuerierHandler", reflect.TypeOf((*MockAppModule)(nil).NewQuerierHandler))
|
||||
}
|
||||
|
||||
// RegisterQueryService mocks base method
|
||||
func (m *MockAppModule) RegisterQueryService(arg0 grpc.Server) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "RegisterQueryService", arg0)
|
||||
}
|
||||
|
||||
// RegisterQueryService indicates an expected call of RegisterQueryService
|
||||
func (mr *MockAppModuleMockRecorder) RegisterQueryService(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterQueryService", reflect.TypeOf((*MockAppModule)(nil).RegisterQueryService), arg0)
|
||||
}
|
||||
|
||||
// BeginBlock mocks base method
|
||||
func (m *MockAppModule) BeginBlock(arg0 types.Context, arg1 types0.RequestBeginBlock) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@ -31,6 +31,8 @@ package module
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -141,8 +143,12 @@ type AppModule interface {
|
||||
// routes
|
||||
Route() string
|
||||
NewHandler() sdk.Handler
|
||||
// Deprecated: use RegisterQueryService
|
||||
QuerierRoute() string
|
||||
// Deprecated: use RegisterQueryService
|
||||
NewQuerierHandler() sdk.Querier
|
||||
// RegisterQueryService allows a module to register a gRPC query service
|
||||
RegisterQueryService(grpc.Server)
|
||||
|
||||
// ABCI
|
||||
BeginBlock(sdk.Context, abci.RequestBeginBlock)
|
||||
@ -178,6 +184,8 @@ func (GenesisOnlyAppModule) QuerierRoute() string { return "" }
|
||||
// NewQuerierHandler returns an empty module querier
|
||||
func (gam GenesisOnlyAppModule) NewQuerierHandler() sdk.Querier { return nil }
|
||||
|
||||
func (gam GenesisOnlyAppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// BeginBlock returns an empty module begin-block
|
||||
func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {}
|
||||
|
||||
@ -256,6 +264,13 @@ func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter)
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterQueryServices registers all module query services
|
||||
func (m *Manager) RegisterQueryServices(grpcRouter grpc.Server) {
|
||||
for _, module := range m.Modules {
|
||||
module.RegisterQueryService(grpcRouter)
|
||||
}
|
||||
}
|
||||
|
||||
// InitGenesis performs init genesis functionality for modules
|
||||
func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, genesisData map[string]json.RawMessage) abci.ResponseInitChain {
|
||||
var validatorUpdates []abci.ValidatorUpdate
|
||||
|
||||
@ -159,6 +159,25 @@ func TestManager_RegisterRoutes(t *testing.T) {
|
||||
mm.RegisterRoutes(router, queryRouter)
|
||||
}
|
||||
|
||||
func TestManager_RegisterQueryServices(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
t.Cleanup(mockCtrl.Finish)
|
||||
|
||||
mockAppModule1 := mocks.NewMockAppModule(mockCtrl)
|
||||
mockAppModule2 := mocks.NewMockAppModule(mockCtrl)
|
||||
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
|
||||
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
|
||||
mm := module.NewManager(mockAppModule1, mockAppModule2)
|
||||
require.NotNil(t, mm)
|
||||
require.Equal(t, 2, len(mm.Modules))
|
||||
|
||||
queryRouter := mocks.NewMockServer(mockCtrl)
|
||||
mockAppModule1.EXPECT().RegisterQueryService(queryRouter).Times(1)
|
||||
mockAppModule2.EXPECT().RegisterQueryService(queryRouter).Times(1)
|
||||
|
||||
mm.RegisterQueryServices(queryRouter)
|
||||
}
|
||||
|
||||
func TestManager_InitGenesis(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
t.Cleanup(mockCtrl.Finish)
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -118,6 +120,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.accountKeeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the auth module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -86,6 +88,8 @@ type AppModule struct {
|
||||
accountKeeper types.AccountKeeper
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
func NewAppModule(cdc codec.Marshaler, keeper Keeper, accountKeeper types.AccountKeeper) AppModule {
|
||||
return AppModule{
|
||||
|
||||
@ -5,6 +5,11 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -12,10 +17,6 @@ import (
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -105,6 +106,8 @@ func (am AppModule) NewHandler() sdk.Handler { return nil }
|
||||
// NewQuerierHandler returns the capability module's Querier.
|
||||
func (am AppModule) NewQuerierHandler() sdk.Querier { return nil }
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// RegisterInvariants registers the capability module's invariants.
|
||||
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -107,6 +109,8 @@ func (AppModule) QuerierRoute() string { return "" }
|
||||
// NewQuerierHandler returns no sdk.Querier.
|
||||
func (AppModule) NewQuerierHandler() sdk.Querier { return nil }
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the crisis module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -136,6 +138,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the distribution module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -144,6 +146,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// RegisterInvariants registers the evidence module's invariants.
|
||||
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -152,6 +154,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the gov module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -122,6 +124,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the ibc transfer module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -126,6 +127,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(*am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the ibc module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -113,6 +115,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the mint module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -97,6 +99,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// ProposalContents returns all the params content functions used to
|
||||
// simulate governance proposals.
|
||||
func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -127,6 +129,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the slashing module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
flag "github.com/spf13/pflag"
|
||||
@ -151,6 +153,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis performs genesis initialization for the staking module. It returns
|
||||
// no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
|
||||
@ -3,6 +3,8 @@ package upgrade
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -109,6 +111,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||
return NewQuerier(am.keeper)
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
||||
|
||||
// InitGenesis is ignored, no sense in serializing future upgrades
|
||||
func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate {
|
||||
return []abci.ValidatorUpdate{}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user