Skip to content

Commit

Permalink
feat: migrate x/mint to use app wiring (#12235)
Browse files Browse the repository at this point in the history
## Description

Implements 2/3 from #12234



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
julienrbrt authored Jun 13, 2022
1 parent 7feae9c commit 82412af
Show file tree
Hide file tree
Showing 8 changed files with 636 additions and 13 deletions.
501 changes: 501 additions & 0 deletions api/cosmos/mint/module/v1/module.pulsar.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions proto/cosmos/mint/module/v1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

package cosmos.mint.module.v1;

import "cosmos/app/v1alpha1/module.proto";

// Module is the config object of the mint module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/cosmos/cosmos-sdk/x/mint"
};
}
12 changes: 4 additions & 8 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func NewSimApp(
&app.StakingKeeper,
&app.NFTKeeper,
&app.SlashingKeeper,
&app.MintKeeper,
&msgServiceRouter,
); err != nil {
panic(err)
Expand All @@ -234,8 +235,9 @@ func NewSimApp(
app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...)

app.keys = sdk.NewKVStoreKeys(
minttypes.StoreKey, distrtypes.StoreKey,
govtypes.StoreKey, upgradetypes.StoreKey,
distrtypes.StoreKey,
govtypes.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
group.StoreKey,
)
Expand All @@ -251,10 +253,6 @@ func NewSimApp(

initParamsKeeper(app.ParamsKeeper)

app.MintKeeper = mintkeeper.NewKeeper(
app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), app.StakingKeeper,
app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
)
app.DistrKeeper = distrkeeper.NewKeeper(
app.appCodec, app.keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
app.StakingKeeper, authtypes.FeeCollectorName,
Expand Down Expand Up @@ -317,7 +315,6 @@ func NewSimApp(
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil),
distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
Expand Down Expand Up @@ -503,7 +500,6 @@ func GetMaccPerms() map[string][]string {

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(paramsKeeper paramskeeper.Keeper) {
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
Expand Down
4 changes: 4 additions & 0 deletions simapp/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ modules:
- name: genutil
config:
"@type": cosmos.genutil.module.v1.Module

- name: mint
config:
"@type": cosmos.mint.module.v1.Module
9 changes: 6 additions & 3 deletions x/mint/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ package testutil
import (
"testing"

"github.com/cosmos/cosmos-sdk/testutil/network"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/mint/testutil"
)

func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}
52 changes: 50 additions & 2 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import (
"fmt"
"math/rand"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

"cosmossdk.io/core/appmodule"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/depinject"
"github.com/cosmos/cosmos-sdk/runtime"
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

modulev1 "cosmossdk.io/api/cosmos/mint/module/v1"
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
"github.com/cosmos/cosmos-sdk/x/mint/simulation"
Expand Down Expand Up @@ -63,7 +71,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
Expand Down Expand Up @@ -187,3 +195,43 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}

//
// New App Wiring Setup
//

func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(provideModuleBasic, provideModule),
)
}

func provideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type mintInputs struct {
depinject.In

Key *store.KVStoreKey
Cdc codec.Codec
Subspace paramstypes.Subspace

AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
StakingKeeper types.StakingKeeper
}

type mintOutputs struct {
depinject.Out

MintKeeper keeper.Keeper
Module runtime.AppModuleWrapper
}

func provideModule(in mintInputs) mintOutputs {
k := keeper.NewKeeper(in.Cdc, in.Key, in.Subspace, in.StakingKeeper, in.AccountKeeper, in.BankKeeper, authtypes.FeeCollectorName)
m := NewAppModule(in.Cdc, k, in.AccountKeeper, nil)

return mintOutputs{MintKeeper: k, Module: runtime.WrapAppModule(m)}
}
47 changes: 47 additions & 0 deletions x/mint/testutil/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
modules:
- name: runtime
config:
"@type": cosmos.app.runtime.v1alpha1.Module

app_name: MintApp

begin_blockers: [staking, auth, bank, mint, genutil, params]
end_blockers: [staking, auth, bank, mint, genutil, params]
init_genesis: [auth, bank, staking, mint, genutil, params]

- name: auth
config:
"@type": cosmos.auth.module.v1.Module
bech32_prefix: cosmos
module_account_permissions:
- account: fee_collector
- account: mint
permissions: [minter]
- account: bonded_tokens_pool
permissions: [burner, staking]
- account: not_bonded_tokens_pool
permissions: [burner, staking]

- name: bank
config:
"@type": cosmos.bank.module.v1.Module

- name: params
config:
"@type": cosmos.params.module.v1.Module

- name: tx
config:
"@type": cosmos.tx.module.v1.Module

- name: staking
config:
"@type": cosmos.staking.module.v1.Module

- name: genutil
config:
"@type": cosmos.genutil.module.v1.Module

- name: mint
config:
"@type": cosmos.mint.module.v1.Module
12 changes: 12 additions & 0 deletions x/mint/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package testutil

import (
_ "embed"

"cosmossdk.io/core/appconfig"
)

//go:embed app.yaml
var appConfig []byte

var AppConfig = appconfig.LoadYAML(appConfig)

0 comments on commit 82412af

Please sign in to comment.