feat!: simplify AppModuleBasic interface for CLI (#16890)
This commit is contained in:
+12
-8
@@ -57,11 +57,7 @@ type AppModuleBasic interface {
|
||||
HasName
|
||||
RegisterLegacyAminoCodec(*codec.LegacyAmino)
|
||||
RegisterInterfaces(types.InterfaceRegistry)
|
||||
|
||||
// client functionality
|
||||
RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)
|
||||
GetTxCmd() *cobra.Command
|
||||
GetQueryCmd() *cobra.Command
|
||||
}
|
||||
|
||||
// HasName allows the module to provide its own name for legacy purposes.
|
||||
@@ -163,8 +159,12 @@ func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *
|
||||
// AddTxCommands adds all tx commands to the rootTxCmd.
|
||||
func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
|
||||
for _, b := range bm {
|
||||
if cmd := b.GetTxCmd(); cmd != nil {
|
||||
rootTxCmd.AddCommand(cmd)
|
||||
if mod, ok := b.(interface {
|
||||
GetTxCmd() *cobra.Command
|
||||
}); ok {
|
||||
if cmd := mod.GetTxCmd(); cmd != nil {
|
||||
rootTxCmd.AddCommand(cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,8 +172,12 @@ func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
|
||||
// AddQueryCommands adds all query commands to the rootQueryCmd.
|
||||
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) {
|
||||
for _, b := range bm {
|
||||
if cmd := b.GetQueryCmd(); cmd != nil {
|
||||
rootQueryCmd.AddCommand(cmd)
|
||||
if mod, ok := b.(interface {
|
||||
GetQueryCmd() *cobra.Command
|
||||
}); ok {
|
||||
if cmd := mod.GetQueryCmd(); cmd != nil {
|
||||
rootQueryCmd.AddCommand(cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@ import (
|
||||
|
||||
var errFoo = errors.New("dummy")
|
||||
|
||||
func (MockCoreAppModule) GetQueryCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "foo",
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasicManager(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
t.Cleanup(mockCtrl.Finish)
|
||||
@@ -52,8 +58,6 @@ func TestBasicManager(t *testing.T) {
|
||||
mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(nil), gomock.Eq(expDefaultGenesis["mockAppModuleBasic1"])).AnyTimes().Return(nil)
|
||||
mockAppModuleBasic1.EXPECT().RegisterLegacyAminoCodec(gomock.Eq(legacyAmino)).Times(1)
|
||||
mockAppModuleBasic1.EXPECT().RegisterInterfaces(gomock.Eq(interfaceRegistry)).Times(1)
|
||||
mockAppModuleBasic1.EXPECT().GetTxCmd().Times(1).Return(nil)
|
||||
mockAppModuleBasic1.EXPECT().GetQueryCmd().Times(1).Return(nil)
|
||||
|
||||
// mock core API module
|
||||
mockCoreAppModule2 := mock.NewMockCoreAppModule(mockCtrl)
|
||||
@@ -82,8 +86,8 @@ func TestBasicManager(t *testing.T) {
|
||||
|
||||
mockCmd := &cobra.Command{Use: "root"}
|
||||
mm.AddTxCommands(mockCmd)
|
||||
|
||||
mm.AddQueryCommands(mockCmd)
|
||||
require.Equal(t, 1, len(mockCmd.Commands()))
|
||||
|
||||
// validate genesis returns nil
|
||||
require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, nil, expDefaultGenesis))
|
||||
|
||||
Reference in New Issue
Block a user