Skip to content

Commit

Permalink
feat: add x/nft app wiring integration tests (#12220)
Browse files Browse the repository at this point in the history
* feat: add x/nft app wiring integration tests

* updates

* feedback
  • Loading branch information
julienrbrt committed Jun 10, 2022
1 parent 7688ce6 commit 8111a05
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion simapp/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ modules:

- name: genutil
config:
"@type": cosmos.genutil.module.v1.Module
"@type": cosmos.genutil.module.v1.Module
35 changes: 35 additions & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion x/nft/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
46 changes: 46 additions & 0 deletions x/nft/testutil/app.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions x/nft/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 8111a05

Please sign in to comment.