From 8111a055943837af0301a89cd738758fb0f6d99f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Jun 2022 16:13:32 +0200 Subject: [PATCH] feat: add x/nft app wiring integration tests (#12220) * feat: add x/nft app wiring integration tests * updates * feedback --- simapp/app.yaml | 2 +- testutil/network/network.go | 35 +++++++++++++++++++++++ x/nft/client/testutil/cli_test.go | 6 +++- x/nft/testutil/app.yaml | 46 +++++++++++++++++++++++++++++++ x/nft/testutil/app_config.go | 12 ++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 x/nft/testutil/app.yaml create mode 100644 x/nft/testutil/app_config.go diff --git a/simapp/app.yaml b/simapp/app.yaml index a522ff08e6dd..2403357bb910 100644 --- a/simapp/app.yaml +++ b/simapp/app.yaml @@ -114,4 +114,4 @@ modules: - name: genutil config: - "@type": cosmos.genutil.module.v1.Module \ No newline at end of file + "@type": cosmos.genutil.module.v1.Module diff --git a/testutil/network/network.go b/testutil/network/network.go index 815117cca1a9..adbc6b391b49 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -33,7 +33,9 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/depinject" pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" srvconfig "github.com/cosmos/cosmos-sdk/server/config" @@ -128,6 +130,39 @@ func DefaultConfig() Config { } } +func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { + cfg := DefaultConfig() + var appBuilder *runtime.AppBuilder + var msgServiceRouter *baseapp.MsgServiceRouter + + if err := depinject.Inject(appConfig, + &appBuilder, + &msgServiceRouter, + ); err != nil { + return Config{}, err + } + + cfg.GenesisState = appBuilder.DefaultGenesis() + cfg.AppConstructor = func(val Validator) servertypes.Application { + app := appBuilder.Build( + val.Ctx.Logger, + dbm.NewMemDB(), + nil, + msgServiceRouter, + baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), + baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), + ) + + if err := app.Load(true); err != nil { + panic(err) + } + + return app + } + + return cfg, nil +} + type ( // Network defines a local in-process testing network using SimApp. It can be // configured to start any number of validators, each with its own RPC and API diff --git a/x/nft/client/testutil/cli_test.go b/x/nft/client/testutil/cli_test.go index 7f92bbeeff55..12544d34a846 100644 --- a/x/nft/client/testutil/cli_test.go +++ b/x/nft/client/testutil/cli_test.go @@ -1,15 +1,19 @@ package testutil import ( + _ "embed" "testing" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/x/nft/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)) } diff --git a/x/nft/testutil/app.yaml b/x/nft/testutil/app.yaml new file mode 100644 index 000000000000..ff5f3ffc9b23 --- /dev/null +++ b/x/nft/testutil/app.yaml @@ -0,0 +1,46 @@ +modules: + - name: runtime + config: + "@type": cosmos.app.runtime.v1alpha1.Module + + app_name: NftApp + + begin_blockers: [staking, auth, bank, genutil, nft, params] + end_blockers: [staking, auth, bank, genutil, nft, params] + init_genesis: [auth, bank, staking, genutil, nft, 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] + - account: nft + + - 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: nft + config: + "@type": cosmos.nft.module.v1.Module + + - name: staking + config: + "@type": cosmos.staking.module.v1.Module + + - name: genutil + config: + "@type": cosmos.genutil.module.v1.Module diff --git a/x/nft/testutil/app_config.go b/x/nft/testutil/app_config.go new file mode 100644 index 000000000000..1f01697aa019 --- /dev/null +++ b/x/nft/testutil/app_config.go @@ -0,0 +1,12 @@ +package testutil + +import ( + _ "embed" + + "cosmossdk.io/core/appconfig" +) + +//go:embed app.yaml +var appConfig []byte + +var AppConfig = appconfig.LoadYAML(appConfig)