Skip to content

Commit

Permalink
Fix module interface registration (#6834)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc authored Jul 24, 2020
1 parent b20b26d commit 1538e65
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 74 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa
* The `SigVerifiableTx` interface now has a `GetSignaturesV2() ([]signing.SignatureV2, error)` method and no longer has the `GetSignBytes` method.
* (client/flags) [\#6632](https://github.com/cosmos/cosmos-sdk/pull/6632) Remove NewCompletionCmd(), the function is now available in tendermint.
* (crypto) [\#6780](https://github.com/cosmos/cosmos-sdk/issues/6780) Move ledger code to its own package.
* (modules) [\#6834](https://github.com/cosmos/cosmos-sdk/issues/6834) Add `RegisterInterfaces` method to `AppModuleBasic` to support registration of protobuf interface types.

### Features

Expand Down
2 changes: 1 addition & 1 deletion simapp/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ func MakeEncodingConfig() params.EncodingConfig {
std.RegisterCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaceModules(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
14 changes: 7 additions & 7 deletions tests/mocks/tendermint_tm_db_DB.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 53 additions & 16 deletions tests/mocks/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions types/module/interface_module.go

This file was deleted.

9 changes: 9 additions & 0 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -48,6 +49,7 @@ import (
type AppModuleBasic interface {
Name() string
RegisterCodec(*codec.Codec)
RegisterInterfaces(codectypes.InterfaceRegistry)

DefaultGenesis(codec.JSONMarshaler) json.RawMessage
ValidateGenesis(codec.JSONMarshaler, json.RawMessage) error
Expand Down Expand Up @@ -77,6 +79,13 @@ func (bm BasicManager) RegisterCodec(cdc *codec.Codec) {
}
}

// RegisterInterfaces registers all module interface types
func (bm BasicManager) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
for _, m := range bm {
m.RegisterInterfaces(registry)
}
}

// DefaultGenesis provides default genesis information for all modules
func (bm BasicManager) DefaultGenesis(cdc codec.JSONMarshaler) map[string]json.RawMessage {
genesis := make(map[string]json.RawMessage)
Expand Down
5 changes: 5 additions & 0 deletions types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"testing"

"github.com/cosmos/cosmos-sdk/codec/types"

"github.com/golang/mock/gomock"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
Expand All @@ -24,6 +26,7 @@ func TestBasicManager(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
cdc := codec.New()
interfaceRegistry := types.NewInterfaceRegistry()
clientCtx := client.Context{}
clientCtx = clientCtx.WithCodec(cdc)
wantDefaultGenesis := map[string]json.RawMessage{"mockAppModuleBasic1": json.RawMessage(``)}
Expand All @@ -35,13 +38,15 @@ func TestBasicManager(t *testing.T) {
mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(wantDefaultGenesis["mockAppModuleBasic1"])).Times(1).Return(errFoo)
mockAppModuleBasic1.EXPECT().RegisterRESTRoutes(gomock.Eq(client.Context{}), gomock.Eq(&mux.Router{})).Times(1)
mockAppModuleBasic1.EXPECT().RegisterCodec(gomock.Eq(cdc)).Times(1)
mockAppModuleBasic1.EXPECT().RegisterInterfaces(gomock.Eq(interfaceRegistry)).Times(1)
mockAppModuleBasic1.EXPECT().GetTxCmd().Times(1).Return(nil)
mockAppModuleBasic1.EXPECT().GetQueryCmd().Times(1).Return(nil)

mm := module.NewBasicManager(mockAppModuleBasic1)
require.Equal(t, mm["mockAppModuleBasic1"], mockAppModuleBasic1)

mm.RegisterCodec(cdc)
mm.RegisterInterfaces(interfaceRegistry)

require.Equal(t, wantDefaultGenesis, mm.DefaultGenesis(cdc))

Expand Down
5 changes: 2 additions & 3 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
_ module.InterfaceModule = AppModuleBasic{}
)

// AppModuleBasic defines the basic application module used by the auth module.
Expand Down Expand Up @@ -75,8 +74,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// RegisterInterfaceTypes registers interfaces and implementations of the auth module.
func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) {
// RegisterInterfaces registers interfaces and implementations of the auth module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}

Expand Down
5 changes: 2 additions & 3 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
_ module.InterfaceModule = AppModuleBasic{}
)

// AppModuleBasic defines the basic application module used by the bank module.
Expand Down Expand Up @@ -72,8 +71,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// RegisterInterfaceTypes registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) {
// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}

Expand Down
5 changes: 5 additions & 0 deletions x/capability/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"math/rand"

cdctypes "github.com/cosmos/cosmos-sdk/codec/types"

"github.com/gogo/protobuf/grpc"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -49,6 +51,9 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
types.RegisterCodec(cdc)
}

// RegisterInterfaces registers the module's interface types
func (a AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {}

// DefaultGenesis returns the capability module's default genesis state.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesis())
Expand Down
4 changes: 2 additions & 2 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func (b AppModuleBasic) GetTxCmd() *cobra.Command {
// GetQueryCmd returns no root query command for the crisis module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }

// RegisterInterfaceTypes registers interfaces and implementations of the crisis
// RegisterInterfaces registers interfaces and implementations of the crisis
// module.
func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) {
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}

Expand Down
Loading

0 comments on commit 1538e65

Please sign in to comment.