From bfb91ab7bc9f8127f6972caf6d04434e37818472 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Wed, 15 Jun 2022 11:01:27 +0530 Subject: [PATCH] feat: add x/group app wiring integration tests (#12243) ## Description ref: #12024 --- ### 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... - [ ] 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 - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] 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) - [ ] 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 - [ ] 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) --- runtime/app.go | 1 + runtime/builder.go | 3 +- runtime/module.go | 7 +++-- simapp/app.go | 4 +-- testutil/network/network.go | 15 +++++---- testutil/sims/app_helpers.go | 6 ++-- x/group/client/testutil/cli_test.go | 5 ++- x/group/testutil/app.yaml | 49 +++++++++++++++++++++++++++++ x/group/testutil/app_config.go | 20 ++++++++++++ 9 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 x/group/testutil/app.yaml create mode 100644 x/group/testutil/app_config.go diff --git a/runtime/app.go b/runtime/app.go index 504e26b1ef..2ceb7cd3ee 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -45,6 +45,7 @@ type App struct { beginBlockers []func(sdk.Context, abci.RequestBeginBlock) endBlockers []func(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate baseAppOptions []BaseAppOption + msgServiceRouter *baseapp.MsgServiceRouter } // RegisterModules registers the provided modules with the module manager and diff --git a/runtime/builder.go b/runtime/builder.go index d5032a0ca4..f73805c17c 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -29,7 +29,6 @@ func (a *AppBuilder) Build( logger log.Logger, db dbm.DB, traceStore io.Writer, - msgServiceRouter *baseapp.MsgServiceRouter, baseAppOptions ...func(*baseapp.BaseApp), ) *App { for _, option := range a.app.baseAppOptions { @@ -37,7 +36,7 @@ func (a *AppBuilder) Build( } bApp := baseapp.NewBaseApp(a.app.config.AppName, logger, db, nil, baseAppOptions...) - bApp.SetMsgServiceRouter(msgServiceRouter) + bApp.SetMsgServiceRouter(a.app.msgServiceRouter) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(a.app.interfaceRegistry) diff --git a/runtime/module.go b/runtime/module.go index f7e26ba1df..fe598f22ee 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -3,6 +3,8 @@ package runtime import ( "fmt" + abci "github.com/tendermint/tendermint/abci/types" + runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/baseapp" @@ -12,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/std" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/module" - abci "github.com/tendermint/tendermint/abci/types" ) // BaseAppOption is a depinject.AutoGroupType which can be used to pass @@ -62,15 +63,17 @@ func provideCodecs(moduleBasics map[string]AppModuleBasicWrapper) ( std.RegisterLegacyAminoCodec(amino) cdc := codec.NewProtoCodec(interfaceRegistry) + msgServiceRouter := baseapp.NewMsgServiceRouter() app := &App{ storeKeys: nil, interfaceRegistry: interfaceRegistry, cdc: cdc, amino: amino, basicManager: basicManager, + msgServiceRouter: msgServiceRouter, } - return interfaceRegistry, cdc, amino, app, cdc, baseapp.NewMsgServiceRouter() + return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter } type appInputs struct { diff --git a/simapp/app.go b/simapp/app.go index 94b931f789..e3e7cfa5de 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -210,7 +210,6 @@ func NewSimApp( } var appBuilder *runtime.AppBuilder - var msgServiceRouter *baseapp.MsgServiceRouter if err := depinject.Inject(AppConfig, &appBuilder, @@ -229,12 +228,11 @@ func NewSimApp( &app.SlashingKeeper, &app.MintKeeper, &app.EvidenceKeeper, - &msgServiceRouter, ); err != nil { panic(err) } - app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...) + app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) app.keys = sdk.NewKVStoreKeys( distrtypes.StoreKey, diff --git a/testutil/network/network.go b/testutil/network/network.go index 95202486e4..c335a78d3b 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -25,6 +25,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" @@ -135,35 +136,37 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { var ( appBuilder *runtime.AppBuilder - msgServiceRouter *baseapp.MsgServiceRouter txConfig client.TxConfig legacyAmino *codec.LegacyAmino - codec codec.Codec + cdc codec.Codec interfaceRegistry codectypes.InterfaceRegistry ) if err := depinject.Inject(appConfig, &appBuilder, - &msgServiceRouter, &txConfig, - &codec, + &cdc, &legacyAmino, &interfaceRegistry, ); err != nil { return Config{}, err } - cfg.Codec = codec + cfg.Codec = cdc cfg.TxConfig = txConfig cfg.LegacyAmino = legacyAmino cfg.InterfaceRegistry = interfaceRegistry cfg.GenesisState = appBuilder.DefaultGenesis() cfg.AppConstructor = func(val Validator) servertypes.Application { + // we build a unique app instance for every validator here + var appBuilder *runtime.AppBuilder + if err := depinject.Inject(appConfig, &appBuilder); err != nil { + panic(err) + } app := appBuilder.Build( val.Ctx.Logger, dbm.NewMemDB(), nil, - msgServiceRouter, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), ) diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 01b1f336bc..be27dc96ed 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -13,7 +13,6 @@ import ( tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -54,17 +53,16 @@ func Setup(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.Ap // create app // var appBuilder *runtime.AppBuilder - var msgServiceRouter *baseapp.MsgServiceRouter var codec codec.Codec if err := depinject.Inject( appConfig, - append(extraOutputs, &appBuilder, &msgServiceRouter, &codec)..., + append(extraOutputs, &appBuilder, &codec)..., ); err != nil { return nil, fmt.Errorf("failed to inject dependencies: %w", err) } - app := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil, msgServiceRouter) + app := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) if err := app.Load(true); err != nil { return nil, fmt.Errorf("failed to load app: %w", err) } diff --git a/x/group/client/testutil/cli_test.go b/x/group/client/testutil/cli_test.go index f23e88847c..be88858caf 100644 --- a/x/group/client/testutil/cli_test.go +++ b/x/group/client/testutil/cli_test.go @@ -7,12 +7,15 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/x/group/testutil" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) func TestIntegrationTestSuite(t *testing.T) { - cfg := network.DefaultConfig() + cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig) + require.NoError(t, err) cfg.NumValidators = 2 suite.Run(t, NewIntegrationTestSuite(cfg)) } diff --git a/x/group/testutil/app.yaml b/x/group/testutil/app.yaml new file mode 100644 index 0000000000..251759067b --- /dev/null +++ b/x/group/testutil/app.yaml @@ -0,0 +1,49 @@ +modules: + - name: runtime + config: + "@type": cosmos.app.runtime.v1alpha1.Module + + app_name: GroupApp + + begin_blockers: [staking, auth, bank, genutil, authz, group, params] + end_blockers: [staking, auth, bank, genutil, authz, group, params] + init_genesis: [auth, bank, staking, genutil, authz, group, params] + + - name: auth + config: + "@type": cosmos.auth.module.v1.Module + bech32_prefix: cosmos + module_account_permissions: + - account: fee_collector + - 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: authz + config: + "@type": cosmos.authz.module.v1.Module + + - name: group + config: + "@type": cosmos.group.v1.module.v1.Module + + - name: genutil + config: + "@type": cosmos.genutil.module.v1.Module \ No newline at end of file diff --git a/x/group/testutil/app_config.go b/x/group/testutil/app_config.go new file mode 100644 index 0000000000..8e7129635d --- /dev/null +++ b/x/group/testutil/app_config.go @@ -0,0 +1,20 @@ +package testutil + +import ( + _ "embed" + + "cosmossdk.io/core/appconfig" + _ "github.com/cosmos/cosmos-sdk/x/auth" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" + _ "github.com/cosmos/cosmos-sdk/x/authz" + _ "github.com/cosmos/cosmos-sdk/x/bank" + _ "github.com/cosmos/cosmos-sdk/x/genutil" + _ "github.com/cosmos/cosmos-sdk/x/group" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" +) + +//go:embed app.yaml +var appConfig []byte + +var AppConfig = appconfig.LoadYAML(appConfig)