refactor!: kill basic manager (#19512)

This commit is contained in:
Julien Robert 2024-02-22 15:44:49 +01:00 committed by GitHub
parent d1d3bf0620
commit b304cf7556
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
170 changed files with 1629 additions and 2324 deletions

View File

@ -56,6 +56,10 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
### Improvements
* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) The notion of basic manager does not exist anymore.
* The module manager now can do everything that the basic manager was doing.
* `AppModuleBasic` has been deprecated for extension interfaces. Modules can now implement `HasRegisterInterfaces`, `HasGRPCGateway` and `HasAminoCodec` when relevant.
* SDK modules now directly implement those extension interfaces on `AppModule` instead of `AppModuleBasic`.
* (client/keys) [#18950](https://github.com/cosmos/cosmos-sdk/pull/18950) Improve `<appd> keys add`, `<appd> keys import` and `<appd> keys rename` by checking name validation.
* (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve `<appd> keys export` and `<appd> keys mnemonic` by adding --yes option to skip interactive confirmation.
* (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve `<appd> keys add -i` by hiding inputting of bip39 passphrase.
@ -100,6 +104,10 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
### API Breaking Changes
* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) Remove basic manager and all related functions (`module.BasicManager`, `module.NewBasicManager`, `module.NewBasicManagerFromManager`, `NewGenesisOnlyAppModule`).
* The module manager now can do everything that the basic manager was doing.
* When using runtime, just inject the module manager when needed using your app config.
* All `AppModuleBasic` structs have been removed.
* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services.
* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does.
* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration.

View File

@ -10,11 +10,6 @@ Note, always read the **SimApp** section for more information on application wir
In this section we describe the changes made in Cosmos SDK' SimApp.
**These changes are directly applicable to your application wiring.**
#### AnteHandlers
The GasConsumptionDecorator and IncreaseSequenceDecorator have been merged with the SigVerificationDecorator, so you'll
need to remove them both from your app.go code, they will yield to unresolvable symbols when compiling.
#### Client (`root.go`)
The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.).
@ -33,16 +28,32 @@ clientCtx = clientCtx.
Refer to SimApp `root_v2.go` and `root.go` for an example with an app v2 and a legacy app.
### Core
#### Server (`app.go`)
`appmodule.Environment` interface was introduced to fetch different services from the application. This can be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services. It needs to be passed into a module at instantiation.
##### Module Manager
Circuit Breaker is used as an example.
The basic module manager has been deleted. It was not necessary anymore and was simplified to use the `module.Manager` directly.
It can be removed from your `app.go`.
```go
app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey])), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec())
For depinject users, it isn't necessary anymore to supply a `map[string]module.AppModuleBasic` for customizing the app module basic instantiation.
The custom parameters (such as genutil message validator or gov proposal handler, or evidence handler) can directly be supplied.
When requiring a module manager in `root.go`, inject `*module.Manager` using `depinject.Inject`.
For non depinject users, simply call `RegisterLegacyAminoCodec` and `RegisterInterfaces` on the module manager:
```diff
-app.BasicModuleManager = module.NewBasicManagerFromManager(...)
-app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
-app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
+app.ModuleManager.RegisterLegacyAminoCodec(legacyAmino)
+app.ModuleManager.RegisterInterfaces(interfaceRegistry)
```
##### AnteHandlers
The `GasConsumptionDecorator` and `IncreaseSequenceDecorator` have been merged with the SigVerificationDecorator, so you'll
need to remove them both from your app.go code, they will yield to unresolvable symbols when compiling.
#### Unordered Transactions
The Cosmos SDK now supports unordered transactions. This means that transactions
@ -129,26 +140,35 @@ If you were depending on `cosmossdk.io/api/tendermint`, please use the buf gener
#### `**all**`
##### Params
Previous module migrations have been removed. It is required to migrate to v0.50 prior to upgrading to v0.51 for not missing any module migrations.
##### Core API
Core API has been introduces for modules in v0.47. With the deprecation of `sdk.Context`, we strongly recommend to use the `cosmossdk.io/core/appmodule` interfaces for the modules. This will allow the modules to work out of the box with server/v2 and baseapp, as well as limit their dependencies on the SDK.
Core API has been introduced for modules since v0.47. With the deprecation of `sdk.Context`, we strongly recommend to use the `cosmossdk.io/core/appmodule` interfaces for the modules. This will allow the modules to work out of the box with server/v2 and baseapp, as well as limit their dependencies on the SDK.
Additionally, the `appmodule.Environment` interface is introduced to fetch different services from the application.
This should be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services.
It needs to be passed into a module at instantiation.
`x/circuit` is used as an example.:
```go
app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey])), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec())
```
##### Dependency Injection
Previously `cosmossdk.io/core` held functions `Invoke`, `Provide` and `Register` were moved to `cosmossdk.io/depinject/appconfig`.
All modules using dependency injection must update their imports.
##### Params
Previous module migrations have been removed. It is required to migrate to v0.50 prior to upgrading to v0.51 for not missing any module migrations.
##### Genesis Interface
All genesis interfaces have been migrated to take context.Context instead of sdk.Context.
```golang
// InitGenesis performs genesis initialization for the authz module. It returns
// no validator updates.
```go
// InitGenesis performs genesis initialization for the authz module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
}

View File

@ -163,7 +163,7 @@ func (msr *MsgServiceRouter) registerMsgServiceHandler(sd *grpc.ServiceDesc, met
return fmt.Errorf(
"type_url %s has not been registered yet. "+
"Before calling RegisterService, you must register all interfaces by calling the `RegisterInterfaces` "+
"method on module.BasicManager. Each module should call `msgservice.RegisterMsgServiceDesc` inside its "+
"method on module.Manager. Each module should call `msgservice.RegisterMsgServiceDesc` inside its "+
"`RegisterInterfaces` method with the `_Msg_serviceDesc` generated by proto-gen",
requestTypeName,
)

View File

@ -39,7 +39,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
keys := storetypes.NewKVStoreKeys(countertypes.StoreKey)
cms := integration.CreateMultiStore(keys, logger)
s.ctx = sdk.NewContext(cms, true, logger)
cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModuleBasic{})
cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModule{})
s.cdc = cfg.Codec
queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, cfg.InterfaceRegistry)

View File

@ -32,7 +32,7 @@ var (
)
func TestAuxTxBuilder(t *testing.T) {
counterModule := counter.AppModuleBasic{}
counterModule := counter.AppModule{}
cdc := moduletestutil.MakeTestEncodingConfig(counterModule).Codec
reg := codectypes.NewInterfaceRegistry()

View File

@ -51,7 +51,7 @@ func initFixture(t *testing.T) *fixture {
clientConn, err := grpc.Dial(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NilError(t, err)
encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModule{})
kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendMemory, home, nil, encodingConfig.Codec)
assert.NilError(t, err)

View File

@ -174,7 +174,7 @@ require (
replace github.com/cosmos/cosmos-sdk => ./../../
replace (
cosmossdk.io/api => ../../api
cosmossdk.io/api => ./../../api
cosmossdk.io/core => ./../../core
cosmossdk.io/depinject => ./../../depinject
cosmossdk.io/x/accounts => ./../../x/accounts

View File

@ -349,7 +349,7 @@ type TxBuilder interface {
```
We then update `Context` to have new fields: `Codec`, `TxGenerator`,
and `AccountRetriever`, and we update `AppModuleBasic.GetTxCmd` to take
and `AccountRetriever`, and we update `AppModule.GetTxCmd` to take
a `Context` which should have all of these fields pre-populated.
Each client method should then use one of the `Init` methods to re-initialize

View File

@ -261,7 +261,7 @@ func TxEmitter(ctx context.Context, cliCtx client.Context, ehs ...EventHandler)
}
// PublishChainTxEvents events using cmtclient. Waits on context shutdown signals to exit.
func PublishChainTxEvents(ctx context.Context, client cmtclient.EventsClient, bus pubsub.Bus, mb module.BasicManager) (err error) {
func PublishChainTxEvents(ctx context.Context, client cmtclient.EventsClient, bus pubsub.Bus) (err error) {
// Subscribe to transaction events
txch, err := client.Subscribe(ctx, "txevents", "tm.event='Tx'", 100)
if err != nil {
@ -289,12 +289,12 @@ func PublishChainTxEvents(ctx context.Context, client cmtclient.EventsClient, bu
if !evt.Result.IsOK() {
continue
}
// range over events, parse them using the basic manager and
// range over events and parse them
// send them to the pubsub bus
for _, abciEv := range events {
typedEvent, err := sdk.ParseTypedEvent(abciEv)
if err != nil {
return er
return err
}
if err := bus.Publish(typedEvent); err != nil {
bus.Close()

View File

@ -264,7 +264,7 @@ type Configurator interface {
The `ModuleKey` is passed to modules in the `RegisterService` method itself so that `RegisterServices` serves as a single
entry point for configuring module services. This is intended to also have the side-effect of greatly reducing boilerplate in
`app.go`. For now, `ModuleKey`s will be created based on `AppModuleBasic.Name()`, but a more flexible system may be
`app.go`. For now, `ModuleKey`s will be created based on `AppModule.Name()`, but a more flexible system may be
introduced in the future. The `ModuleManager` will handle creation of module accounts behind the scenes.
Because modules do not get direct access to each other anymore, modules may have unfulfilled dependencies. To make sure
@ -344,7 +344,7 @@ Other future improvements may include:
* optimizes inter-module calls - for instance caching resolved methods after first invocation
* combining `StoreKey`s and `ModuleKey`s into a single interface so that modules have a single OCAPs handle
* code generation which makes inter-module communication more performant
* decoupling `ModuleKey` creation from `AppModuleBasic.Name()` so that app's can override root module account names
* decoupling `ModuleKey` creation from `AppModule.Name()` so that app's can override root module account names
* inter-module hooks and plugins
## Alternatives

View File

@ -463,10 +463,10 @@ module manager and follow the Cosmos SDK's existing [0-based versioning](https:/
versioning as well as runtime modularity, new officially supported runtime modules will be created under the
`cosmossdk.io/runtime` prefix. For each supported consensus engine a semantically-versioned go module should be created
with a runtime implementation for that consensus engine. For example:
- `cosmossdk.io/runtime/comet`
- `cosmossdk.io/runtime/comet/v2`
- `cosmossdk.io/runtime/rollkit`
- etc.
* `cosmossdk.io/runtime/comet`
* `cosmossdk.io/runtime/comet/v2`
* `cosmossdk.io/runtime/rollkit`
* etc.
These runtime modules should attempt to be semantically versioned even if the underlying consensus engine is not. Also,
because a runtime module is also a first class Cosmos SDK module, it should have a protobuf module config type.

View File

@ -27,15 +27,13 @@ For legacy reason modules can still implement interfaces from the SDK `module` p
There are 2 main application module interfaces:
* [`appmodule.AppModule` / `module.AppModule`](#appmodule) for inter-dependent module functionalities (except genesis-related functionalities).
* (legacy) [`module.AppModuleBasic`](#appmodulebasic) for independent module functionalities. New modules can use `module.CoreAppModuleBasicAdaptor` instead.
The above interfaces are mostly embedding smaller interfaces (extension interfaces), that defines specific functionalities:
* (legacy) `module.HasName`: Allows the module to provide its own name for legacy purposes.
* (legacy) [`module.HasGenesisBasics`](#modulehasgenesisbasics): The legacy interface for stateless genesis methods.
* [`module.HasGenesis`](#modulehasgenesis) for inter-dependent genesis-related module functionalities.
* [`module.HasABCIGenesis`](#modulehasabcigenesis) for inter-dependent genesis-related module functionalities.
* [`appmodule.HasGenesis` / `module.HasGenesis`](#appmodulehasgenesis): The extension interface for stateful genesis methods.
* (legacy) [`module.HasGenesis`](#modulehasgenesis) for inter-dependent genesis-related module functionalities.
* (legacy) [`module.HasABCIGenesis`](#modulehasabcigenesis) for inter-dependent genesis-related module functionalities.
* [`appmodule.HasPreBlocker`](#haspreblocker): The extension interface that contains information about the `AppModule` and `PreBlock`.
* [`appmodule.HasBeginBlocker`](#hasbeginblocker): The extension interface that contains information about the `AppModule` and `BeginBlock`.
* [`appmodule.HasEndBlocker`](#hasendblocker): The extension interface that contains information about the `AppModule` and `EndBlock`.
@ -46,31 +44,34 @@ The above interfaces are mostly embedding smaller interfaces (extension interfac
* (legacy) [`module.HasInvariants`](#hasinvariants): The extension interface for registering invariants.
* (legacy) [`module.HasConsensusVersion`](#hasconsensusversion): The extension interface for declaring a module consensus version.
The `AppModuleBasic` interface exists to define independent methods of the module, i.e. those that do not depend on other modules in the application. This allows for the construction of the basic application structure early in the application definition, generally in the `init()` function of the [main application file](https://docs.cosmos.network/main/learn/beginner/app-anatomy).
The `AppModule` interface exists to define inter-dependent module methods. Many modules need to interact with other modules, typically through [`keeper`s](./06-keeper.md), which means there is a need for an interface where modules list their `keeper`s and other methods that require a reference to another module's object. `AppModule` interface extension, such as `HasBeginBlocker` and `HasEndBlocker`, also enables the module manager to set the order of execution between module's methods like `BeginBlock` and `EndBlock`, which is important in cases where the order of execution between modules matters in the context of the application.
The usage of extension interfaces allows modules to define only the functionalities they need. For example, a module that does not need an `EndBlock` does not need to define the `HasEndBlocker` interface and thus the `EndBlock` method. `AppModule` and `AppModuleGenesis` are voluntarily small interfaces, that can take advantage of the `Module` patterns without having to define many placeholder functions.
### `AppModuleBasic`
:::note
Use `module.CoreAppModuleBasicAdaptor` instead for creating an `AppModuleBasic` from an `appmodule.AppModule`.
:::
The `AppModuleBasic` interface defines the independent methods modules need to implement.
### `HasAminoCodec`
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L56-L66
// TODO
```
Let us go through the methods:
* `RegisterLegacyAminoCodec(*codec.LegacyAmino)`: Registers the `amino` codec for the module, which is used to marshal and unmarshal structs to/from `[]byte` in order to persist them in the module's `KVStore`.
### `HasRegisterInterfaces`
```go reference
// TODO
```
* `RegisterInterfaces(codectypes.InterfaceRegistry)`: Registers a module's interface types and their concrete implementations as `proto.Message`.
### `HasGRPCGateway`
```go reference
// TODO
```
* `RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)`: Registers gRPC routes for the module.
All the `AppModuleBasic` of an application are managed by the [`BasicManager`](#basicmanager).
### `HasName`
@ -83,7 +84,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go
### Genesis
:::tip
For easily creating an `AppModule` that only has genesis functionalities, use `module.GenesisOnlyAppModule`.
For easily creating an `AppModule` that only has genesis functionalities, implement `module.HasGenesis/HasABCIGenesis` and `module.HasName`.
:::
#### `module.HasGenesisBasics`
@ -113,16 +114,6 @@ https://github.com/cosmos/cosmos-sdk/blob/6ce2505/types/module/module.go#L184-L1
https://github.com/cosmos/cosmos-sdk/blob/6ce2505/types/module/module.go#L191-L196
```
#### `appmodule.HasGenesis`
:::warning
`appmodule.HasGenesis` is experimental and should be considered unstable, it is recommended to not use this interface at this time.
:::
```go reference
https://github.com/cosmos/cosmos-sdk/blob/6ce2505/core/appmodule/genesis.go#L8-L25
```
### `AppModule`
The `AppModule` interface defines a module. Modules can declare their functionalities by implementing extensions interfaces.
@ -238,49 +229,24 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module.
### Implementing the Application Module Interfaces
// TODO reword!
Typically, the various application module interfaces are implemented in a file called `module.go`, located in the module's folder (e.g. `./x/module/module.go`).
Almost every module needs to implement the `AppModuleBasic` and `AppModule` interfaces. If the module is only used for genesis, it will implement `AppModuleGenesis` instead of `AppModule`. The concrete type that implements the interface can add parameters that are required for the implementation of the various methods of the interface. For example, the `Route()` function often calls a `NewMsgServerImpl(k keeper)` function defined in `keeper/msg_server.go` and therefore needs to pass the module's [`keeper`](./06-keeper.md) as a parameter.
Almost every module needs to implement the `AppModule` interfaces. If the module is only used for genesis, it will implement `AppModuleGenesis` instead of `AppModule`. The concrete type that implements the interface can add parameters that are required for the implementation of the various methods of the interface. For example, the `Route()` function often calls a `NewMsgServerImpl(k keeper)` function defined in `keeper/msg_server.go` and therefore needs to pass the module's [`keeper`](./06-keeper.md) as a parameter.
```go
// example
type AppModule struct {
AppModuleBasic
keeper Keeper
}
```
In the example above, you can see that the `AppModule` concrete type references an `AppModuleBasic`, and not an `AppModuleGenesis`. That is because `AppModuleGenesis` only needs to be implemented in modules that focus on genesis-related functionalities. In most modules, the concrete `AppModule` type will have a reference to an `AppModuleBasic` and implement the two added methods of `AppModuleGenesis` directly in the `AppModule` type.
If no parameter is required (which is often the case for `AppModuleBasic`), just declare an empty concrete type like so:
## Module Manager
```go
type AppModuleBasic struct{}
```
## Module Managers
Module managers are used to manage collections of `AppModuleBasic` and `AppModule`.
### `BasicManager`
The `BasicManager` is a structure that lists all the `AppModuleBasic` of an application:
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L82
```
It implements the following methods:
* `NewBasicManager(modules ...AppModuleBasic)`: Constructor function. It takes a list of the application's `AppModuleBasic` and builds a new `BasicManager`. This function is generally called in the `init()` function of [`app.go`](../../learn/beginner/00-app-anatomy.md#core-application-file) to quickly initialize the independent elements of the application's modules (click [here](https://github.com/cosmos/gaia/blob/main/app/app.go#L59-L74) to see an example).
* `NewBasicManagerFromManager(manager *Manager, customModuleBasics map[string]AppModuleBasic)`: Constructor function. It creates a new `BasicManager` from a `Manager`. The `BasicManager` will contain all `AppModuleBasic` from the `AppModule` manager using `CoreAppModuleBasicAdaptor` whenever possible. Module's `AppModuleBasic` can be overridden by passing a custom AppModuleBasic map
* `RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)`: Registers the [`codec.LegacyAmino`s](../../learn/advanced/05-encoding.md#amino) of each of the application's `AppModuleBasic`. This function is usually called early on in the [application's construction](../../learn/beginner/00-app-anatomy.md#constructor).
* `RegisterInterfaces(registry codectypes.InterfaceRegistry)`: Registers interface types and implementations of each of the application's `AppModuleBasic`.
* `DefaultGenesis(cdc codec.JSONCodec)`: Provides default genesis information for modules in the application by calling the [`DefaultGenesis(cdc codec.JSONCodec)`](./08-genesis.md#defaultgenesis) function of each module. It only calls the modules that implements the `HasGenesisBasics` interfaces.
* `ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, genesis map[string]json.RawMessage)`: Validates the genesis information modules by calling the [`ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage)`](./08-genesis.md#validategenesis) function of modules implementing the `HasGenesisBasics` interface.
* `RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux)`: Registers gRPC routes for modules.
* `AddTxCommands(rootTxCmd *cobra.Command)`: Adds modules' transaction commands (defined as `GetTxCmd() *cobra.Command`) to the application's [`rootTxCommand`](../../learn/advanced/07-cli.md#transaction-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../../learn/advanced/07-cli.md).
* `AddQueryCommands(rootQueryCmd *cobra.Command)`: Adds modules' query commands (defined as `GetQueryCmd() *cobra.Command`) to the application's [`rootQueryCommand`](../../learn/advanced/07-cli.md#query-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../../learn/advanced/07-cli.md).
The module manager is used to manage collections of `appmodule.AppModule` and `AppModule` and all the extensions interfaces.
### `Manager`
@ -312,6 +278,11 @@ The module manager is used throughout the application whenever an action on a co
* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndBlock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any).
* `Precommit(ctx context.Context)`: During [`Commit`](../../learn/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../../learn/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../learn/advanced/04-store.md#commitmultistore) and, in turn calls the `Precommit` function of each modules implementing the `HasPrecommit` interface, in the order defined in `OrderPrecommiters`. It creates a child [context](../../learn/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`finalizeblockstate`](../../learn/advanced/00-baseapp.md#state-updates).
* `PrepareCheckState(ctx context.Context)`: During [`Commit`](../../learn/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately after the [`deliverState`](../../learn/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../learn/advanced/04-store.md#commitmultistore) and, in turn calls the `PrepareCheckState` function of each module implementing the `HasPrepareCheckState` interface, in the order defined in `OrderPrepareCheckStaters`. It creates a child [context](../../learn/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the next block's [`checkState`](../../learn/advanced/00-baseapp.md#state-updates). Writes to this state will be present in the [`checkState`](../../learn/advanced/00-baseapp.md#state-updates) of the next block, and therefore this method can be used to prepare the `checkState` for the next block.
* (Optional) `RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)`: Registers the [`codec.LegacyAmino`s](../../learn/advanced/05-encoding.md#amino) of each of the application module. This function is usually called early on in the [application's construction](../../learn/beginner/00-app-anatomy.md#constructor).
* `RegisterInterfaces(registry codectypes.InterfaceRegistry)`: Registers interface types and implementations of each of the application's `AppModule`.
* (Optional) `RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux)`: Registers gRPC routes for modules.
* `DefaultGenesis(cdc codec.JSONCodec)`: Provides default genesis information for modules in the application by calling the [`DefaultGenesis(cdc codec.JSONCodec)`](./08-genesis.md#defaultgenesis) function of each module. It only calls the modules that implements the `HasGenesisBasics` interfaces.
* `ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, genesis map[string]json.RawMessage)`: Validates the genesis information modules by calling the [`ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage)`](./08-genesis.md#validategenesis) function of modules implementing the `HasGenesisBasics` interface.
Here's an example of a concrete integration within an `simapp`:

View File

@ -84,7 +84,7 @@ The Cosmos SDK uses Protobuf definitions to generate client and server code:
A `RegisterMsgServer` method is also generated and should be used to register the module's `MsgServer` implementation in `RegisterServices` method from the [`AppModule` interface](./01-module-manager.md#appmodule).
In order for clients (CLI and grpc-gateway) to have these URLs registered, the Cosmos SDK provides the function `RegisterMsgServiceDesc(registry codectypes.InterfaceRegistry, sd *grpc.ServiceDesc)` that should be called inside module's [`RegisterInterfaces`](01-module-manager.md#appmodulebasic) method, using the proto-generated `&_Msg_serviceDesc` as `*grpc.ServiceDesc` argument.
In order for clients (CLI and grpc-gateway) to have these URLs registered, the Cosmos SDK provides the function `RegisterMsgServiceDesc(registry codectypes.InterfaceRegistry, sd *grpc.ServiceDesc)` that should be called inside module's [`RegisterInterfaces`](01-module-manager.md#hasregisterinterfaces) method, using the proto-generated `&_Msg_serviceDesc` as `*grpc.ServiceDesc` argument.
## Queries

View File

@ -64,84 +64,13 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/bank/module.go#L84-L
This section is being rewritten. Refer to [AutoCLI](https://docs.cosmos.network/main/core/autocli) while this section is being updated.
:::
<!-- UPDATE THIS TO AUTOCLI
[Queries](./02-messages-and-queries.md#queries) allow users to gather information about the application or network state; they are routed by the application and processed by the module in which they are defined. Query commands typically have their own `query.go` file in the module's `./client/cli` folder. Like transaction commands, they are specified in getter functions. Here is an example of a query command from the `x/auth` module:
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/auth/client/cli/query.go#L86-L128
```
In the example, `GetAccountCmd()` creates and returns a query command that returns the state of an account based on the provided account address.
In general, the getter function does the following:
* **Constructs the command:** Read the [Cobra Documentation](https://pkg.go.dev/github.com/spf13/cobra) for more detailed information on how to create commands.
* **Use:** Specifies the format of the user input required to invoke the command. In the example above, `account` is the name of the query command and `[address]` is the argument.
* **Args:** The number of arguments the user provides. In this case, there is exactly one: `[address]`.
* **Short and Long:** Descriptions for the command. A `Short` description is expected. A `Long` description can be used to provide additional information that is displayed when a user adds the `--help` flag.
* **RunE:** Defines a function that can return an error. This is the function that is called when the command is executed. This function encapsulates all of the logic to create a new query.
* The function typically starts by getting the `clientCtx`, which can be done with `client.GetClientQueryContext(cmd)`. The `clientCtx` contains information relevant to query handling.
* If applicable, the command's arguments are parsed. In this example, the argument `[address]` is parsed.
* A new `queryClient` is initialized using `NewQueryClient(clientCtx)`. The `queryClient` is then used to call the appropriate [query](./02-messages-and-queries.md#grpc-queries).
* The `clientCtx.PrintProto` method is used to format the `proto.Message` object so that the results can be printed back to the user.
* **Adds query flags:** All query commands must add a set of query [flags](#flags). The query flags are added to the constructed command using `AddQueryFlagsToCmd(cmd)`.
* **Returns the command:** Finally, the query command is returned.
Each module must implement `GetQueryCmd()`, which aggregates all of the query commands of the module. Here is an example from the `x/auth` module:
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/auth/client/cli/query.go#L33-L53
```
Each module must also implement the `GetQueryCmd()` method for `AppModuleBasic` that returns the `GetQueryCmd()` function. This allows for the root command to easily aggregate all of the query commands for each module. Here is an example:
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/bank/module.go#L84-L87
```
### Flags
[Flags](../../learn/advanced/07-cli.md#flags) allow users to customize commands. `--fees` and `--gas-prices` are examples of flags that allow users to set the [fees](../../learn/beginner/04-gas-fees.md) and gas prices for their transactions.
Flags that are specific to a module are typically created in a `flags.go` file in the module's `./client/cli` folder. When creating a flag, developers set the value type, the name of the flag, the default value, and a description about the flag. Developers also have the option to mark flags as _required_ so that an error is thrown if the user does not include a value for the flag.
Here is an example that adds the `--from` flag to a command:
```go
cmd.Flags().String(FlagFrom, "", "Name or address of private key with which to sign")
```
In this example, the value of the flag is a `String`, the name of the flag is `from` (the value of the `FlagFrom` constant), the default value of the flag is `""`, and there is a description that will be displayed when a user adds `--help` to the command.
Here is an example that marks the `--from` flag as _required_:
```go
cmd.MarkFlagRequired(FlagFrom)
```
For more detailed information on creating flags, visit the [Cobra Documentation](https://github.com/spf13/cobra).
As mentioned in [transaction commands](#transaction-commands), there is a set of flags that all transaction commands must add. This is done with the `AddTxFlagsToCmd` method defined in the Cosmos SDK's `./client/flags` package.
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/client/flags/flags.go#L108-L138
```
Since `AddTxFlagsToCmd(cmd *cobra.Command)` includes all of the basic flags required for a transaction command, module developers may choose not to add any of their own (specifying arguments instead may often be more appropriate).
Similarly, there is a `AddQueryFlagsToCmd(cmd *cobra.Command)` to add common flags to a module query command.
```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/client/flags/flags.go#L95-L106```
-->
## gRPC
[gRPC](https://grpc.io/) is a Remote Procedure Call (RPC) framework. RPC is the preferred way for external clients like wallets and exchanges to interact with a blockchain.
In addition to providing an ABCI query pathway, the Cosmos SDK provides a gRPC proxy server that routes gRPC query requests to ABCI query requests.
In order to do that, modules must implement `RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux)` on `AppModuleBasic` to wire the client gRPC requests to the correct handler inside the module.
In order to do that, modules must implement the `module.HasGRPCGateway` interface on `AppModule` to wire the client gRPC requests to the correct handler inside the module.
Here's an example from the `x/auth` module:

View File

@ -79,7 +79,7 @@ x/{module_name}
* `client/`: The module's CLI client functionality implementation and the module's CLI testing suite.
* `exported/`: The module's exported types - typically interface types. If a module relies on keepers from another module, it is expected to receive the keepers as interface contracts through the `expected_keepers.go` file (see below) in order to avoid a direct dependency on the module implementing the keepers. However, these interface contracts can define methods that operate on and/or return types that are specific to the module that is implementing the keepers and this is where `exported/` comes into play. The interface types that are defined in `exported/` use canonical types, allowing for the module to receive the keepers as interface contracts through the `expected_keepers.go` file. This pattern allows for code to remain DRY and also alleviates import cycle chaos.
* `keeper/`: The module's `Keeper` and `MsgServer` implementation.
* `module/`: The module's `AppModule` and `AppModuleBasic` implementation.
* `module/`: The module's `AppModule` implementation.
* `abci.go`: The module's `BeginBlocker` and `EndBlocker` implementations (this file is only required if `BeginBlocker` and/or `EndBlocker` need to be defined).
* `autocli.go`: The module [autocli](https://docs.cosmos.network/main/core/autocli) options.
* `simulation/`: The module's [simulation](./14-simulator.md) package defines functions used by the blockchain simulator application (`simapp`).

View File

@ -55,7 +55,7 @@ The first thing defined in `app.go` is the `type` of the application. It is gene
* **A list of module's `keeper`s.** Each module defines an abstraction called [`keeper`](../../build/building-modules/06-keeper.md), which handles reads and writes for this module's store(s). The `keeper`'s methods of one module can be called from other modules (if authorized), which is why they are declared in the application's type and exported as interfaces to other modules so that the latter can only access the authorized functions.
* **A reference to an [`appCodec`](../advanced/05-encoding.md).** The application's `appCodec` is used to serialize and deserialize data structures in order to store them, as stores can only persist `[]bytes`. The default codec is [Protocol Buffers](../advanced/05-encoding.md).
* **A reference to a [`legacyAmino`](../advanced/05-encoding.md) codec.** Some parts of the Cosmos SDK have not been migrated to use the `appCodec` above, and are still hardcoded to use Amino. Other parts explicitly use Amino for backwards compatibility. For these reasons, the application still holds a reference to the legacy Amino codec. Please note that the Amino codec will be removed from the SDK in the upcoming releases.
* **A reference to a [module manager](../../build/building-modules/01-module-manager.md#manager)** and a [basic module manager](../../build/building-modules/01-module-manager.md#basicmanager). The module manager is an object that contains a list of the application's modules. It facilitates operations related to these modules, like registering their [`Msg` service](../advanced/00-baseapp.md#msg-services) and [gRPC `Query` service](../advanced/00-baseapp.md#grpc-query-services), or setting the order of execution between modules for various functions like [`InitChainer`](#initchainer), [`PreBlocker`](#preblocker) and [`BeginBlocker` and `EndBlocker`](#beginblocker-and-endblocker).
* **A reference to a [module manager](../../build/building-modules/01-module-manager.md#manager)**. The module manager is an object that contains a list of the application's modules. It facilitates operations related to these modules, like registering their [`Msg` service](../advanced/00-baseapp.md#msg-services) and [gRPC `Query` service](../advanced/00-baseapp.md#grpc-query-services), or setting the order of execution between modules for various functions like [`InitChainer`](#initchainer), [`PreBlocker`](#preblocker) and [`BeginBlocker` and `EndBlocker`](#beginblocker-and-endblocker).
See an example of application type definition from `simapp`, the Cosmos SDK's own app used for demo and testing purposes:
@ -73,7 +73,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/server/types/app.go#L6
Here are the main actions performed by this function:
* Instantiate a new [`codec`](../advanced/05-encoding.md) and initialize the `codec` of each of the application's modules using the [basic manager](../../build/building-modules/01-module-manager.md#basicmanager).
* Instantiate a new [`codec`](../advanced/05-encoding.md) and initialize the `codec` of each of the application's modules using the module manager.
* Instantiate a new application with a reference to a `baseapp` instance, a codec, and all the appropriate store keys.
* Instantiate all the [`keeper`](#keeper) objects defined in the application's `type` using the `NewKeeper` function of each of the application's modules. Note that keepers must be instantiated in the correct order, as the `NewKeeper` of one module might require a reference to another module's `keeper`.
* Instantiate the application's [module manager](../../build/building-modules/01-module-manager.md#manager) with the [`AppModule`](#application-module-interface) object of each of the application's modules.
@ -165,7 +165,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/params/encoding
### Application Module Interface
Modules must implement [interfaces](../../build/building-modules/01-module-manager.md#application-module-interfaces) defined in the Cosmos SDK, [`AppModuleBasic`](../../build/building-modules/01-module-manager.md#appmodulebasic) and [`AppModule`](../../build/building-modules/01-module-manager.md#appmodule). The former implements basic non-dependent elements of the module, such as the `codec`, while the latter handles the bulk of the module methods (including methods that require references to other modules' `keeper`s). Both the `AppModule` and `AppModuleBasic` types are, by convention, defined in a file called `module.go`.
Modules must implement [interfaces](../../build/building-modules/01-module-manager.md#application-module-interfaces) defined in the Cosmos SDK and [`AppModule`](../../build/building-modules/01-module-manager.md#appmodule). `AppModule` handles the bulk of the module methods (including methods that require references to other modules' `keeper`s). `AppModule` is, by convention, defined in a file called `module.go`.
`AppModule` exposes a collection of useful methods on the module that facilitates the composition of modules into a coherent application. These methods are called from the [`module manager`](../../build/building-modules/01-module-manager.md#manager), which manages the application's collection of modules.
@ -235,7 +235,7 @@ Generally, the [commands related to a module](../../build/building-modules/09-mo
Each module can expose gRPC endpoints called [service methods](https://grpc.io/docs/what-is-grpc/core-concepts/#service-definition), which are defined in the [module's Protobuf `query.proto` file](#grpc-query-services). A service method is defined by its name, input arguments, and output response. The module then needs to perform the following actions:
* Define a `RegisterGRPCGatewayRoutes` method on `AppModuleBasic` to wire the client gRPC requests to the correct handler inside the module.
* (Optional) Define a `RegisterGRPCGatewayRoutes` method on `AppModule` to wire the client gRPC requests to the correct handler inside the module.
* For each service method, define a corresponding handler. The handler implements the core logic necessary to serve the gRPC request, and is located in the `keeper/grpc_query.go` file.
#### gRPC-gateway REST Endpoints

View File

@ -47,7 +47,6 @@ type App struct {
interfaceRegistry codectypes.InterfaceRegistry
cdc codec.Codec
amino *codec.LegacyAmino
basicManager module.BasicManager
baseAppOptions []BaseAppOption
msgServiceRouter *baseapp.MsgServiceRouter
appConfig *appv1alpha1.Config
@ -67,14 +66,12 @@ func (a *App) RegisterModules(modules ...module.AppModule) error {
return fmt.Errorf("AppModule named %q already exists", name)
}
if _, ok := a.basicManager[name]; ok {
return fmt.Errorf("AppModuleBasic named %q already exists", name)
}
a.ModuleManager.Modules[name] = appModule
a.basicManager[name] = appModule
appModule.RegisterInterfaces(a.interfaceRegistry)
appModule.RegisterLegacyAminoCodec(a.amino)
if mod, ok := appModule.(module.HasAminoCodec); ok {
mod.RegisterLegacyAminoCodec(a.amino)
}
if mod, ok := appModule.(module.HasServices); ok {
mod.RegisterServices(a.configurator)
@ -208,7 +205,7 @@ func (a *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register grpc-gateway routes for all modules.
a.basicManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
a.ModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
}
// RegisterTxService implements the Application.RegisterTxService method.
@ -242,9 +239,9 @@ func (a *App) LoadHeight(height int64) error {
return a.LoadVersion(height)
}
// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
// DefaultGenesis returns a default genesis from the registered AppModule's.
func (a *App) DefaultGenesis() map[string]json.RawMessage {
return a.basicManager.DefaultGenesis(a.cdc)
return a.ModuleManager.DefaultGenesis(a.cdc)
}
// GetStoreKeys returns all the stored store keys.

View File

@ -18,7 +18,7 @@ type AppBuilder struct {
app *App
}
// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
// DefaultGenesis returns a default genesis from the registered modules.
func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage {
return a.app.DefaultGenesis()
}

View File

@ -14,7 +14,6 @@ import (
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
"cosmossdk.io/core/genesis"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject"
@ -70,8 +69,7 @@ func init() {
ProvideEnvironment,
ProvideMemoryStoreService,
ProvideTransientStoreService,
ProvideEventService,
ProvideBasicManager,
ProvideModuleManager,
ProvideAppVersionModifier,
ProvideAddressCodec,
),
@ -111,7 +109,6 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) (
interfaceRegistry: interfaceRegistry,
cdc: cdc,
amino: amino,
basicManager: module.BasicManager{},
msgServiceRouter: msgServiceRouter,
}
appBuilder := &AppBuilder{app}
@ -122,15 +119,14 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) (
type AppInputs struct {
depinject.In
AppConfig *appv1alpha1.Config
Config *runtimev1alpha1.Module
AppBuilder *AppBuilder
Modules map[string]appmodule.AppModule
CustomModuleBasics map[string]module.AppModuleBasic `optional:"true"`
BaseAppOptions []BaseAppOption
InterfaceRegistry codectypes.InterfaceRegistry
LegacyAmino *codec.LegacyAmino
Logger log.Logger
Logger log.Logger
AppConfig *appv1alpha1.Config
Config *runtimev1alpha1.Module
AppBuilder *AppBuilder
ModuleManager *module.Manager
BaseAppOptions []BaseAppOption
InterfaceRegistry codectypes.InterfaceRegistry
LegacyAmino *codec.LegacyAmino
}
func SetupAppBuilder(inputs AppInputs) {
@ -139,21 +135,9 @@ func SetupAppBuilder(inputs AppInputs) {
app.config = inputs.Config
app.appConfig = inputs.AppConfig
app.logger = inputs.Logger
app.ModuleManager = module.NewManagerFromMap(inputs.Modules)
for name, mod := range inputs.Modules {
if customBasicMod, ok := inputs.CustomModuleBasics[name]; ok {
app.basicManager[name] = customBasicMod
customBasicMod.RegisterInterfaces(inputs.InterfaceRegistry)
customBasicMod.RegisterLegacyAminoCodec(inputs.LegacyAmino)
continue
}
coreAppModuleBasic := module.CoreAppModuleBasicAdaptor(name, mod)
app.basicManager[name] = coreAppModuleBasic
coreAppModuleBasic.RegisterInterfaces(inputs.InterfaceRegistry)
coreAppModuleBasic.RegisterLegacyAminoCodec(inputs.LegacyAmino)
}
app.ModuleManager = inputs.ModuleManager
app.ModuleManager.RegisterInterfaces(inputs.InterfaceRegistry)
app.ModuleManager.RegisterLegacyAminoCodec(inputs.LegacyAmino)
}
func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec ValidatorAddressCodec, customGetSigners []signing.CustomGetSigner) (codectypes.InterfaceRegistry, error) {
@ -220,6 +204,10 @@ func ProvideMemoryStoreKey(key depinject.ModuleKey, app *AppBuilder) *storetypes
return storeKey
}
func ProvideModuleManager(modules map[string]appmodule.AppModule) *module.Manager {
return module.NewManagerFromMap(modules)
}
func ProvideGenesisTxHandler(appBuilder *AppBuilder) genesis.TxHandler {
return appBuilder.app
}
@ -240,14 +228,6 @@ func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) stor
return transientStoreService{key: storeKey}
}
func ProvideEventService() event.Service {
return EventService{}
}
func ProvideBasicManager(app *AppBuilder) module.BasicManager {
return app.app.basicManager
}
func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier {
return app.app
}

View File

@ -458,7 +458,7 @@ func TestEmptyMinGasPrices(t *testing.T) {
serverCtx.Config.SetRoot(tempDir)
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
cmd := genutilcli.InitCmd(module.NewBasicManager())
cmd := genutilcli.InitCmd(module.NewManager())
cmd.SetArgs([]string{"appnode-test"})
err = cmd.ExecuteContext(ctx)
require.NoError(t, err)

View File

@ -56,7 +56,6 @@ import (
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
feegrantmodule "cosmossdk.io/x/feegrant/module"
"cosmossdk.io/x/gov"
govclient "cosmossdk.io/x/gov/client"
govkeeper "cosmossdk.io/x/gov/keeper"
govtypes "cosmossdk.io/x/gov/types"
govv1beta1 "cosmossdk.io/x/gov/types/v1beta1"
@ -168,14 +167,10 @@ type SimApp struct {
CircuitKeeper circuitkeeper.Keeper
PoolKeeper poolkeeper.Keeper
// the module manager
// managers
ModuleManager *module.Manager
BasicModuleManager module.BasicManager
UnorderedTxManager *unorderedtx.Manager
// simulation manager
sm *module.SimulationManager
sm *module.SimulationManager
// module configurator
configurator module.Configurator // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1.
@ -414,10 +409,7 @@ func NewSimApp(
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.ModuleManager = module.NewManager(
genutil.NewAppModule(
app.AuthKeeper, app.StakingKeeper, app,
txConfig,
),
genutil.NewAppModule(app.AuthKeeper, app.StakingKeeper, app, txConfig, genutiltypes.DefaultMessageValidator),
accounts.NewAppModule(app.AccountsKeeper),
auth.NewAppModule(appCodec, app.AuthKeeper, authsims.RandomGenesisAccounts),
vesting.NewAppModule(app.AuthKeeper, app.BankKeeper),
@ -428,7 +420,7 @@ func NewSimApp(
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.interfaceRegistry),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AuthKeeper, app.BankKeeper),
upgrade.NewAppModule(app.UpgradeKeeper, app.AuthKeeper.AddressCodec()),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry),
@ -437,21 +429,8 @@ func NewSimApp(
circuit.NewAppModule(appCodec, app.CircuitKeeper),
protocolpool.NewAppModule(appCodec, app.PoolKeeper, app.AuthKeeper, app.BankKeeper),
)
// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration and genesis verification.
// By default it is composed of all the module from the module manager.
// Additionally, app module basics can be overwritten by passing them as argument.
app.BasicModuleManager = module.NewBasicManagerFromManager(
app.ModuleManager,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{},
),
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
app.ModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.ModuleManager.RegisterInterfaces(interfaceRegistry)
// NOTE: upgrade module is required to be prioritized
app.ModuleManager.SetOrderPreBlockers(
@ -718,9 +697,9 @@ func (app *SimApp) AutoCliOpts() autocli.AppOptions {
}
}
// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
// DefaultGenesis returns a default genesis from the registered AppModule's.
func (a *SimApp) DefaultGenesis() map[string]json.RawMessage {
return a.BasicModuleManager.DefaultGenesis(a.appCodec)
return a.ModuleManager.DefaultGenesis(a.appCodec)
}
// GetKey returns the KVStoreKey for the provided store key.
@ -759,7 +738,7 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register grpc-gateway routes for all modules.
app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
app.ModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// register swagger API from root so that other applications can override easily
if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {

View File

@ -44,6 +44,7 @@ import (
evidencetypes "cosmossdk.io/x/evidence/types"
"cosmossdk.io/x/feegrant"
_ "cosmossdk.io/x/feegrant/module" // import for side-effects
_ "cosmossdk.io/x/gov" // import for side-effects
govtypes "cosmossdk.io/x/gov/types"
"cosmossdk.io/x/group"
_ "cosmossdk.io/x/group/module" // import for side-effects

View File

@ -26,10 +26,7 @@ import (
distrkeeper "cosmossdk.io/x/distribution/keeper"
evidencekeeper "cosmossdk.io/x/evidence/keeper"
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
"cosmossdk.io/x/gov"
govclient "cosmossdk.io/x/gov/client"
govkeeper "cosmossdk.io/x/gov/keeper"
govtypes "cosmossdk.io/x/gov/types"
groupkeeper "cosmossdk.io/x/group/keeper"
mintkeeper "cosmossdk.io/x/mint/keeper"
nftkeeper "cosmossdk.io/x/nft/keeper"
@ -52,8 +49,6 @@ import (
testdata_pulsar "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb"
"github.com/cosmos/cosmos-sdk/types/module"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
// DefaultNodeHome default home directories for the application daemon
@ -110,17 +105,7 @@ func init() {
// AppConfig returns the default app config.
func AppConfig() depinject.Config {
return depinject.Configs(
// appconfig.LoadYAML(AppConfigYAML),
appConfig,
depinject.Supply(
// supply custom module basics
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{},
),
},
),
appConfig, // Alternatively use appconfig.LoadYAML(AppConfigYAML)
)
}

View File

@ -9,6 +9,6 @@ import (
// The identifier is used to determine which module genesis information belongs
// to so it may be appropriately routed during init chain.
// Within this application default genesis information is retrieved from
// the ModuleBasicManager which populates json from each BasicModule
// the module manager which populates json from each module
// object provided to it during init.
type GenesisState map[string]json.RawMessage

View File

@ -37,14 +37,14 @@ func initRootCmd(
txConfig client.TxConfig,
interfaceRegistry codectypes.InterfaceRegistry,
appCodec codec.Codec,
basicManager module.BasicManager,
moduleManager *module.Manager,
) {
cfg := sdk.GetConfig()
cfg.Seal()
rootCmd.AddCommand(
genutilcli.InitCmd(basicManager),
NewTestnetCmd(basicManager, banktypes.GenesisBalancesIterator{}),
genutilcli.InitCmd(moduleManager),
NewTestnetCmd(moduleManager, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
confixcmd.ConfigCommand(),
pruning.Cmd(newApp),
@ -56,7 +56,7 @@ func initRootCmd(
// add keybase, auxiliary RPC, query, genesis, and tx child commands
rootCmd.AddCommand(
server.StatusCommand(),
genesisCommand(txConfig, basicManager, appExport),
genesisCommand(txConfig, moduleManager, appExport),
queryCommand(),
txCommand(),
keys.Commands(),
@ -65,8 +65,8 @@ func initRootCmd(
}
// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter
func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, appExport servertypes.AppExporter, cmds ...*cobra.Command) *cobra.Command {
cmd := genutilcli.Commands(txConfig, basicManager, appExport)
func genesisCommand(txConfig client.TxConfig, moduleManager *module.Manager, appExport servertypes.AppExporter, cmds ...*cobra.Command) *cobra.Command {
cmd := genutilcli.Commands(txConfig, moduleManager, appExport)
for _, subCmd := range cmds {
cmd.AddCommand(subCmd)

View File

@ -103,7 +103,7 @@ func NewRootCmd() *cobra.Command {
},
}
initRootCmd(rootCmd, encodingConfig.TxConfig, encodingConfig.InterfaceRegistry, encodingConfig.Codec, tempApp.BasicModuleManager)
initRootCmd(rootCmd, encodingConfig.TxConfig, encodingConfig.InterfaceRegistry, encodingConfig.Codec, tempApp.ModuleManager)
// autocli opts
customClientTemplate, customClientConfig := initClientConfig()

View File

@ -31,9 +31,9 @@ import (
// NewRootCmd creates a new root command for simd. It is called once in the main function.
func NewRootCmd() *cobra.Command {
var (
autoCliOpts autocli.AppOptions
moduleBasicManager module.BasicManager
clientCtx client.Context
autoCliOpts autocli.AppOptions
moduleManager *module.Manager
clientCtx client.Context
)
if err := depinject.Inject(
@ -48,7 +48,7 @@ func NewRootCmd() *cobra.Command {
),
),
&autoCliOpts,
&moduleBasicManager,
&moduleManager,
&clientCtx,
); err != nil {
panic(err)
@ -86,7 +86,7 @@ func NewRootCmd() *cobra.Command {
},
}
initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleBasicManager)
initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleManager)
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)

View File

@ -96,7 +96,7 @@ func addTestnetFlagsToCmd(cmd *cobra.Command) {
// NewTestnetCmd creates a root testnet command with subcommands to run an in-process testnet or initialize
// validator configuration files for running a multi-validator testnet in a separate process
func NewTestnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
func NewTestnetCmd(mm *module.Manager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
testnetCmd := &cobra.Command{
Use: "testnet",
Short: "subcommands for starting or configuring local testnets",
@ -106,13 +106,13 @@ func NewTestnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBala
}
testnetCmd.AddCommand(testnetStartCmd())
testnetCmd.AddCommand(testnetInitFilesCmd(mbm, genBalIterator))
testnetCmd.AddCommand(testnetInitFilesCmd(mm, genBalIterator))
return testnetCmd
}
// testnetInitFilesCmd returns a cmd to initialize all files for CometBFT testnet and application
func testnetInitFilesCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
func testnetInitFilesCmd(mm *module.Manager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
cmd := &cobra.Command{
Use: "init-files",
Short: "Initialize config directories & files for a multi-validator testnet running locally via separate processes (e.g. Docker Compose or similar)",
@ -148,7 +148,7 @@ Example:
args.numValidators, _ = cmd.Flags().GetInt(flagNumValidators)
args.algo, _ = cmd.Flags().GetString(flags.FlagKeyType)
return initTestnetFiles(clientCtx, cmd, config, mbm, genBalIterator, clientCtx.TxConfig.SigningContext().ValidatorAddressCodec(), args)
return initTestnetFiles(clientCtx, cmd, config, mm, genBalIterator, clientCtx.TxConfig.SigningContext().ValidatorAddressCodec(), args)
},
}
@ -207,7 +207,7 @@ func initTestnetFiles(
clientCtx client.Context,
cmd *cobra.Command,
nodeConfig *cmtconfig.Config,
mbm module.BasicManager,
mm *module.Manager,
genBalIterator banktypes.GenesisBalancesIterator,
valAddrCodec runtime.ValidatorAddressCodec,
args initArgs,
@ -354,7 +354,7 @@ func initTestnetFiles(
}
}
if err := initGenFiles(clientCtx, mbm, args.chainID, genAccounts, genBalances, genFiles, args.numValidators); err != nil {
if err := initGenFiles(clientCtx, mm, args.chainID, genAccounts, genBalances, genFiles, args.numValidators); err != nil {
return err
}
@ -371,11 +371,11 @@ func initTestnetFiles(
}
func initGenFiles(
clientCtx client.Context, mbm module.BasicManager, chainID string,
clientCtx client.Context, mm *module.Manager, chainID string,
genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance,
genFiles []string, numValidators int,
) error {
appGenState := mbm.DefaultGenesis(clientCtx.Codec)
appGenState := mm.DefaultGenesis(clientCtx.Codec)
// set the accounts in the genesis state
var authGenState authtypes.GenesisState

View File

@ -8,43 +8,50 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
"cosmossdk.io/x/auth"
"cosmossdk.io/x/bank"
banktypes "cosmossdk.io/x/bank/types"
"cosmossdk.io/x/distribution"
"cosmossdk.io/x/mint"
"cosmossdk.io/x/staking"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/types/module"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
func Test_TestnetCmd(t *testing.T) {
moduleBasic := module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distribution.AppModuleBasic{},
consensus.AppModuleBasic{},
config := configurator.NewAppConfig(
configurator.AuthModule(),
configurator.BankModule(),
configurator.GenutilModule(),
configurator.StakingModule(),
configurator.ConsensusModule(),
configurator.TxModule(),
configurator.MintModule(),
)
var moduleManager *module.Manager
err := depinject.Inject(
depinject.Configs(config,
depinject.Supply(log.NewNopLogger()),
),
&moduleManager,
)
require.NoError(t, err)
require.NotNil(t, moduleManager)
require.Len(t, moduleManager.Modules, 7)
home := t.TempDir()
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, staking.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{})
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultCometConfig(home)
require.NoError(t, err)
err = genutiltest.ExecInitCmd(moduleBasic, home, encodingConfig.Codec)
err = genutiltest.ExecInitCmd(moduleManager, home, encodingConfig.Codec)
require.NoError(t, err)
serverCtx := server.NewContext(viper.New(), cfg, logger)
@ -56,7 +63,7 @@ func Test_TestnetCmd(t *testing.T) {
ctx := context.Background()
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
cmd := testnetInitFilesCmd(moduleBasic, banktypes.GenesisBalancesIterator{})
cmd := testnetInitFilesCmd(moduleManager, banktypes.GenesisBalancesIterator{})
cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)})
err = cmd.ExecuteContext(ctx)
require.NoError(t, err)

View File

@ -56,7 +56,7 @@ func TestCLITestSuite(t *testing.T) {
}
func (s *CLITestSuite) SetupSuite() {
s.encCfg = testutilmod.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, gov.AppModuleBasic{})
s.encCfg = testutilmod.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{})
s.kr = keyring.NewInMemory(s.encCfg.Codec)
s.baseCtx = client.Context{}.
WithKeyring(s.kr).

View File

@ -63,7 +63,7 @@ type deterministicFixture struct {
func initDeterministicFixture(t *testing.T) *deterministicFixture {
t.Helper()
keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}).Codec
logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

View File

@ -66,7 +66,7 @@ func initFixture(t *testing.T) *fixture {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, pooltypes.StoreKey, stakingtypes.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, distribution.AppModuleBasic{}, protocolpool.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}, protocolpool.AppModule{}).Codec
logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

View File

@ -87,7 +87,7 @@ func initFixture(tb testing.TB) *fixture {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, consensusparamtypes.StoreKey, evidencetypes.StoreKey, stakingtypes.StoreKey, slashingtypes.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, evidence.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, evidence.AppModule{}).Codec
logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

View File

@ -29,7 +29,7 @@ import (
func Example() {
// in this example we are testing the integration of the following modules:
// - mint, which directly depends on auth, bank and staking
encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, mint.AppModuleBasic{})
encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, mint.AppModule{})
keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, minttypes.StoreKey)
authority := authtypes.NewModuleAddress("gov").String()
@ -118,7 +118,7 @@ func Example() {
// That module has no dependency on other modules.
func Example_oneModule() {
// in this example we are testing the integration of the auth module:
encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
keys := storetypes.NewKVStoreKeys(authtypes.StoreKey)
authority := authtypes.NewModuleAddress("gov").String()

View File

@ -52,7 +52,7 @@ func initFixture(tb testing.TB) *fixture {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, pooltypes.StoreKey, types.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, gov.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{}).Codec
logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

View File

@ -56,7 +56,7 @@ func initFixture(tb testing.TB) *fixture {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}).Codec
logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

View File

@ -103,7 +103,7 @@ func initFixture(tb testing.TB) *fixture {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, types.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, staking.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{}).Codec
logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

View File

@ -68,7 +68,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, distribution.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}).Codec
logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

View File

@ -92,10 +92,10 @@ import (
// by the mutation of genOpts passed to the generator.
func TestAminoJSON_Equivalence(t *testing.T) {
encCfg := testutil.MakeTestEncodingConfig(
auth.AppModuleBasic{}, authzmodule.AppModuleBasic{}, bank.AppModuleBasic{}, consensus.AppModuleBasic{},
distribution.AppModuleBasic{}, evidence.AppModuleBasic{}, feegrantmodule.AppModuleBasic{},
gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{},
slashing.AppModuleBasic{}, staking.AppModuleBasic{}, upgrade.AppModuleBasic{}, vesting.AppModuleBasic{})
auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, consensus.AppModule{},
distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{},
gov.AppModule{}, groupmodule.AppModule{}, mint.AppModule{},
slashing.AppModule{}, staking.AppModule{}, upgrade.AppModule{}, vesting.AppModule{})
legacytx.RegressionTestingAminoCodec = encCfg.Amino
aj := aminojson.NewEncoder(aminojson.EncoderOptions{DoNotSortFields: true})
@ -208,9 +208,9 @@ func newAny(t *testing.T, msg proto.Message) *anypb.Any {
// TestAminoJSON_LegacyParity tests that the Encoder encoder produces the same output as the Encoder encoder.
func TestAminoJSON_LegacyParity(t *testing.T) {
encCfg := testutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, authzmodule.AppModuleBasic{},
bank.AppModuleBasic{}, distribution.AppModuleBasic{}, slashing.AppModuleBasic{}, staking.AppModuleBasic{},
vesting.AppModuleBasic{}, gov.AppModuleBasic{})
encCfg := testutil.MakeTestEncodingConfig(auth.AppModule{}, authzmodule.AppModule{},
bank.AppModule{}, distribution.AppModule{}, slashing.AppModule{}, staking.AppModule{},
vesting.AppModule{}, gov.AppModule{})
legacytx.RegressionTestingAminoCodec = encCfg.Amino
aj := aminojson.NewEncoder(aminojson.EncoderOptions{DoNotSortFields: true})
@ -512,8 +512,8 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
}
func TestSendAuthorization(t *testing.T) {
encCfg := testutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, authzmodule.AppModuleBasic{},
distribution.AppModuleBasic{}, bank.AppModuleBasic{})
encCfg := testutil.MakeTestEncodingConfig(auth.AppModule{}, authzmodule.AppModule{},
distribution.AppModule{}, bank.AppModule{})
aj := aminojson.NewEncoder(aminojson.EncoderOptions{})
@ -562,7 +562,7 @@ func TestSendAuthorization(t *testing.T) {
}
func TestDecimalMutation(t *testing.T) {
encCfg := testutil.MakeTestEncodingConfig(staking.AppModuleBasic{})
encCfg := testutil.MakeTestEncodingConfig(staking.AppModule{})
rates := &stakingtypes.CommissionRates{}
rateBz, _ := encCfg.Amino.MarshalJSON(rates)
require.Equal(t, `{"rate":"0","max_rate":"0","max_change_rate":"0"}`, string(rateBz))

View File

@ -43,10 +43,10 @@ import (
// TestDecode tests that the tx decoder can decode all the txs in the test suite.
func TestDecode(t *testing.T) {
encCfg := testutil.MakeTestEncodingConfig(
auth.AppModuleBasic{}, authzmodule.AppModuleBasic{}, bank.AppModuleBasic{}, consensus.AppModuleBasic{},
distribution.AppModuleBasic{}, evidence.AppModuleBasic{}, feegrantmodule.AppModuleBasic{},
gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{},
slashing.AppModuleBasic{}, staking.AppModuleBasic{}, upgrade.AppModuleBasic{}, vesting.AppModuleBasic{})
auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, consensus.AppModule{},
distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{},
gov.AppModule{}, groupmodule.AppModule{}, mint.AppModule{},
slashing.AppModule{}, staking.AppModule{}, upgrade.AppModule{}, vesting.AppModule{})
legacytx.RegressionTestingAminoCodec = encCfg.Amino
fee := sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100)))

View File

@ -52,8 +52,7 @@ func NewIntegrationApp(
interfaceRegistry := codectypes.NewInterfaceRegistry()
moduleManager := module.NewManagerFromMap(modules)
basicModuleManager := module.NewBasicManagerFromManager(moduleManager, nil)
basicModuleManager.RegisterInterfaces(interfaceRegistry)
moduleManager.RegisterInterfaces(interfaceRegistry)
txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes)
bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName))

View File

@ -17,7 +17,6 @@ import (
types1 "github.com/cosmos/cosmos-sdk/types"
module "github.com/cosmos/cosmos-sdk/types/module"
gomock "github.com/golang/mock/gomock"
runtime "github.com/grpc-ecosystem/grpc-gateway/runtime"
)
// MockAppModuleWithAllExtensions is a mock of AppModuleWithAllExtensions interface.
@ -150,18 +149,6 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) Name() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockAppModuleWithAllExtensions) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// RegisterInterfaces mocks base method.
func (m *MockAppModuleWithAllExtensions) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
@ -186,18 +173,6 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterInvariants(arg0 in
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterInvariants), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockAppModuleWithAllExtensions) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterLegacyAminoCodec), arg0)
}
// RegisterServices mocks base method.
func (m *MockAppModuleWithAllExtensions) RegisterServices(arg0 module.Configurator) {
m.ctrl.T.Helper()
@ -356,18 +331,6 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) Name() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAppModuleWithAllExtensionsABCI)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockAppModuleWithAllExtensionsABCI) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModuleWithAllExtensionsABCI)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// RegisterInterfaces mocks base method.
func (m *MockAppModuleWithAllExtensionsABCI) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
@ -392,18 +355,6 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) RegisterInvariants(arg
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockAppModuleWithAllExtensionsABCI)(nil).RegisterInvariants), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockAppModuleWithAllExtensionsABCI) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModuleWithAllExtensionsABCI)(nil).RegisterLegacyAminoCodec), arg0)
}
// RegisterServices mocks base method.
func (m *MockAppModuleWithAllExtensionsABCI) RegisterServices(arg0 module.Configurator) {
m.ctrl.T.Helper()

View File

@ -19,31 +19,55 @@ import (
runtime "github.com/grpc-ecosystem/grpc-gateway/runtime"
)
// MockAppModuleBasic is a mock of AppModuleBasic interface.
type MockAppModuleBasic struct {
// MockAppModule is a mock of AppModule interface.
type MockAppModule struct {
ctrl *gomock.Controller
recorder *MockAppModuleBasicMockRecorder
recorder *MockAppModuleMockRecorder
}
// MockAppModuleBasicMockRecorder is the mock recorder for MockAppModuleBasic.
type MockAppModuleBasicMockRecorder struct {
mock *MockAppModuleBasic
// MockAppModuleMockRecorder is the mock recorder for MockAppModule.
type MockAppModuleMockRecorder struct {
mock *MockAppModule
}
// NewMockAppModuleBasic creates a new mock instance.
func NewMockAppModuleBasic(ctrl *gomock.Controller) *MockAppModuleBasic {
mock := &MockAppModuleBasic{ctrl: ctrl}
mock.recorder = &MockAppModuleBasicMockRecorder{mock}
// NewMockAppModule creates a new mock instance.
func NewMockAppModule(ctrl *gomock.Controller) *MockAppModule {
mock := &MockAppModule{ctrl: ctrl}
mock.recorder = &MockAppModuleMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockAppModuleBasic) EXPECT() *MockAppModuleBasicMockRecorder {
func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder {
return m.recorder
}
// IsAppModule mocks base method.
func (m *MockAppModule) IsAppModule() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IsAppModule")
}
// IsAppModule indicates an expected call of IsAppModule.
func (mr *MockAppModuleMockRecorder) IsAppModule() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockAppModule)(nil).IsAppModule))
}
// IsOnePerModuleType mocks base method.
func (m *MockAppModule) IsOnePerModuleType() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IsOnePerModuleType")
}
// IsOnePerModuleType indicates an expected call of IsOnePerModuleType.
func (mr *MockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockAppModule)(nil).IsOnePerModuleType))
}
// Name mocks base method.
func (m *MockAppModuleBasic) Name() string {
func (m *MockAppModule) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
@ -51,45 +75,21 @@ func (m *MockAppModuleBasic) Name() string {
}
// Name indicates an expected call of Name.
func (mr *MockAppModuleBasicMockRecorder) Name() *gomock.Call {
func (mr *MockAppModuleMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAppModuleBasic)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockAppModuleBasic) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockAppModuleBasicMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAppModule)(nil).Name))
}
// RegisterInterfaces mocks base method.
func (m *MockAppModuleBasic) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
func (m *MockAppModule) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterInterfaces", arg0)
}
// RegisterInterfaces indicates an expected call of RegisterInterfaces.
func (mr *MockAppModuleBasicMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call {
func (mr *MockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterInterfaces), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockAppModuleBasic) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockAppModuleBasicMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterLegacyAminoCodec), arg0)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModule)(nil).RegisterInterfaces), arg0)
}
// MockHasName is a mock of HasName interface.
@ -166,6 +166,20 @@ func (mr *MockHasGenesisBasicsMockRecorder) DefaultGenesis(arg0 interface{}) *go
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockHasGenesisBasics)(nil).DefaultGenesis), arg0)
}
// Name mocks base method.
func (m *MockHasGenesisBasics) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockHasGenesisBasicsMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasGenesisBasics)(nil).Name))
}
// ValidateGenesis mocks base method.
func (m *MockHasGenesisBasics) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
@ -180,6 +194,111 @@ func (mr *MockHasGenesisBasicsMockRecorder) ValidateGenesis(arg0, arg1, arg2 int
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockHasGenesisBasics)(nil).ValidateGenesis), arg0, arg1, arg2)
}
// MockHasAminoCodec is a mock of HasAminoCodec interface.
type MockHasAminoCodec struct {
ctrl *gomock.Controller
recorder *MockHasAminoCodecMockRecorder
}
// MockHasAminoCodecMockRecorder is the mock recorder for MockHasAminoCodec.
type MockHasAminoCodecMockRecorder struct {
mock *MockHasAminoCodec
}
// NewMockHasAminoCodec creates a new mock instance.
func NewMockHasAminoCodec(ctrl *gomock.Controller) *MockHasAminoCodec {
mock := &MockHasAminoCodec{ctrl: ctrl}
mock.recorder = &MockHasAminoCodecMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockHasAminoCodec) EXPECT() *MockHasAminoCodecMockRecorder {
return m.recorder
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockHasAminoCodec) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockHasAminoCodecMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockHasAminoCodec)(nil).RegisterLegacyAminoCodec), arg0)
}
// MockHasRegisterInterfaces is a mock of HasRegisterInterfaces interface.
type MockHasRegisterInterfaces struct {
ctrl *gomock.Controller
recorder *MockHasRegisterInterfacesMockRecorder
}
// MockHasRegisterInterfacesMockRecorder is the mock recorder for MockHasRegisterInterfaces.
type MockHasRegisterInterfacesMockRecorder struct {
mock *MockHasRegisterInterfaces
}
// NewMockHasRegisterInterfaces creates a new mock instance.
func NewMockHasRegisterInterfaces(ctrl *gomock.Controller) *MockHasRegisterInterfaces {
mock := &MockHasRegisterInterfaces{ctrl: ctrl}
mock.recorder = &MockHasRegisterInterfacesMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockHasRegisterInterfaces) EXPECT() *MockHasRegisterInterfacesMockRecorder {
return m.recorder
}
// RegisterInterfaces mocks base method.
func (m *MockHasRegisterInterfaces) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterInterfaces", arg0)
}
// RegisterInterfaces indicates an expected call of RegisterInterfaces.
func (mr *MockHasRegisterInterfacesMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockHasRegisterInterfaces)(nil).RegisterInterfaces), arg0)
}
// MockHasGRPCGateway is a mock of HasGRPCGateway interface.
type MockHasGRPCGateway struct {
ctrl *gomock.Controller
recorder *MockHasGRPCGatewayMockRecorder
}
// MockHasGRPCGatewayMockRecorder is the mock recorder for MockHasGRPCGateway.
type MockHasGRPCGatewayMockRecorder struct {
mock *MockHasGRPCGateway
}
// NewMockHasGRPCGateway creates a new mock instance.
func NewMockHasGRPCGateway(ctrl *gomock.Controller) *MockHasGRPCGateway {
mock := &MockHasGRPCGateway{ctrl: ctrl}
mock.recorder = &MockHasGRPCGatewayMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockHasGRPCGateway) EXPECT() *MockHasGRPCGatewayMockRecorder {
return m.recorder
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockHasGRPCGateway) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockHasGRPCGatewayMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockHasGRPCGateway)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// MockHasGenesis is a mock of HasGenesis interface.
type MockHasGenesis struct {
ctrl *gomock.Controller
@ -243,6 +362,20 @@ func (mr *MockHasGenesisMockRecorder) InitGenesis(arg0, arg1, arg2 interface{})
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockHasGenesis)(nil).InitGenesis), arg0, arg1, arg2)
}
// Name mocks base method.
func (m *MockHasGenesis) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockHasGenesisMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasGenesis)(nil).Name))
}
// ValidateGenesis mocks base method.
func (m *MockHasGenesis) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
@ -322,6 +455,20 @@ func (mr *MockHasABCIGenesisMockRecorder) InitGenesis(arg0, arg1, arg2 interface
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockHasABCIGenesis)(nil).InitGenesis), arg0, arg1, arg2)
}
// Name mocks base method.
func (m *MockHasABCIGenesis) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockHasABCIGenesisMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasABCIGenesis)(nil).Name))
}
// ValidateGenesis mocks base method.
func (m *MockHasABCIGenesis) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
@ -336,103 +483,6 @@ func (mr *MockHasABCIGenesisMockRecorder) ValidateGenesis(arg0, arg1, arg2 inter
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockHasABCIGenesis)(nil).ValidateGenesis), arg0, arg1, arg2)
}
// MockAppModule is a mock of AppModule interface.
type MockAppModule struct {
ctrl *gomock.Controller
recorder *MockAppModuleMockRecorder
}
// MockAppModuleMockRecorder is the mock recorder for MockAppModule.
type MockAppModuleMockRecorder struct {
mock *MockAppModule
}
// NewMockAppModule creates a new mock instance.
func NewMockAppModule(ctrl *gomock.Controller) *MockAppModule {
mock := &MockAppModule{ctrl: ctrl}
mock.recorder = &MockAppModuleMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder {
return m.recorder
}
// IsAppModule mocks base method.
func (m *MockAppModule) IsAppModule() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IsAppModule")
}
// IsAppModule indicates an expected call of IsAppModule.
func (mr *MockAppModuleMockRecorder) IsAppModule() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockAppModule)(nil).IsAppModule))
}
// IsOnePerModuleType mocks base method.
func (m *MockAppModule) IsOnePerModuleType() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IsOnePerModuleType")
}
// IsOnePerModuleType indicates an expected call of IsOnePerModuleType.
func (mr *MockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockAppModule)(nil).IsOnePerModuleType))
}
// Name mocks base method.
func (m *MockAppModule) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockAppModuleMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAppModule)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// RegisterInterfaces mocks base method.
func (m *MockAppModule) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterInterfaces", arg0)
}
// RegisterInterfaces indicates an expected call of RegisterInterfaces.
func (mr *MockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModule)(nil).RegisterInterfaces), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModule)(nil).RegisterLegacyAminoCodec), arg0)
}
// MockHasInvariants is a mock of HasInvariants interface.
type MockHasInvariants struct {
ctrl *gomock.Controller
@ -616,18 +666,6 @@ func (mr *MockHasABCIEndBlockMockRecorder) Name() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasABCIEndBlock)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockHasABCIEndBlock) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockHasABCIEndBlockMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// RegisterInterfaces mocks base method.
func (m *MockHasABCIEndBlock) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
@ -639,144 +677,3 @@ func (mr *MockHasABCIEndBlockMockRecorder) RegisterInterfaces(arg0 interface{})
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterInterfaces), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockHasABCIEndBlock) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockHasABCIEndBlockMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterLegacyAminoCodec), arg0)
}
// MockgenesisOnlyModule is a mock of genesisOnlyModule interface.
type MockgenesisOnlyModule struct {
ctrl *gomock.Controller
recorder *MockgenesisOnlyModuleMockRecorder
}
// MockgenesisOnlyModuleMockRecorder is the mock recorder for MockgenesisOnlyModule.
type MockgenesisOnlyModuleMockRecorder struct {
mock *MockgenesisOnlyModule
}
// NewMockgenesisOnlyModule creates a new mock instance.
func NewMockgenesisOnlyModule(ctrl *gomock.Controller) *MockgenesisOnlyModule {
mock := &MockgenesisOnlyModule{ctrl: ctrl}
mock.recorder = &MockgenesisOnlyModuleMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockgenesisOnlyModule) EXPECT() *MockgenesisOnlyModuleMockRecorder {
return m.recorder
}
// DefaultGenesis mocks base method.
func (m *MockgenesisOnlyModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DefaultGenesis", arg0)
ret0, _ := ret[0].(json.RawMessage)
return ret0
}
// DefaultGenesis indicates an expected call of DefaultGenesis.
func (mr *MockgenesisOnlyModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockgenesisOnlyModule)(nil).DefaultGenesis), arg0)
}
// ExportGenesis mocks base method.
func (m *MockgenesisOnlyModule) ExportGenesis(arg0 context.Context, arg1 codec.JSONCodec) json.RawMessage {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1)
ret0, _ := ret[0].(json.RawMessage)
return ret0
}
// ExportGenesis indicates an expected call of ExportGenesis.
func (mr *MockgenesisOnlyModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockgenesisOnlyModule)(nil).ExportGenesis), arg0, arg1)
}
// InitGenesis mocks base method.
func (m *MockgenesisOnlyModule) InitGenesis(arg0 context.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2)
ret0, _ := ret[0].([]types.ValidatorUpdate)
return ret0
}
// InitGenesis indicates an expected call of InitGenesis.
func (mr *MockgenesisOnlyModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockgenesisOnlyModule)(nil).InitGenesis), arg0, arg1, arg2)
}
// Name mocks base method.
func (m *MockgenesisOnlyModule) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockgenesisOnlyModuleMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockgenesisOnlyModule)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockgenesisOnlyModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockgenesisOnlyModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockgenesisOnlyModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// RegisterInterfaces mocks base method.
func (m *MockgenesisOnlyModule) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterInterfaces", arg0)
}
// RegisterInterfaces indicates an expected call of RegisterInterfaces.
func (mr *MockgenesisOnlyModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockgenesisOnlyModule)(nil).RegisterInterfaces), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockgenesisOnlyModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockgenesisOnlyModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockgenesisOnlyModule)(nil).RegisterLegacyAminoCodec), arg0)
}
// ValidateGenesis mocks base method.
func (m *MockgenesisOnlyModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// ValidateGenesis indicates an expected call of ValidateGenesis.
func (mr *MockgenesisOnlyModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockgenesisOnlyModule)(nil).ValidateGenesis), arg0, arg1, arg2)
}

View File

@ -236,7 +236,7 @@ func (s *MempoolTestSuite) TestSampleTxs() {
}
func unmarshalTx(txBytes []byte) (sdk.Tx, error) {
cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModuleBasic{})
cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModule{})
return cfg.TxConfig.TxJSONDecoder()(txBytes)
}

View File

@ -19,33 +19,31 @@ import (
)
var (
_ appmodule.AppModule = coreAppModuleBasicAdaptor{}
_ appmodule.AppModule = coreAppModuleAdaptor{}
_ AppModuleBasic = coreAppModuleBasicAdaptor{}
_ HasABCIGenesis = coreAppModuleBasicAdaptor{}
_ HasServices = coreAppModuleBasicAdaptor{}
_ HasName = coreAppModuleAdaptor{}
_ HasAminoCodec = coreAppModuleAdaptor{}
_ HasGRPCGateway = coreAppModuleAdaptor{}
_ HasRegisterInterfaces = coreAppModuleAdaptor{}
_ HasABCIGenesis = coreAppModuleAdaptor{}
_ HasServices = coreAppModuleAdaptor{}
)
// CoreAppModuleAdaptor wraps the core API module as an AppModule that this version of the SDK can use.
func CoreAppModuleAdaptor(name string, module appmodule.AppModule) AppModule {
return coreAppModuleBasicAdaptor{
return coreAppModuleAdaptor{
name: name,
module: module,
}
}
// CoreAppModuleBasicAdaptor wraps the core API module as an AppModule that this version of the SDK can use.
func CoreAppModuleBasicAdaptor(name string, module appmodule.AppModule) AppModule {
return CoreAppModuleAdaptor(name, module)
}
type coreAppModuleBasicAdaptor struct {
type coreAppModuleAdaptor struct {
name string
module appmodule.AppModule
}
// DefaultGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (c coreAppModuleAdaptor) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
if mod, ok := c.module.(appmodule.HasGenesis); ok {
target := genesis.RawJSONTarget{}
err := mod.DefaultGenesis(target.Target())
@ -69,7 +67,7 @@ func (c coreAppModuleBasicAdaptor) DefaultGenesis(cdc codec.JSONCodec) json.RawM
}
// ValidateGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) ValidateGenesis(cdc codec.JSONCodec, txConfig client.TxEncodingConfig, bz json.RawMessage) error {
func (c coreAppModuleAdaptor) ValidateGenesis(cdc codec.JSONCodec, txConfig client.TxEncodingConfig, bz json.RawMessage) error {
if mod, ok := c.module.(appmodule.HasGenesis); ok {
source, err := genesis.SourceFromRawJSON(bz)
if err != nil {
@ -89,7 +87,7 @@ func (c coreAppModuleBasicAdaptor) ValidateGenesis(cdc codec.JSONCodec, txConfig
}
// ExportGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage {
func (c coreAppModuleAdaptor) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage {
if module, ok := c.module.(appmodule.HasGenesis); ok {
ctx := sdk.UnwrapSDKContext(ctx).WithGasMeter(storetypes.NewInfiniteGasMeter()) // avoid race conditions
target := genesis.RawJSONTarget{}
@ -114,7 +112,7 @@ func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx context.Context, cdc codec.
}
// InitGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
func (c coreAppModuleAdaptor) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
if module, ok := c.module.(appmodule.HasGenesis); ok {
// core API genesis
source, err := genesis.SourceFromRawJSON(bz)
@ -138,13 +136,12 @@ func (c coreAppModuleBasicAdaptor) InitGenesis(ctx context.Context, cdc codec.JS
return nil
}
// Name implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) Name() string {
// Name implements HasName
func (c coreAppModuleAdaptor) Name() string {
return c.name
}
// GetQueryCmd implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) GetQueryCmd() *cobra.Command {
func (c coreAppModuleAdaptor) GetQueryCmd() *cobra.Command {
if mod, ok := c.module.(interface {
GetQueryCmd() *cobra.Command
}); ok {
@ -154,8 +151,7 @@ func (c coreAppModuleBasicAdaptor) GetQueryCmd() *cobra.Command {
return nil
}
// GetTxCmd implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) GetTxCmd() *cobra.Command {
func (c coreAppModuleAdaptor) GetTxCmd() *cobra.Command {
if mod, ok := c.module.(interface {
GetTxCmd() *cobra.Command
}); ok {
@ -165,8 +161,8 @@ func (c coreAppModuleBasicAdaptor) GetTxCmd() *cobra.Command {
return nil
}
// RegisterGRPCGatewayRoutes implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) RegisterGRPCGatewayRoutes(ctx client.Context, mux *runtime.ServeMux) {
// RegisterGRPCGatewayRoutes implements HasGRPCGateway
func (c coreAppModuleAdaptor) RegisterGRPCGatewayRoutes(ctx client.Context, mux *runtime.ServeMux) {
if mod, ok := c.module.(interface {
RegisterGRPCGatewayRoutes(context client.Context, mux *runtime.ServeMux)
}); ok {
@ -174,8 +170,8 @@ func (c coreAppModuleBasicAdaptor) RegisterGRPCGatewayRoutes(ctx client.Context,
}
}
// RegisterInterfaces implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// RegisterInterfaces implements HasRegisterInterfaces
func (c coreAppModuleAdaptor) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
if mod, ok := c.module.(interface {
RegisterInterfaces(registry codectypes.InterfaceRegistry)
}); ok {
@ -183,8 +179,8 @@ func (c coreAppModuleBasicAdaptor) RegisterInterfaces(registry codectypes.Interf
}
}
// RegisterLegacyAminoCodec implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {
// RegisterLegacyAminoCodec implements HasAminoCodec
func (c coreAppModuleAdaptor) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {
if mod, ok := c.module.(interface {
RegisterLegacyAminoCodec(amino *codec.LegacyAmino)
}); ok {
@ -193,7 +189,7 @@ func (c coreAppModuleBasicAdaptor) RegisterLegacyAminoCodec(amino *codec.LegacyA
}
// RegisterServices implements HasServices
func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) {
func (c coreAppModuleAdaptor) RegisterServices(cfg Configurator) {
if module, ok := c.module.(appmodule.HasServices); ok {
err := module.RegisterServices(cfg)
if err != nil {
@ -209,6 +205,6 @@ func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) {
}
}
func (c coreAppModuleBasicAdaptor) IsOnePerModuleType() {}
func (c coreAppModuleAdaptor) IsOnePerModuleType() {}
func (c coreAppModuleBasicAdaptor) IsAppModule() {}
func (c coreAppModuleAdaptor) IsAppModule() {}

View File

@ -1,7 +1,6 @@
/*
Package module contains application module patterns and associated "manager" functionality.
The module pattern has been broken down by:
- independent module functionality (AppModuleBasic)
- inter-dependent module simulation functionality (AppModuleSimulation)
- inter-dependent module full functionality (AppModule)
@ -11,14 +10,7 @@ module keepers are dependent on each other, thus in order to access the full
set of module functionality we need to define all the keepers/params-store/keys
etc. This full set of advanced functionality is defined by the AppModule interface.
Independent module functions are separated to allow for the construction of the
basic application structures required early on in the application definition
and used to enable the definition of full module functionality later in the
process. This separation is necessary, however we still want to allow for a
high level pattern for modules to follow - for instance, such that we don't
have to manually register all of the codecs for all the modules. This basic
procedure as well as other basic patterns are handled through the use of
BasicManager.
Independent module functions of modules can be accessed through a non instantiated AppModule.
Lastly the interface for genesis functionality (HasGenesis & HasABCIGenesis) has been
separated out from full module functionality (AppModule) so that modules which
@ -51,12 +43,22 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// AppModuleBasic is the standard form for basic non-dependant elements of an application module.
// Deprecated: use the embed extension interfaces instead, when needed.
type AppModuleBasic interface {
HasName
RegisterLegacyAminoCodec(*codec.LegacyAmino)
RegisterInterfaces(types.InterfaceRegistry)
RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)
HasRegisterInterfaces
HasGRPCGateway
HasAminoCodec
}
// AppModule is the form for an application module. Most of
// its functionality has been moved to extension interfaces.
// Deprecated: use appmodule.AppModule with a combination of extension interfaces interfaces instead.
type AppModule interface {
appmodule.AppModule
HasName
HasRegisterInterfaces
}
// HasName allows the module to provide its own name for legacy purposes.
@ -68,117 +70,26 @@ type HasName interface {
// HasGenesisBasics is the legacy interface for stateless genesis methods.
type HasGenesisBasics interface {
HasName
DefaultGenesis(codec.JSONCodec) json.RawMessage
ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error
}
// BasicManager is a collection of AppModuleBasic
type BasicManager map[string]AppModuleBasic
// NewBasicManager creates a new BasicManager object
func NewBasicManager(modules ...AppModuleBasic) BasicManager {
moduleMap := make(map[string]AppModuleBasic)
for _, module := range modules {
moduleMap[module.Name()] = module
}
return moduleMap
// HasAminoCodec is the interface for modules that have amino codec registration.
// Deprecated: modules should not need to register their own amino codecs.
type HasAminoCodec interface {
RegisterLegacyAminoCodec(*codec.LegacyAmino)
}
// NewBasicManagerFromManager creates a new BasicManager from a Manager
// The BasicManager will contain all AppModuleBasic from the AppModule Manager
// Module's AppModuleBasic can be overridden by passing a custom AppModuleBasic map
func NewBasicManagerFromManager(manager *Manager, customModuleBasics map[string]AppModuleBasic) BasicManager {
moduleMap := make(map[string]AppModuleBasic)
for name, module := range manager.Modules {
if customBasicMod, ok := customModuleBasics[name]; ok {
moduleMap[name] = customBasicMod
continue
}
if appModule, ok := module.(appmodule.AppModule); ok {
moduleMap[name] = CoreAppModuleBasicAdaptor(name, appModule)
continue
}
if basicMod, ok := module.(AppModuleBasic); ok {
moduleMap[name] = basicMod
}
}
return moduleMap
// HasRegisterInterfaces is the interface for modules to register their msg types.
type HasRegisterInterfaces interface {
RegisterInterfaces(types.InterfaceRegistry)
}
// RegisterLegacyAminoCodec registers all module codecs
func (bm BasicManager) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
for _, b := range bm {
b.RegisterLegacyAminoCodec(cdc)
}
}
// RegisterInterfaces registers all module interface types
func (bm BasicManager) RegisterInterfaces(registry types.InterfaceRegistry) {
for _, m := range bm {
m.RegisterInterfaces(registry)
}
}
// DefaultGenesis provides default genesis information for all modules
func (bm BasicManager) DefaultGenesis(cdc codec.JSONCodec) map[string]json.RawMessage {
genesisData := make(map[string]json.RawMessage)
for _, b := range bm {
if mod, ok := b.(HasGenesisBasics); ok {
genesisData[b.Name()] = mod.DefaultGenesis(cdc)
}
}
return genesisData
}
// ValidateGenesis performs genesis state validation for all modules
func (bm BasicManager) ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, genesisData map[string]json.RawMessage) error {
for _, b := range bm {
// first check if the module is an adapted Core API Module
if mod, ok := b.(HasGenesisBasics); ok {
if err := mod.ValidateGenesis(cdc, txEncCfg, genesisData[b.Name()]); err != nil {
return err
}
}
}
return nil
}
// RegisterGRPCGatewayRoutes registers all module rest routes
func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux) {
for _, b := range bm {
b.RegisterGRPCGatewayRoutes(clientCtx, rtr)
}
}
// AddTxCommands adds all tx commands to the rootTxCmd.
func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
for _, b := range bm {
if mod, ok := b.(interface {
GetTxCmd() *cobra.Command
}); ok {
if cmd := mod.GetTxCmd(); cmd != nil {
rootTxCmd.AddCommand(cmd)
}
}
}
}
// AddQueryCommands adds all query commands to the rootQueryCmd.
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) {
for _, b := range bm {
if mod, ok := b.(interface {
GetQueryCmd() *cobra.Command
}); ok {
if cmd := mod.GetQueryCmd(); cmd != nil {
rootQueryCmd.AddCommand(cmd)
}
}
}
// HasGRPCGateway is the interface for modules to register their gRPC gateway routes.
type HasGRPCGateway interface {
RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)
}
// HasGenesis is the extension interface for stateful genesis methods.
@ -195,15 +106,6 @@ type HasABCIGenesis interface {
ExportGenesis(context.Context, codec.JSONCodec) json.RawMessage
}
// AppModule is the form for an application module. Most of
// its functionality has been moved to extension interfaces.
// Deprecated: use appmodule.AppModule with a combination of extension interfaes interfaces instead.
type AppModule interface {
appmodule.AppModule
AppModuleBasic
}
// HasInvariants is the interface for registering invariants.
type HasInvariants interface {
// RegisterInvariants registers module invariants.
@ -235,41 +137,6 @@ type HasABCIEndBlock interface {
EndBlock(context.Context) ([]abci.ValidatorUpdate, error)
}
var (
_ appmodule.AppModule = (*GenesisOnlyAppModule)(nil)
_ AppModuleBasic = (*GenesisOnlyAppModule)(nil)
)
// genesisOnlyModule is an interface need to return GenesisOnlyAppModule struct in order to wrap two interfaces
type genesisOnlyModule interface {
AppModuleBasic
HasABCIGenesis
}
// GenesisOnlyAppModule is an AppModule that only has import/export functionality
type GenesisOnlyAppModule struct {
genesisOnlyModule
}
// NewGenesisOnlyAppModule creates a new GenesisOnlyAppModule object
func NewGenesisOnlyAppModule(amg genesisOnlyModule) GenesisOnlyAppModule {
return GenesisOnlyAppModule{
genesisOnlyModule: amg,
}
}
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (GenesisOnlyAppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (GenesisOnlyAppModule) IsAppModule() {}
// RegisterInvariants is a placeholder function register no invariants
func (GenesisOnlyAppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (gam GenesisOnlyAppModule) ConsensusVersion() uint64 { return 1 }
// Manager defines a module manager that provides the high level utility for managing and executing
// operations for a group of modules
type Manager struct {
@ -444,6 +311,87 @@ func (m *Manager) SetOrderMigrations(moduleNames ...string) {
m.OrderMigrations = moduleNames
}
// RegisterLegacyAminoCodec registers all module codecs
func (m *Manager) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
for _, b := range m.Modules {
if mod, ok := b.(HasAminoCodec); ok {
mod.RegisterLegacyAminoCodec(cdc)
}
}
}
// RegisterInterfaces registers all module interface types
func (m *Manager) RegisterInterfaces(registry types.InterfaceRegistry) {
for _, b := range m.Modules {
if mod, ok := b.(HasRegisterInterfaces); ok {
mod.RegisterInterfaces(registry)
}
}
}
// DefaultGenesis provides default genesis information for all modules
func (m *Manager) DefaultGenesis(cdc codec.JSONCodec) map[string]json.RawMessage {
genesisData := make(map[string]json.RawMessage)
for _, b := range m.Modules {
if mod, ok := b.(HasGenesisBasics); ok {
genesisData[mod.Name()] = mod.DefaultGenesis(cdc)
} else if mod, ok := b.(HasName); ok {
genesisData[mod.Name()] = []byte("{}")
}
}
return genesisData
}
// ValidateGenesis performs genesis state validation for all modules
func (m *Manager) ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, genesisData map[string]json.RawMessage) error {
for _, b := range m.Modules {
// first check if the module is an adapted Core API Module
if mod, ok := b.(HasGenesisBasics); ok {
if err := mod.ValidateGenesis(cdc, txEncCfg, genesisData[mod.Name()]); err != nil {
return err
}
}
}
return nil
}
// RegisterGRPCGatewayRoutes registers all module rest routes
func (m *Manager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux) {
for _, b := range m.Modules {
if mod, ok := b.(HasGRPCGateway); ok {
mod.RegisterGRPCGatewayRoutes(clientCtx, rtr)
}
}
}
// AddTxCommands adds all tx commands to the rootTxCmd.
func (m *Manager) AddTxCommands(rootTxCmd *cobra.Command) {
for _, b := range m.Modules {
if mod, ok := b.(interface {
GetTxCmd() *cobra.Command
}); ok {
if cmd := mod.GetTxCmd(); cmd != nil {
rootTxCmd.AddCommand(cmd)
}
}
}
}
// AddQueryCommands adds all query commands to the rootQueryCmd.
func (m *Manager) AddQueryCommands(rootQueryCmd *cobra.Command) {
for _, b := range m.Modules {
if mod, ok := b.(interface {
GetQueryCmd() *cobra.Command
}); ok {
if cmd := mod.GetQueryCmd(); cmd != nil {
rootQueryCmd.AddCommand(cmd)
}
}
}
}
// RegisterInvariants registers all module invariants
func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) {
for _, module := range m.Modules {

View File

@ -32,66 +32,6 @@ func (MockCoreAppModule) GetQueryCmd() *cobra.Command {
}
}
func TestBasicManager(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
legacyAmino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
// Test with a legacy module, a mock core module that doesn't return anything,
// and a core module defined in this file
expDefaultGenesis := map[string]json.RawMessage{
"mockAppModuleBasic1": json.RawMessage(``),
"mockCoreAppModule2": json.RawMessage(`null`),
"mockCoreAppModule3": json.RawMessage(`{
"someField": "someKey"
}`),
}
// legacy module
mockAppModuleBasic1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockAppModuleBasic1.EXPECT().Name().AnyTimes().Return("mockAppModuleBasic1")
mockAppModuleBasic1.EXPECT().DefaultGenesis(gomock.Eq(cdc)).Times(1).Return(json.RawMessage(``))
// Allow ValidateGenesis to be called any times because other module can fail before this one is called.
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)
// mock core API module
mockCoreAppModule2 := mock.NewMockCoreAppModule(mockCtrl)
mockCoreAppModule2.EXPECT().DefaultGenesis(gomock.Any()).AnyTimes().Return(nil)
mockCoreAppModule2.EXPECT().ValidateGenesis(gomock.Any()).AnyTimes().Return(nil)
mockAppModule2 := module.CoreAppModuleBasicAdaptor("mockCoreAppModule2", mockCoreAppModule2)
// mock core API module (but all methods are implemented)
mockCoreAppModule3 := module.CoreAppModuleBasicAdaptor("mockCoreAppModule3", MockCoreAppModule{})
mm := module.NewBasicManager(mockAppModuleBasic1, mockAppModule2, mockCoreAppModule3)
require.Equal(t, mockAppModuleBasic1, mm["mockAppModuleBasic1"])
require.Equal(t, mockAppModule2, mm["mockCoreAppModule2"])
require.Equal(t, mockCoreAppModule3, mm["mockCoreAppModule3"])
mm.RegisterLegacyAminoCodec(legacyAmino)
mm.RegisterInterfaces(interfaceRegistry)
require.Equal(t, expDefaultGenesis, mm.DefaultGenesis(cdc))
var data map[string]string
require.Equal(t, map[string]string(nil), data)
require.ErrorIs(t, mm.ValidateGenesis(cdc, nil, expDefaultGenesis), errFoo)
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))
}
func TestAssertNoForgottenModules(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
@ -101,7 +41,7 @@ func TestAssertNoForgottenModules(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mm := module.NewManager(
mockAppModule1,
module.CoreAppModuleBasicAdaptor("module3", mockAppModule3),
module.CoreAppModuleAdaptor("module3", mockAppModule3),
)
require.NotNil(t, mm)
require.Equal(t, 2, len(mm.Modules))
@ -131,7 +71,7 @@ func TestManagerOrderSetters(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("module3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("module3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@ -174,7 +114,7 @@ func TestManager_RegisterInvariants(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
// TODO: This is not working for Core API modules yet
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("mockAppModule3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("mockAppModule3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@ -195,7 +135,7 @@ func TestManager_RegisterQueryServices(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
// TODO: This is not working for Core API modules yet
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("mockAppModule3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("mockAppModule3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@ -227,7 +167,7 @@ func TestManager_InitGenesis(t *testing.T) {
mockAppModule3 := mock.NewMockCoreAppModule(mockCtrl)
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(4).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("module3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("module3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@ -261,7 +201,7 @@ func TestManager_InitGenesis(t *testing.T) {
// happy path
mm2 := module.NewManager(mockAppModuleABCI1, mockAppModule2, module.CoreAppModuleBasicAdaptor("module3", mockAppModule3))
mm2 := module.NewManager(mockAppModuleABCI1, mockAppModule2, module.CoreAppModuleAdaptor("module3", mockAppModule3))
mockAppModuleABCI1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{{}})
mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module2"])).Times(1)
mockAppModule3.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Any()).Times(1).Return(nil)
@ -278,7 +218,7 @@ func TestManager_ExportGenesis(t *testing.T) {
mockCoreAppModule := MockCoreAppModule{}
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("mockCoreAppModule", mockCoreAppModule))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("mockCoreAppModule", mockCoreAppModule))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))

View File

@ -12,7 +12,7 @@ import (
)
// TestEncodingConfig defines an encoding configuration that is used for testing
// purposes. Note, MakeTestEncodingConfig takes a series of AppModuleBasic types
// purposes. Note, MakeTestEncodingConfig takes a series of AppModule types
// which should only contain the relevant module being tested and any potential
// dependencies.
type TestEncodingConfig struct {
@ -22,7 +22,7 @@ type TestEncodingConfig struct {
Amino *codec.LegacyAmino
}
func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig {
func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig {
aminoCodec := codec.NewLegacyAmino()
interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)
@ -34,8 +34,7 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig
Amino: aminoCodec,
}
mb := module.NewBasicManager(modules...)
mb := module.NewManager(modules...)
std.RegisterLegacyAminoCodec(encCfg.Amino)
std.RegisterInterfaces(encCfg.InterfaceRegistry)
mb.RegisterLegacyAminoCodec(encCfg.Amino)

View File

@ -12,7 +12,6 @@ require (
github.com/cosmos/cosmos-sdk v0.51.0
github.com/cosmos/gogoproto v1.4.11
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
@ -85,6 +84,7 @@ require (
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect

View File

@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"google.golang.org/grpc"
@ -51,14 +50,12 @@ type AppModule struct {
func (m AppModule) IsAppModule() {}
func (m AppModule) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}
func (AppModule) Name() string { return ModuleName }
func (m AppModule) RegisterInterfaces(registry types.InterfaceRegistry) {
msgservice.RegisterMsgServiceDesc(registry, v1.MsgServiceDesc())
}
func (m AppModule) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
// App module services
func (m AppModule) RegisterServices(registar grpc.ServiceRegistrar) error {
@ -100,8 +97,6 @@ func (m AppModule) ExportGenesis(ctx context.Context, jsonCodec codec.JSONCodec)
return jsonCodec.MustMarshalJSON(gs)
}
func (AppModule) Name() string { return ModuleName }
func (AppModule) GetTxCmd() *cobra.Command {
return cli.TxCmd(ModuleName)
}

View File

@ -67,7 +67,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
key := storetypes.NewKVStoreKey(types.StoreKey)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
suite.ctx = testCtx.Ctx.WithIsCheckTx(isCheckTx).WithBlockHeight(1)
suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
maccPerms := map[string][]string{
"fee_collector": nil,

View File

@ -17,7 +17,7 @@ import (
)
func TestGetCommandEncode(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
txConfig := encodingConfig.TxConfig
cdc := encodingConfig.Codec
@ -47,7 +47,7 @@ func TestGetCommandEncode(t *testing.T) {
}
func TestGetCommandDecode(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
txConfig := encodingConfig.TxConfig
cdc := encodingConfig.Codec

View File

@ -138,7 +138,7 @@ func TestReadTxsFromFile(t *testing.T) {
func TestBatchScanner_Scan(t *testing.T) {
t.Parallel()
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
txConfig := encodingConfig.TxConfig
clientCtx := client.Context{}

View File

@ -52,7 +52,7 @@ func TestDeterministicTestSuite(t *testing.T) {
}
func (suite *DeterministicTestSuite) SetupTest() {
suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
suite.Require()
key := storetypes.NewKVStoreKey(types.StoreKey)

View File

@ -46,7 +46,7 @@ type KeeperTestSuite struct {
}
func (suite *KeeperTestSuite) SetupTest() {
suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)

View File

@ -8,7 +8,6 @@ import (
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/x/auth/keeper"
"cosmossdk.io/x/auth/simulation"
@ -28,8 +27,8 @@ const (
)
var (
_ module.AppModuleBasic = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasName = AppModule{}
_ module.HasGenesis = AppModule{}
_ appmodule.AppModule = AppModule{}
@ -37,53 +36,8 @@ var (
_ appmodule.HasMigrations = AppModule{}
)
// AppModuleBasic defines the basic application module used by the auth module.
type AppModuleBasic struct {
ac address.Codec
}
// Name returns the auth module's name.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the auth module's types for the given codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// DefaultGenesis returns default genesis state as raw bytes for the auth
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the auth module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return types.ValidateGenesis(data)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the auth module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// RegisterInterfaces registers interfaces and implementations of the auth module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module for the auth module.
type AppModule struct {
AppModuleBasic
accountKeeper keeper.AccountKeeper
randGenAccountsFn types.RandomGenesisAccountsFn
}
@ -94,12 +48,33 @@ func (am AppModule) IsAppModule() {}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, accountKeeper keeper.AccountKeeper, randGenAccountsFn types.RandomGenesisAccountsFn) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{ac: accountKeeper.AddressCodec()},
accountKeeper: accountKeeper,
randGenAccountsFn: randGenAccountsFn,
}
}
// Name returns the auth module's name.
func (AppModule) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the auth module's types for the given codec.
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the auth module.
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// RegisterInterfaces registers interfaces and implementations of the auth module.
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.accountKeeper))
@ -108,6 +83,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
return nil
}
// RegisterMigrations registers module migrations
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
m := keeper.NewMigrator(am.accountKeeper)
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
@ -127,8 +103,22 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
return nil
}
// InitGenesis performs genesis initialization for the auth module. It returns
// no validator updates.
// DefaultGenesis returns default genesis state as raw bytes for the auth module.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the auth module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return types.ValidateGenesis(data)
}
// InitGenesis performs genesis initialization for the auth module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
@ -148,7 +138,7 @@ func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json
return cdc.MustMarshalJSON(gs)
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// AppModuleSimulation functions

View File

@ -54,7 +54,7 @@ func TestValidateGenesisDuplicateAccounts(t *testing.T) {
}
func TestGenesisAccountIterator(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
cdc := encodingConfig.Codec
acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1))

View File

@ -37,7 +37,7 @@ func TestMigrateTestSuite(t *testing.T) {
}
func (s *CLITestSuite) SetupSuite() {
s.encCfg = testutilmod.MakeTestEncodingConfig(vesting.AppModuleBasic{})
s.encCfg = testutilmod.MakeTestEncodingConfig(vesting.AppModule{})
s.kr = keyring.NewInMemory(s.encCfg.Codec)
s.baseCtx = client.Context{}.
WithKeyring(s.kr).

View File

@ -1,10 +1,6 @@
package vesting
import (
"context"
"encoding/json"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"google.golang.org/grpc"
@ -13,92 +9,60 @@ import (
"cosmossdk.io/x/auth/vesting/client/cli"
"cosmossdk.io/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module"
)
var (
_ module.AppModuleBasic = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.AppModule = AppModule{}
_ module.HasName = AppModule{}
_ appmodule.AppModule = AppModule{}
)
// AppModuleBasic defines the basic application module used by the sub-vesting
// module. The module itself contain no special logic or state other than message
// handling.
type AppModuleBasic struct{}
// Name returns the module's name.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
// RegisterCodec registers the module's types with the given codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers the module's interfaces and implementations with
// the given interface registry.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// DefaultGenesis returns the module's default genesis state as raw bytes.
func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
return []byte("{}")
}
// ValidateGenesis performs genesis state validation. Currently, this is a no-op.
func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
return nil
}
// RegisterGRPCGatewayRoutes registers the module's gRPC Gateway routes. Currently, this
// is a no-op.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {}
// GetTxCmd returns the root tx command for the vesting module.
func (amb AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
// AppModule extends the AppModuleBasic implementation by implementing the
// AppModule interface.
// AppModule implementing the AppModule interface.
type AppModule struct {
AppModuleBasic
accountKeeper keeper.AccountKeeper
bankKeeper types.BankKeeper
}
func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
accountKeeper: ak,
bankKeeper: bk,
accountKeeper: ak,
bankKeeper: bk,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// Name returns the module's name.
func (AppModule) Name() string {
return types.ModuleName
}
// RegisterCodec registers the module's types with the given codec.
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers the module's interfaces and implementations with
// the given interface registry.
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// GetTxCmd returns the root tx command for the vesting module.
func (AppModule) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, NewMsgServerImpl(am.accountKeeper, am.bankKeeper))
return nil
}
// InitGenesis performs a no-op.
func (am AppModule) InitGenesis(_ context.Context, _ codec.JSONCodec, _ json.RawMessage) {}
// ExportGenesis is always empty, as InitGenesis does nothing either.
func (am AppModule) ExportGenesis(_ context.Context, cdc codec.JSONCodec) json.RawMessage {
return am.DefaultGenesis(cdc)
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }

View File

@ -38,7 +38,7 @@ type VestingAccountTestSuite struct {
}
func (s *VestingAccountTestSuite) SetupTest() {
encCfg := moduletestutil.MakeTestEncodingConfig(vesting.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(vesting.AppModule{})
key := storetypes.NewKVStoreKey(authtypes.StoreKey)
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())

View File

@ -51,7 +51,7 @@ func TestCLITestSuite(t *testing.T) {
}
func (s *CLITestSuite) SetupSuite() {
s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModuleBasic{}, authz.AppModule{})
s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModule{}, authz.AppModule{})
s.kr = keyring.NewInMemory(s.encCfg.Codec)
s.baseCtx = client.Context{}.

View File

@ -48,7 +48,7 @@ func (suite *GenesisTestSuite) SetupTest() {
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{})
// gomock initializations
ctrl := gomock.NewController(suite.T())

View File

@ -51,7 +51,7 @@ func (s *TestSuite) SetupTest() {
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now().Round(0).UTC()})
s.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
s.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{})
s.baseApp = baseapp.NewBaseApp(
"authz",

View File

@ -3,10 +3,4 @@ package authz
const (
// ModuleName is the module name constant used in many places
ModuleName = "authz"
// RouterKey is the message route for authz
RouterKey = ModuleName
// QuerierRoute is the querier route for authz
QuerierRoute = ModuleName
)

View File

@ -24,7 +24,7 @@ import (
)
func TestMigration(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}, bank.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}, bank.AppModule{})
cdc := encodingConfig.Codec
authzKey := storetypes.NewKVStoreKey("authz")

View File

@ -30,7 +30,7 @@ func TestExpiredGrantsQueue(t *testing.T) {
key := storetypes.NewKVStoreKey(keeper.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{})
ctx := testCtx.Ctx
baseApp := baseapp.NewBaseApp(

View File

@ -23,10 +23,15 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
const ConsensusVersion = 2
var (
_ module.AppModuleBasic = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasName = AppModule{}
_ module.HasAminoCodec = AppModule{}
_ module.HasGRPCGateway = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasBeginBlocker = AppModule{}
@ -34,13 +39,31 @@ var (
_ appmodule.HasMigrations = AppModule{}
)
// AppModuleBasic defines the basic application module used by the authz module.
type AppModuleBasic struct {
cdc codec.Codec
// AppModule implements the sdk.AppModule interface
type AppModule struct {
cdc codec.Codec
keeper keeper.Keeper
accountKeeper authz.AccountKeeper
bankKeeper authz.BankKeeper
registry cdctypes.InterfaceRegistry
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak authz.AccountKeeper, bk authz.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule {
return AppModule{
cdc: cdc,
keeper: keeper,
accountKeeper: ak,
bankKeeper: bk,
registry: registry,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (AppModule) IsAppModule() {}
// Name returns the authz module's name.
func (AppModuleBasic) Name() string {
func (AppModule) Name() string {
return authz.ModuleName
}
@ -52,6 +75,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
return nil
}
// RegisterMigrations registers the authz module migrations.
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
m := keeper.NewMigrator(am.keeper)
if err := mr.Register(authz.ModuleName, 1, m.Migrate1to2); err != nil {
@ -62,23 +86,34 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
}
// RegisterLegacyAminoCodec registers the authz module's types for the given codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
authz.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers the authz module's interface types
func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
authz.RegisterInterfaces(registry)
}
// DefaultGenesis returns default genesis state as raw bytes for the authz
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module.
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) {
if err := authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the transaction commands for the authz module
func (AppModule) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
// DefaultGenesis returns default genesis state as raw bytes for the authz module.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(authz.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the authz module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error {
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error {
var data authz.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return errors.Wrapf(err, "failed to unmarshal %s genesis state", authz.ModuleName)
@ -87,59 +122,21 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEn
return authz.ValidateGenesis(data)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) {
if err := authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the transaction commands for the authz module
func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
// AppModule implements the sdk.AppModule interface
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
accountKeeper authz.AccountKeeper
bankKeeper authz.BankKeeper
registry cdctypes.InterfaceRegistry
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak authz.AccountKeeper, bk authz.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
accountKeeper: ak,
bankKeeper: bk,
registry: registry,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// InitGenesis performs genesis initialization for the authz module. It returns
// no validator updates.
// InitGenesis performs genesis initialization for the authz module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
var genesisState authz.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
am.keeper.InitGenesis(ctx, &genesisState)
}
// ExportGenesis returns the exported genesis state as raw bytes for the authz
// module.
// ExportGenesis returns the exported genesis state as raw bytes for the authz module.
func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage {
gs := am.keeper.ExportGenesis(ctx)
return cdc.MustMarshalJSON(gs)
}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 2 }
// ConsensusVersion implements HasConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// BeginBlock returns the begin blocker for the authz module.
func (am AppModule) BeginBlock(ctx context.Context) error {

View File

@ -19,7 +19,7 @@ import (
)
func TestDecodeStore(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{})
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
dec := simulation.NewDecodeStore(encCfg.Codec)

View File

@ -19,7 +19,7 @@ import (
)
func TestRandomizedGenState(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{})
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
s := rand.NewSource(1)

View File

@ -37,7 +37,7 @@ func TestCLITestSuite(t *testing.T) {
}
func (s *CLITestSuite) SetupSuite() {
s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModuleBasic{})
s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModule{})
s.kr = keyring.NewInMemory(s.encCfg.Codec)
s.baseCtx = client.Context{}.
WithKeyring(s.kr).

View File

@ -29,73 +29,63 @@ import (
const ConsensusVersion = 4
var (
_ module.AppModuleBasic = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasInvariants = AppModule{}
_ module.HasName = AppModule{}
_ module.HasAminoCodec = AppModule{}
_ module.HasGRPCGateway = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasInvariants = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasServices = AppModule{}
_ appmodule.HasMigrations = AppModule{}
)
// AppModuleBasic defines the basic application module used by the bank module.
type AppModuleBasic struct {
cdc codec.Codec
// AppModule implements an application module for the bank module.
type AppModule struct {
cdc codec.Codec
keeper keeper.Keeper
accountKeeper types.AccountKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper) AppModule {
return AppModule{
cdc: cdc,
keeper: keeper,
accountKeeper: accountKeeper,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// Name returns the bank module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }
func (AppModule) Name() string { return types.ModuleName }
// RegisterLegacyAminoCodec registers the bank module's types on the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// DefaultGenesis returns default genesis state as raw bytes for the bank
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the bank module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return data.Validate()
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bank module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the root tx command for the bank module.
func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module for the bank module.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
accountKeeper types.AccountKeeper
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
@ -104,6 +94,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
return nil
}
// RegisterMigrations registers the bank module's migrations.
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
m := keeper.NewMigrator(am.keeper.(keeper.BaseKeeper))
@ -122,25 +113,27 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
return nil
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
accountKeeper: accountKeeper,
}
}
// RegisterInvariants registers the bank module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
keeper.RegisterInvariants(ir, am.keeper)
}
// QuerierRoute returns the bank module's querier route name.
func (AppModule) QuerierRoute() string { return types.RouterKey }
// DefaultGenesis returns default genesis state as raw bytes for the bank module.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// InitGenesis performs genesis initialization for the bank module. It returns
// no validator updates.
// ValidateGenesis performs genesis state validation for the bank module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return data.Validate()
}
// InitGenesis performs genesis initialization for the bank module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
start := time.Now()
var genesisState types.GenesisState
@ -157,7 +150,7 @@ func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json
return cdc.MustMarshalJSON(gs)
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// AppModuleSimulation functions

View File

@ -65,20 +65,6 @@ func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomo
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr)
}
// GetAllAccounts mocks base method.
func (m *MockAccountKeeper) GetAllAccounts(ctx context.Context) []types0.AccountI {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllAccounts", ctx)
ret0, _ := ret[0].([]types0.AccountI)
return ret0
}
// GetAllAccounts indicates an expected call of GetAllAccounts.
func (mr *MockAccountKeeperMockRecorder) GetAllAccounts(ctx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllAccounts", reflect.TypeOf((*MockAccountKeeper)(nil).GetAllAccounts), ctx)
}
// GetModuleAccount mocks base method.
func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, moduleName string) types0.ModuleAccountI {
m.ctrl.T.Helper()
@ -165,18 +151,6 @@ func (mr *MockAccountKeeperMockRecorder) HasAccount(ctx, addr interface{}) *gomo
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasAccount", reflect.TypeOf((*MockAccountKeeper)(nil).HasAccount), ctx, addr)
}
// IterateAccounts mocks base method.
func (m *MockAccountKeeper) IterateAccounts(ctx context.Context, process func(types0.AccountI) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateAccounts", ctx, process)
}
// IterateAccounts indicates an expected call of IterateAccounts.
func (mr *MockAccountKeeperMockRecorder) IterateAccounts(ctx, process interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateAccounts", reflect.TypeOf((*MockAccountKeeper)(nil).IterateAccounts), ctx, process)
}
// NewAccount mocks base method.
func (m *MockAccountKeeper) NewAccount(arg0 context.Context, arg1 types0.AccountI) types0.AccountI {
m.ctrl.T.Helper()

View File

@ -15,9 +15,6 @@ const (
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey defines the module's message routing key
RouterKey = ModuleName
// GovModuleName duplicates the gov module's name to avoid a cyclic dependency with x/gov.
// It should be synced with the gov module's name if it is ever changed.
// See: https://github.com/cosmos/cosmos-sdk/blob/b62a28aac041829da5ded4aeacfcd7a42873d1c8/x/gov/types/keys.go#L9

View File

@ -37,7 +37,7 @@ func (m MockCircuitBreaker) IsAllowed(ctx context.Context, typeURL string) (bool
func initFixture(t *testing.T) *fixture {
t.Helper()
mockStoreKey := storetypes.NewKVStoreKey("test")
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{})
mockclientCtx := client.Context{}.
WithTxConfig(encCfg.TxConfig)
@ -61,8 +61,8 @@ func TestCircuitBreakerDecorator(t *testing.T) {
allowed bool
}{
{msg: &cbtypes.MsgAuthorizeCircuitBreaker{
Grantee: "cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x",
Granter: "cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts",
Grantee: "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5",
Granter: "cosmos16wfryel63g7axeamw68630wglalcnk3l0zuadc",
}, allowed: true},
{msg: testdata.NewTestMsg(addr1), allowed: false},
}

View File

@ -37,7 +37,7 @@ func TestGenesisTestSuite(t *testing.T) {
func (s *GenesisTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(types.ModuleName)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModule{})
sdkCtx := testCtx.Ctx
s.ctx = sdkCtx

View File

@ -6,8 +6,6 @@ import (
"cosmossdk.io/collections"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
"cosmossdk.io/core/store"
"cosmossdk.io/x/circuit/types"
"github.com/cosmos/cosmos-sdk/codec"
@ -15,9 +13,8 @@ import (
// Keeper defines the circuit module's keeper.
type Keeper struct {
cdc codec.BinaryCodec
storeService store.KVStoreService
eventService event.Service
cdc codec.BinaryCodec
env appmodule.Environment
authority []byte
@ -37,15 +34,12 @@ func NewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, authority strin
panic(err)
}
storeService := env.KVStoreService
sb := collections.NewSchemaBuilder(storeService)
sb := collections.NewSchemaBuilder(env.KVStoreService)
k := Keeper{
cdc: cdc,
storeService: storeService,
eventService: env.EventService,
authority: auth,
env: env,
addressCodec: addressCodec,
Permissions: collections.NewMap(
sb,

View File

@ -40,7 +40,7 @@ type fixture struct {
func initFixture(t *testing.T) *fixture {
t.Helper()
encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModule{})
ac := addresscodec.NewBech32Codec("cosmos")
mockStoreKey := storetypes.NewKVStoreKey("test")

View File

@ -63,13 +63,12 @@ func (srv msgServer) AuthorizeCircuitBreaker(ctx context.Context, msg *types.Msg
return nil, err
}
err = srv.Keeper.eventService.EventManager(ctx).EmitKV(
if err = srv.Keeper.env.EventService.EventManager(ctx).EmitKV(
"authorize_circuit_breaker",
event.NewAttribute("granter", msg.Granter),
event.NewAttribute("grantee", msg.Grantee),
event.NewAttribute("permission", msg.Permissions.String()),
)
if err != nil {
); err != nil {
return nil, err
}
@ -121,12 +120,11 @@ func (srv msgServer) TripCircuitBreaker(ctx context.Context, msg *types.MsgTripC
urls := strings.Join(msg.GetMsgTypeUrls(), ",")
err = srv.Keeper.eventService.EventManager(ctx).EmitKV(
if err = srv.Keeper.env.EventService.EventManager(ctx).EmitKV(
"trip_circuit_breaker",
event.NewAttribute("authority", msg.Authority),
event.NewAttribute("msg_url", urls),
)
if err != nil {
); err != nil {
return nil, err
}
@ -180,12 +178,11 @@ func (srv msgServer) ResetCircuitBreaker(ctx context.Context, msg *types.MsgRese
urls := strings.Join(msg.GetMsgTypeUrls(), ",")
err = srv.Keeper.eventService.EventManager(ctx).EmitKV(
if err = srv.Keeper.env.EventService.EventManager(ctx).EmitKV(
"reset_circuit_breaker",
event.NewAttribute("authority", msg.Authority),
event.NewAttribute("msg_url", urls),
)
if err != nil {
); err != nil {
return nil, err
}

View File

@ -24,63 +24,39 @@ import (
const ConsensusVersion = 1
var (
_ module.AppModuleBasic = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasName = AppModule{}
_ module.HasGRPCGateway = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ module.HasGenesis = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasServices = AppModule{}
)
// AppModuleBasic defines the basic application module used by the circuit module.
type AppModuleBasic struct {
cdc codec.Codec
// AppModule implements an application module for the circuit module.
type AppModule struct {
cdc codec.Codec
keeper keeper.Keeper
}
// IsAppModule implements the appmodule.AppModule interface.
func (AppModule) IsAppModule() {}
// Name returns the circuit module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }
// RegisterLegacyAminoCodec registers the circuit module's types on the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
}
// DefaultGenesis returns default genesis state as raw bytes for the circuit
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the circuit module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return data.Validate()
}
func (AppModule) Name() string { return types.ModuleName }
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the circuit module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// RegisterInterfaces registers interfaces and implementations of the circuit module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module for the circuit module.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
@ -92,16 +68,30 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
cdc: cdc,
keeper: keeper,
}
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// InitGenesis performs genesis initialization for the circuit module. It returns
// no validator updates.
// DefaultGenesis returns default genesis state as raw bytes for the circuit module.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the circuit module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return data.Validate()
}
// InitGenesis performs genesis initialization for the circuit module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
start := time.Now()
var genesisState types.GenesisState

View File

@ -20,46 +20,51 @@ import (
const ConsensusVersion = 1
var (
_ module.AppModuleBasic = AppModule{}
_ module.HasName = AppModule{}
_ module.HasAminoCodec = AppModule{}
_ module.HasGRPCGateway = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ appmodule.AppModule = AppModule{}
)
// AppModuleBasic defines the basic application module used by the consensus module.
type AppModuleBasic struct {
cdc codec.Codec
// AppModule implements an application module
type AppModule struct {
cdc codec.Codec
keeper keeper.Keeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
return AppModule{
cdc: cdc,
keeper: keeper,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (AppModule) IsAppModule() {}
// Name returns the consensus module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }
func (AppModule) Name() string { return types.ModuleName }
// RegisterLegacyAminoCodec registers the consensus module's types on the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, am.keeper)
@ -67,13 +72,5 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
return nil
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
}
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }

View File

@ -1,13 +1,10 @@
package counter
import (
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
"cosmossdk.io/core/appmodule"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/counter/keeper"
@ -15,32 +12,14 @@ import (
)
var (
_ module.AppModuleBasic = AppModule{}
_ module.HasName = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ appmodule.AppModule = AppModule{}
)
// AppModuleBasic defines the basic application module used by the consensus module.
type AppModuleBasic struct{}
// Name returns the consensus module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }
// RegisterLegacyAminoCodec registers the consensus module's types on the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {}
// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
}
@ -57,10 +36,17 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
// NewAppModule creates a new AppModule object
func NewAppModule(keeper keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
keeper: keeper,
}
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return 1 }
// Name returns the consensus module's name.
func (AppModule) Name() string { return types.ModuleName }
// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}

View File

@ -37,7 +37,7 @@ func (s *GenesisTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{})
// gomock initializations
ctrl := gomock.NewController(s.T())

View File

@ -26,7 +26,7 @@ func TestLogger(t *testing.T) {
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{})
keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos"))
require.Equal(t,
@ -40,7 +40,7 @@ func TestInvariants(t *testing.T) {
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{})
keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos"))
require.Equal(t, keeper.InvCheckPeriod(), uint(5))
@ -57,7 +57,7 @@ func TestAssertInvariants(t *testing.T) {
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{})
keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos"))
keeper.RegisterRoute("testModule", "testRoute1", func(sdk.Context) (string, bool) { return "", false })

View File

@ -37,7 +37,7 @@ func (s *KeeperTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{})
keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", sdk.AccAddress([]byte("addr1_______________")).String(), addresscodec.NewBech32Codec("cosmos"))
s.ctx = testCtx.Ctx
@ -51,7 +51,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() {
err := s.keeper.ConstantFee.Set(s.ctx, constantFee)
s.Require().NoError(err)
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{})
kr := keyring.NewInMemory(encCfg.Codec)
testutil.CreateKeyringAccounts(s.T(), kr, 1)

View File

@ -6,7 +6,6 @@ import (
"fmt"
"time"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"google.golang.org/grpc"
@ -25,8 +24,10 @@ import (
const ConsensusVersion = 2
var (
_ module.AppModuleBasic = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasName = AppModule{}
_ module.HasAminoCodec = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ module.HasGenesis = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasEndBlocker = AppModule{}
@ -35,52 +36,10 @@ var (
)
// Module init related flags
const (
FlagSkipGenesisInvariants = "x-crisis-skip-assert-invariants"
)
// AppModuleBasic defines the basic application module used by the crisis module.
type AppModuleBasic struct{}
// Name returns the crisis module's name.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the crisis module's types on the given LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// DefaultGenesis returns default genesis state as raw bytes for the crisis
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the crisis module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return types.ValidateGenesis(&data)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the crisis module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {}
// RegisterInterfaces registers interfaces and implementations of the crisis
// module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
const FlagSkipGenesisInvariants = "x-crisis-skip-assert-invariants"
// AppModule implements an application module for the crisis module.
type AppModule struct {
AppModuleBasic
// NOTE: We store a reference to the keeper here so that after a module
// manager is created, the invariants can be properly registered and
// executed.
@ -95,9 +54,7 @@ type AppModule struct {
// modified genesis file.
func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
keeper: keeper,
skipGenesisInvariants: skipGenesisInvariants,
}
}
@ -105,6 +62,22 @@ func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool) AppModule {
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// Name returns the crisis module's name.
func (AppModule) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the crisis module's types on the given LegacyAmino codec.
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers interfaces and implementations of the crisis
// module.
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AddModuleInitFlags implements servertypes.ModuleInitFlags interface.
func AddModuleInitFlags(startCmd *cobra.Command) {
startCmd.Flags().Bool(FlagSkipGenesisInvariants, false, "Skip x/crisis invariants check on startup")
@ -117,6 +90,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
return nil
}
// RegisterMigrations registers the crisis module migrations.
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
m := keeper.NewMigrator(am.keeper)
@ -127,8 +101,22 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
return nil
}
// InitGenesis performs genesis initialization for the crisis module. It returns
// no validator updates.
// DefaultGenesis returns default genesis state as raw bytes for the crisis module.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the crisis module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return types.ValidateGenesis(&data)
}
// InitGenesis performs genesis initialization for the crisis module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
start := time.Now()
var genesisState types.GenesisState
@ -141,14 +129,13 @@ func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data j
}
}
// ExportGenesis returns the exported genesis state as raw bytes for the crisis
// module.
// ExportGenesis returns the exported genesis state as raw bytes for the crisis module.
func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage {
gs := am.keeper.ExportGenesis(ctx)
return cdc.MustMarshalJSON(gs)
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// EndBlock returns the end blocker for the crisis module. It returns no validator

View File

@ -34,9 +34,7 @@ func NewTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}
distTxCmd.AddCommand(
NewWithdrawAllRewardsCmd(),
)
distTxCmd.AddCommand(NewWithdrawAllRewardsCmd())
return distTxCmd
}

View File

@ -31,7 +31,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -90,7 +90,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -221,7 +221,7 @@ func TestAllocateTokensTruncation(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)

View File

@ -29,7 +29,7 @@ func TestCalculateRewardsBasic(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -131,7 +131,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -236,7 +236,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -362,7 +362,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -461,7 +461,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -538,7 +538,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -656,7 +656,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -795,7 +795,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)
@ -996,7 +996,7 @@ func Test100PercentCommissionReward(t *testing.T) {
key := storetypes.NewKVStoreKey(disttypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
bankKeeper := distrtestutil.NewMockBankKeeper(ctrl)

View File

@ -38,7 +38,7 @@ func initFixture(t *testing.T) (sdk.Context, []sdk.AccAddress, keeper.Keeper, de
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})
addrs := simtestutil.CreateIncrementalAccounts(2)

View File

@ -34,7 +34,7 @@ func TestFundsMigration(t *testing.T) {
)
logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, distribution.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, distribution.AppModule{})
ctx := sdk.NewContext(cms, true, logger)
maccPerms := map[string][]string{

View File

@ -19,7 +19,7 @@ import (
)
func TestMigration(t *testing.T) {
cdc := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}).Codec
cdc := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}).Codec
storeKey := storetypes.NewKVStoreKey("distribution")
storeService := runtime.NewKVStoreService(storeKey)
tKey := storetypes.NewTransientStoreKey("transient_test")

View File

@ -27,10 +27,13 @@ import (
const ConsensusVersion = 4
var (
_ module.AppModuleBasic = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasInvariants = AppModule{}
_ module.HasName = AppModule{}
_ module.HasAminoCodec = AppModule{}
_ module.HasGRPCGateway = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasInvariants = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasBeginBlocker = AppModule{}
@ -38,58 +41,9 @@ var (
_ appmodule.HasMigrations = AppModule{}
)
// AppModuleBasic defines the basic application module used by the distribution module.
type AppModuleBasic struct {
cdc codec.Codec
}
// Name returns the distribution module's name.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the distribution module's types for the given codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// DefaultGenesis returns default genesis state as raw bytes for the distribution
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the distribution module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return types.ValidateGenesis(&data)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the distribution module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the root tx command for the distribution module.
func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
// RegisterInterfaces implements InterfaceModule
func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module for the distribution module.
type AppModule struct {
AppModuleBasic
cdc codec.Codec
keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
@ -103,18 +57,45 @@ func NewAppModule(
bankKeeper types.BankKeeper, stakingKeeper types.StakingKeeper, poolKeeper types.PoolKeeper,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
poolKeeper: poolKeeper,
cdc: cdc,
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
poolKeeper: poolKeeper,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// Name returns the distribution module's name.
func (AppModule) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the distribution module's types for the given codec.
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the distribution module.
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the root tx command for the distribution module.
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
// RegisterInterfaces implements InterfaceModule
func (AppModule) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// RegisterInvariants registers the distribution module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
keeper.RegisterInvariants(ir, am.keeper)
@ -128,6 +109,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
return nil
}
// RegisterMigrations registers the distribution module's migrations.
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
m := keeper.NewMigrator(am.keeper)
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
@ -145,8 +127,22 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
return nil
}
// InitGenesis performs genesis initialization for the distribution module. It returns
// no validator updates.
// DefaultGenesis returns default genesis state as raw bytes for the distribution module.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the distribution module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return types.ValidateGenesis(&data)
}
// InitGenesis performs genesis initialization for the distribution module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
@ -160,7 +156,7 @@ func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json
return cdc.MustMarshalJSON(gs)
}
// ConsensusVersion implements AppModule/ConsensusVersion.
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// BeginBlock returns the begin blocker for the distribution module.

View File

@ -24,7 +24,7 @@ var (
)
func TestDecodeDistributionStore(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
encodingConfig := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{})
cdc := encodingConfig.Codec
dec := simulation.NewDecodeStore(cdc)

View File

@ -6,6 +6,7 @@ import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
eviclient "cosmossdk.io/x/evidence/client"
"cosmossdk.io/x/evidence/keeper"
"cosmossdk.io/x/evidence/types"
@ -26,8 +27,9 @@ func init() {
type ModuleInputs struct {
depinject.In
Environment appmodule.Environment
Cdc codec.Codec
Environment appmodule.Environment
Cdc codec.Codec
EvidenceHandlers []eviclient.EvidenceHandler `optional:"true"`
StakingKeeper types.StakingKeeper
SlashingKeeper types.SlashingKeeper
@ -43,7 +45,7 @@ type ModuleOutputs struct {
func ProvideModule(in ModuleInputs) ModuleOutputs {
k := keeper.NewKeeper(in.Cdc, in.Environment, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec)
m := NewAppModule(*k)
m := NewAppModule(*k, in.EvidenceHandlers...)
return ModuleOutputs{EvidenceKeeper: *k, Module: m}
}

View File

@ -15,11 +15,6 @@ flexibility in designing evidence handling.
A full setup of the evidence module may look something as follows:
ModuleBasics = module.NewBasicManager(
// ...,
evidence.AppModuleBasic{},
)
// First, create the keeper
evidenceKeeper := evidence.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[evidencetypes.StoreKey]),

View File

@ -84,7 +84,7 @@ type KeeperTestSuite struct {
}
func (suite *KeeperTestSuite) SetupTest() {
encCfg := moduletestutil.MakeTestEncodingConfig(evidence.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(evidence.AppModule{})
key := storetypes.NewKVStoreKey(types.StoreKey)
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())
tkey := storetypes.NewTransientStoreKey("evidence_transient_store")
@ -115,7 +115,7 @@ func (suite *KeeperTestSuite) SetupTest() {
evidenceKeeper.SetRouter(router)
suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})
suite.encCfg = moduletestutil.MakeTestEncodingConfig(evidence.AppModuleBasic{})
suite.encCfg = moduletestutil.MakeTestEncodingConfig(evidence.AppModule{})
suite.accountKeeper = accountKeeper

View File

@ -24,67 +24,57 @@ import (
)
var (
_ module.AppModuleBasic = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasName = AppModule{}
_ module.HasAminoCodec = AppModule{}
_ module.HasGRPCGateway = AppModule{}
_ module.HasRegisterInterfaces = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasBeginBlocker = AppModule{}
)
// ----------------------------------------------------------------------------
// AppModuleBasic
// ----------------------------------------------------------------------------
const ConsensusVersion = 1
// AppModuleBasic implements the AppModuleBasic interface for the evidence module.
type AppModuleBasic struct {
evidenceHandlers []eviclient.EvidenceHandler // eviclient evidence submission handlers
// AppModule implements the AppModule interface for the evidence module.
type AppModule struct {
evidenceHandlers []eviclient.EvidenceHandler
keeper keeper.Keeper
}
// NewAppModuleBasic creates a AppModuleBasic without the codec.
func NewAppModuleBasic(evidenceHandlers ...eviclient.EvidenceHandler) AppModuleBasic {
return AppModuleBasic{
// NewAppModule creates a new AppModule object.
func NewAppModule(keeper keeper.Keeper, evidenceHandlers ...eviclient.EvidenceHandler) AppModule {
return AppModule{
keeper: keeper,
evidenceHandlers: evidenceHandlers,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// Name returns the evidence module's name.
func (AppModuleBasic) Name() string {
func (AppModule) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the evidence module's types to the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// DefaultGenesis returns the evidence module's default genesis state.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the evidence module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var gs types.GenesisState
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return gs.Validate()
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the evidence module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the evidence module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
evidenceCLIHandlers := make([]*cobra.Command, len(a.evidenceHandlers))
for i, evidenceHandler := range a.evidenceHandlers {
func (am AppModule) GetTxCmd() *cobra.Command {
evidenceCLIHandlers := make([]*cobra.Command, len(am.evidenceHandlers))
for i, evidenceHandler := range am.evidenceHandlers {
evidenceCLIHandlers[i] = evidenceHandler.CLIHandler()
}
@ -92,32 +82,10 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command {
}
// RegisterInterfaces registers the evidence module's interface types
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------
// AppModule implements the AppModule interface for the evidence module.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
}
// NewAppModule creates a new AppModule object.
func NewAppModule(keeper keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
}
}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
@ -125,8 +93,22 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
return nil
}
// InitGenesis performs the evidence module's genesis initialization It returns
// no validator updates.
// DefaultGenesis returns the evidence module's default genesis state.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the evidence module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var gs types.GenesisState
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return gs.Validate()
}
// InitGenesis performs the evidence module's genesis initialization
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) {
var gs types.GenesisState
err := cdc.UnmarshalJSON(bz, &gs)
@ -142,8 +124,8 @@ func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json
return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper))
}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// BeginBlock executes all ABCI BeginBlock logic respective to the evidence module.
func (am AppModule) BeginBlock(ctx context.Context) error {

View File

@ -61,7 +61,7 @@ func TestCLITestSuite(t *testing.T) {
func (s *CLITestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
s.encCfg = testutilmod.MakeTestEncodingConfig(module.AppModuleBasic{}, gov.AppModule{})
s.encCfg = testutilmod.MakeTestEncodingConfig(module.AppModule{}, gov.AppModule{})
s.kr = keyring.NewInMemory(s.encCfg.Codec)
s.baseCtx = client.Context{}.
WithKeyring(s.kr).
@ -85,15 +85,10 @@ func (s *CLITestSuite) SetupSuite() {
}
s.clientCtx = ctxGen()
if testing.Short() {
s.T().Skip("skipping test in unit-tests mode.")
}
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 2)
granter := accounts[0].Address
grantee := accounts[1].Address
s.createGrant(granter, grantee)
granteeStr, err := s.baseCtx.AddressCodec.BytesToString(grantee)

View File

@ -22,7 +22,7 @@ import (
func TestFilteredFeeValidAllow(t *testing.T) {
key := storetypes.NewKVStoreKey(feegrant.StoreKey)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})

View File

@ -21,7 +21,7 @@ func TestGrant(t *testing.T) {
addressCodec := codecaddress.NewBech32Codec("cosmos")
key := storetypes.NewKVStoreKey(feegrant.StoreKey)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{})
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{})
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})

Some files were not shown because too many files have changed in this diff Show More