Make integration test suites reusable by apps (#6711)
* WIP on refactoring new integration tests.
* godocs
* godocs
* Fix ineff assign
* Updates
* Updates
* fix test
* refactor crisis, distr testsuites
* fix import issue
* refactor x/auth
* refactor x/authz
* refactor x/evidence
* refactor x/feegrant
* refactor x/genutil
* refactor x/gov
* refactor x/mint
* refactor x/params
* refactor x/{auth_vesting, slashing, staking}
* fix lint
* fix tests & lint
* fix lint
* fix tests
* lint
* lint
* fix lint memory
* add missing `norace` build flag
* update feegrant cfg
* fix lint
Co-authored-by: atheesh <atheesh@vitwit.com>
Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
This commit is contained in:
co-authored by
atheesh
atheeshp
parent
5ea817a6fb
commit
3c65c3dacd
@@ -1,97 +0,0 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) SetupSuite() {
|
||||
s.T().Log("setting up integration test suite")
|
||||
|
||||
cfg := network.DefaultConfig()
|
||||
cfg.NumValidators = 1
|
||||
|
||||
s.cfg = cfg
|
||||
s.network = network.New(s.T(), cfg)
|
||||
|
||||
_, err := s.network.WaitForHeight(1)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down integration test suite")
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGenTxCmd() {
|
||||
val := s.network.Validators[0]
|
||||
dir := s.T().TempDir()
|
||||
|
||||
cmd := cli.GenTxCmd(
|
||||
simapp.ModuleBasics,
|
||||
val.ClientCtx.TxConfig, banktypes.GenesisBalancesIterator{}, val.ClientCtx.HomeDir)
|
||||
|
||||
_, out := testutil.ApplyMockIO(cmd)
|
||||
clientCtx := val.ClientCtx.WithOutput(out)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
|
||||
amount := sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(12))
|
||||
genTxFile := filepath.Join(dir, "myTx")
|
||||
cmd.SetArgs([]string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, genTxFile),
|
||||
val.Moniker,
|
||||
amount.String(),
|
||||
})
|
||||
|
||||
err := cmd.ExecuteContext(ctx)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// validate generated transaction.
|
||||
open, err := os.Open(genTxFile)
|
||||
s.Require().NoError(err)
|
||||
|
||||
all, err := ioutil.ReadAll(open)
|
||||
s.Require().NoError(err)
|
||||
|
||||
tx, err := val.ClientCtx.TxConfig.TxJSONDecoder()(all)
|
||||
s.Require().NoError(err)
|
||||
|
||||
msgs := tx.GetMsgs()
|
||||
s.Require().Len(msgs, 1)
|
||||
|
||||
s.Require().Equal(types.TypeMsgCreateValidator, msgs[0].Type())
|
||||
s.Require().Equal([]sdk.AccAddress{val.Address}, msgs[0].GetSigners())
|
||||
s.Require().Equal(amount, msgs[0].(*types.MsgCreateValidator).Value)
|
||||
err = tx.ValidateBasic()
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||
)
|
||||
|
||||
func TestGetMigrationCallback(t *testing.T) {
|
||||
for _, version := range cli.GetMigrationVersions() {
|
||||
require.NotNil(t, cli.GetMigrationCallback(version))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestMigrateGenesis() {
|
||||
val0 := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
genesis string
|
||||
target string
|
||||
expErr bool
|
||||
expErrMsg string
|
||||
check func(jsonOut string)
|
||||
}{
|
||||
{
|
||||
"migrate 0.34 to 0.36",
|
||||
`{"chain_id":"test","app_state":{}}`,
|
||||
"v0.36",
|
||||
false, "", func(_ string) {},
|
||||
},
|
||||
{
|
||||
"migrate 0.37 to 0.42",
|
||||
v037Exported,
|
||||
"v0.42",
|
||||
true, "Make sure that you have correctly migrated all Tendermint consensus params", func(_ string) {},
|
||||
},
|
||||
{
|
||||
"migrate 0.42 to 0.43",
|
||||
v040Valid,
|
||||
"v0.43",
|
||||
false, "",
|
||||
func(jsonOut string) {
|
||||
// Make sure the json output contains the ADR-037 gov weighted votes.
|
||||
s.Require().Contains(jsonOut, "\"weight\":\"1.000000000000000000\"")
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis)
|
||||
jsonOutput, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.MigrateGenesisCmd(), []string{tc.target, genesisFile.Name()})
|
||||
if tc.expErr {
|
||||
s.Require().Contains(err.Error(), tc.expErrMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
tc.check(jsonOutput.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||
)
|
||||
|
||||
// An example exported genesis file from a 0.37 chain. Note that evidence
|
||||
// parameters only contains `max_age`.
|
||||
var v037Exported = `{
|
||||
"app_hash": "",
|
||||
"app_state": {},
|
||||
"chain_id": "test",
|
||||
"consensus_params": {
|
||||
"block": {
|
||||
"max_bytes": "22020096",
|
||||
"max_gas": "-1",
|
||||
"time_iota_ms": "1000"
|
||||
},
|
||||
"evidence": { "max_age": "100000" },
|
||||
"validator": { "pub_key_types": ["ed25519"] }
|
||||
},
|
||||
"genesis_time": "2020-09-29T20:16:29.172362037Z",
|
||||
"validators": []
|
||||
}`
|
||||
|
||||
// An example exported genesis file that's 0.40 compatible.
|
||||
// We added the following app_state:
|
||||
//
|
||||
// - x/gov: added votes to test ADR-037 split votes migration.
|
||||
var v040Valid = `{
|
||||
"app_hash": "",
|
||||
"app_state": {
|
||||
"gov": {
|
||||
"starting_proposal_id": "0",
|
||||
"deposits": [],
|
||||
"votes": [
|
||||
{
|
||||
"proposal_id": "5",
|
||||
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh",
|
||||
"option": "VOTE_OPTION_YES"
|
||||
}
|
||||
],
|
||||
"proposals": [],
|
||||
"deposit_params": { "min_deposit": [], "max_deposit_period": "0s" },
|
||||
"voting_params": { "voting_period": "0s" },
|
||||
"tally_params": { "quorum": "0", "threshold": "0", "veto_threshold": "0" }
|
||||
}
|
||||
},
|
||||
"chain_id": "test",
|
||||
"consensus_params": {
|
||||
"block": {
|
||||
"max_bytes": "22020096",
|
||||
"max_gas": "-1",
|
||||
"time_iota_ms": "1000"
|
||||
},
|
||||
"evidence": {
|
||||
"max_age_num_blocks": "100000",
|
||||
"max_age_duration": "172800000000000",
|
||||
"max_bytes": "0"
|
||||
},
|
||||
"validator": { "pub_key_types": ["ed25519"] }
|
||||
},
|
||||
"genesis_time": "2020-09-29T20:16:29.172362037Z",
|
||||
"validators": []
|
||||
}`
|
||||
|
||||
func (s *IntegrationTestSuite) TestValidateGenesis() {
|
||||
val0 := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
genesis string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
"exported 0.37 genesis file",
|
||||
v037Exported,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid 0.40 genesis file",
|
||||
v040Valid,
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis)
|
||||
_, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.ValidateGenesisCmd(nil), []string{genesisFile.Name()})
|
||||
if tc.expErr {
|
||||
s.Require().Contains(err.Error(), "Make sure that you have correctly migrated all Tendermint consensus params")
|
||||
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user