refactor: move module cli tests up to simapp (#12718)

## Description

Ref: #11899 

Moves CLI test runners up to simapp while keeping test specification in the module, breaking the dependency from `x/module -> simapp` brought on by the current iteration of CLI / integration / network-backed tests.



---

### 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
- [x] 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)
- [ ] 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
- [x] 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)
This commit is contained in:
Matt Kocubinski
2022-07-26 22:00:54 +00:00
committed by GitHub
parent 2a9731d60f
commit 159ab4f8e8
22 changed files with 78 additions and 58 deletions
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/cosmos/cosmos-sdk/testutil/network"
testutil2 "github.com/cosmos/cosmos-sdk/x/auth/client/testutil"
"github.com/cosmos/cosmos-sdk/x/auth/testutil"
"github.com/stretchr/testify/require"
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 2
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil2.NewIntegrationTestSuite(cfg))
}
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/testutil/network"
testutil2 "github.com/cosmos/cosmos-sdk/x/auth/vesting/client/testutil"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/testutil"
)
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil2.NewIntegrationTestSuite(cfg))
}
@@ -6,14 +6,15 @@ package testutil
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/x/authz/client/testutil"
)
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil.NewIntegrationTestSuite(cfg))
}
@@ -6,14 +6,15 @@ package testutil
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
"github.com/stretchr/testify/suite"
)
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil.NewIntegrationTestSuite(cfg))
}
@@ -1,19 +1,20 @@
//go:build norace
// +build norace
package testutil
package testsuite
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/x/crisis/client/testsuite"
)
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil.NewIntegrationTestSuite(cfg))
}
@@ -4,16 +4,18 @@ import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/x/distribution/client/testutil"
)
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
suite.Run(t, new(testutil.IntegrationTestSuite))
}
func TestGRPCQueryTestSuite(t *testing.T) {
suite.Run(t, new(GRPCQueryTestSuite))
suite.Run(t, new(testutil.GRPCQueryTestSuite))
}
func TestWithdrawAllSuite(t *testing.T) {
suite.Run(t, new(WithdrawAllTestSuite))
suite.Run(t, new(testutil.WithdrawAllTestSuite))
}
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/testutil/network"
testutil2 "github.com/cosmos/cosmos-sdk/x/evidence/client/testutil"
"github.com/cosmos/cosmos-sdk/x/evidence/testutil"
)
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil2.NewIntegrationTestSuite(cfg))
}
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/cosmos/cosmos-sdk/testutil/network"
clienttestutil "github.com/cosmos/cosmos-sdk/x/feegrant/client/testutil"
"github.com/cosmos/cosmos-sdk/x/feegrant/testutil"
"github.com/stretchr/testify/require"
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 3
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg))
}
@@ -6,14 +6,15 @@ package testutil
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"
"github.com/stretchr/testify/suite"
)
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil.NewIntegrationTestSuite(cfg))
}
@@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/stretchr/testify/require"
@@ -16,7 +17,7 @@ import (
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil.NewIntegrationTestSuite(cfg))
dp := v1.NewDepositParams(sdk.NewCoins(sdk.NewCoin(cfg.BondDenom, v1.DefaultMinDepositTokens)), time.Duration(15)*time.Second)
vp := v1.NewVotingParams(time.Duration(5) * time.Second)
@@ -26,5 +27,5 @@ func TestIntegrationTestSuite(t *testing.T) {
bz, err := cfg.Codec.MarshalJSON(genesisState)
require.NoError(t, err)
cfg.GenesisState["gov"] = bz
suite.Run(t, NewDepositTestSuite(cfg))
suite.Run(t, testutil.NewDepositTestSuite(cfg))
}
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/cosmos/cosmos-sdk/testutil/network"
clienttestutil "github.com/cosmos/cosmos-sdk/x/group/client/testutil"
"github.com/cosmos/cosmos-sdk/x/group/testutil"
"github.com/stretchr/testify/require"
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 2
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg))
}
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/testutil/network"
clienttestutil "github.com/cosmos/cosmos-sdk/x/mint/client/testutil"
"github.com/cosmos/cosmos-sdk/x/mint/testutil"
)
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg))
}
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/testutil/network"
clienttestutil "github.com/cosmos/cosmos-sdk/x/nft/client/testutil"
"github.com/cosmos/cosmos-sdk/x/nft/testutil"
)
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg))
}
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/testutil/network"
clienttestutil "github.com/cosmos/cosmos-sdk/x/params/client/testutil"
"github.com/cosmos/cosmos-sdk/x/params/testutil"
)
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg))
}
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/cosmos/cosmos-sdk/testutil/network"
clienttestutil "github.com/cosmos/cosmos-sdk/x/slashing/client/testutil"
"github.com/cosmos/cosmos-sdk/x/slashing/testutil"
"github.com/stretchr/testify/require"
@@ -17,5 +18,5 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig)
require.NoError(t, err)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg))
}
@@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/staking/client/testutil"
"github.com/stretchr/testify/suite"
)
@@ -15,5 +16,5 @@ import (
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 2
suite.Run(t, NewIntegrationTestSuite(cfg))
suite.Run(t, testutil.NewIntegrationTestSuite(cfg))
}
@@ -0,0 +1,25 @@
package testutil
import (
"testing"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/upgrade/client/testutil"
)
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
app.UpgradeKeeper.SetVersionSetter(app.BaseApp)
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
suite.Run(t, testutil.NewIntegrationTestSuite(cfg, app.UpgradeKeeper, ctx))
}
+2 -2
View File
@@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/simapp"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli"
@@ -106,7 +106,7 @@ func (s *IntegrationTestSuite) TestGenTxCmd() {
s.Run(tc.name, func() {
cmd := cli.GenTxCmd(
simapp.ModuleBasics,
module.NewBasicManager(),
val.ClientCtx.TxConfig,
banktypes.GenesisBalancesIterator{},
val.ClientCtx.HomeDir)
-16
View File
@@ -1,16 +0,0 @@
package testutil
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
)
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}
+6 -12
View File
@@ -4,9 +4,7 @@ import (
"fmt"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/simapp"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -15,8 +13,12 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
)
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
return &IntegrationTestSuite{cfg: cfg}
func NewIntegrationTestSuite(cfg network.Config, keeper keeper.Keeper, ctx sdk.Context) *IntegrationTestSuite {
return &IntegrationTestSuite{
cfg: cfg,
upgradeKeeper: keeper,
ctx: ctx,
}
}
type IntegrationTestSuite struct {
@@ -31,14 +33,6 @@ type IntegrationTestSuite struct {
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
app := simapp.Setup(s.T(), false)
s.upgradeKeeper = app.UpgradeKeeper
s.ctx = app.BaseApp.NewContext(false, tmproto.Header{})
s.upgradeKeeper.SetVersionSetter(app.BaseApp)
s.upgradeKeeper.SetModuleVersionMap(s.ctx, app.ModuleManager.GetVersionMap())
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)