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:
Aaron Craelius
2021-04-23 14:49:49 -04:00
committed by GitHub
co-authored by atheesh atheeshp
parent 5ea817a6fb
commit 3c65c3dacd
32 changed files with 616 additions and 424 deletions
+3 -3
View File
@@ -756,15 +756,15 @@ func (s *IntegrationTestSuite) TestQueryHistoricalInfoGRPC() {
resp, err := rest.GetRequest(tc.url)
s.Require().NoError(err)
var historical_info types.QueryHistoricalInfoResponse
var historicalInfo types.QueryHistoricalInfoResponse
err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, &historical_info)
err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, &historicalInfo)
if tc.error {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NotNil(historical_info)
s.Require().NotNil(historicalInfo)
}
})
}
+17
View File
@@ -0,0 +1,17 @@
// +build norace
package testutil
import (
"testing"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/stretchr/testify/suite"
)
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 2
suite.Run(t, NewIntegrationTestSuite(cfg))
}
@@ -1,6 +1,4 @@
// +build norace
package cli_test
package testutil
import (
"context"
@@ -24,7 +22,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/query"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/client/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -35,6 +32,10 @@ type IntegrationTestSuite struct {
network *network.Network
}
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
return &IntegrationTestSuite{cfg: cfg}
}
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
@@ -42,8 +43,6 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.T().Skip("skipping test in unit-tests mode.")
}
s.cfg = network.DefaultConfig()
s.cfg.NumValidators = 2
s.network = network.New(s.T(), s.cfg)
_, err := s.network.WaitForHeight(1)
@@ -56,7 +55,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
val2 := s.network.Validators[1]
// redelegate
_, err = stakingtestutil.MsgRedelegateExec(
_, err = MsgRedelegateExec(
val.ClientCtx,
val.Address,
val.ValAddress,
@@ -68,7 +67,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
// unbonding
_, err = stakingtestutil.MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbond)
_, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbond)
s.Require().NoError(err)
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
@@ -106,8 +105,8 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
name string
args []string
expectErr bool
respType proto.Message
expectedCode uint32
respType proto.Message
}{
{
"invalid transaction (missing amount)",
@@ -125,7 +124,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"invalid transaction (missing pubkey)",
@@ -144,7 +143,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"invalid transaction (missing moniker)",
@@ -164,7 +163,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"valid transaction",
@@ -185,7 +184,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
}
@@ -844,11 +843,11 @@ func (s *IntegrationTestSuite) TestGetCmdQueryHistoricalInfo() {
if tc.error {
s.Require().Error(err)
} else {
var historical_info types.HistoricalInfo
var historicalInfo types.HistoricalInfo
err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &historical_info)
err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &historicalInfo)
s.Require().NoError(err)
s.Require().NotNil(historical_info)
s.Require().NotNil(historicalInfo)
}
})
}
@@ -938,8 +937,8 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
name string
args []string
expectErr bool
respType proto.Message
expectedCode uint32
respType proto.Message
}{
{
"with no edit flag (since all are optional)",
@@ -949,7 +948,7 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"with no edit flag (since all are optional)",
@@ -959,7 +958,7 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
{
"edit validator details",
@@ -970,7 +969,7 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
{
"edit validator identity",
@@ -981,7 +980,7 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
{
"edit validator security-contact",
@@ -992,7 +991,7 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
{
"edit validator website",
@@ -1003,7 +1002,7 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
{
"with all edit flags",
@@ -1017,7 +1016,7 @@ func (s *IntegrationTestSuite) TestNewCmdEditValidator() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
}
@@ -1064,8 +1063,8 @@ func (s *IntegrationTestSuite) TestNewCmdDelegate() {
name string
args []string
expectErr bool
respType proto.Message
expectedCode uint32
respType proto.Message
}{
{
"without delegate amount",
@@ -1076,7 +1075,7 @@ func (s *IntegrationTestSuite) TestNewCmdDelegate() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"without validator address",
@@ -1087,7 +1086,7 @@ func (s *IntegrationTestSuite) TestNewCmdDelegate() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"valid transaction of delegate",
@@ -1099,7 +1098,7 @@ func (s *IntegrationTestSuite) TestNewCmdDelegate() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
}
@@ -1132,8 +1131,8 @@ func (s *IntegrationTestSuite) TestNewCmdRedelegate() {
name string
args []string
expectErr bool
respType proto.Message
expectedCode uint32
respType proto.Message
}{
{
"without amount",
@@ -1145,7 +1144,7 @@ func (s *IntegrationTestSuite) TestNewCmdRedelegate() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"with wrong source validator address",
@@ -1158,7 +1157,7 @@ func (s *IntegrationTestSuite) TestNewCmdRedelegate() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 4,
false, 4, &sdk.TxResponse{},
},
{
"with wrong destination validator address",
@@ -1171,7 +1170,7 @@ func (s *IntegrationTestSuite) TestNewCmdRedelegate() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 39,
false, 39, &sdk.TxResponse{},
},
{
"valid transaction of delegate",
@@ -1185,7 +1184,7 @@ func (s *IntegrationTestSuite) TestNewCmdRedelegate() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
}
@@ -1217,8 +1216,8 @@ func (s *IntegrationTestSuite) TestNewCmdUnbond() {
name string
args []string
expectErr bool
respType proto.Message
expectedCode uint32
respType proto.Message
}{
{
"Without unbond amount",
@@ -1229,7 +1228,7 @@ func (s *IntegrationTestSuite) TestNewCmdUnbond() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"Without validator address",
@@ -1240,7 +1239,7 @@ func (s *IntegrationTestSuite) TestNewCmdUnbond() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
true, nil, 0,
true, 0, nil,
},
{
"valid transaction of unbond",
@@ -1252,7 +1251,7 @@ func (s *IntegrationTestSuite) TestNewCmdUnbond() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, &sdk.TxResponse{}, 0,
false, 0, &sdk.TxResponse{},
},
}
@@ -1316,6 +1315,7 @@ func (s *IntegrationTestSuite) TestBlockResults() {
// Create a HTTP rpc client.
rpcClient, err := http.New(val.RPCAddress, "/websocket")
require.NoError(err)
// Loop until we find a block result with the correct validator updates.
// By experience, it happens around 2 blocks after `delHeight`.
@@ -1345,7 +1345,3 @@ func (s *IntegrationTestSuite) TestBlockResults() {
s.network.WaitForNextBlock()
}
}
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}