Skip to content

Commit

Permalink
Make integration test suites reusable by apps (#6711)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: atheeshp <[email protected]>
  • Loading branch information
3 people authored Apr 23, 2021
1 parent 5ea817a commit 3c65c3d
Show file tree
Hide file tree
Showing 32 changed files with 616 additions and 424 deletions.
17 changes: 17 additions & 0 deletions x/auth/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
137 changes: 67 additions & 70 deletions x/auth/client/cli/cli_test.go → x/auth/client/testutil/suite.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions x/auth/vesting/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -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 = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// +build norace

package cli_test
package testutil

import (
"fmt"
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
Expand All @@ -23,14 +20,14 @@ 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")

cfg := network.DefaultConfig()
cfg.NumValidators = 1

s.cfg = cfg
s.network = network.New(s.T(), cfg)
s.network = network.New(s.T(), s.cfg)

_, err := s.network.WaitForHeight(1)
s.Require().NoError(err)
Expand All @@ -47,8 +44,8 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() {
testCases := map[string]struct {
args []string
expectErr bool
respType proto.Message
expectedCode uint32
respType proto.Message
}{
"create a continuous vesting account": {
args: []string{
Expand All @@ -61,8 +58,8 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
respType: &sdk.TxResponse{},
expectedCode: 0,
respType: &sdk.TxResponse{},
},
"create a delayed vesting account": {
args: []string{
Expand All @@ -76,8 +73,8 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
expectErr: false,
respType: &sdk.TxResponse{},
expectedCode: 0,
respType: &sdk.TxResponse{},
},
"invalid address": {
args: []string{
Expand All @@ -87,8 +84,8 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() {
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
},
expectErr: true,
respType: &sdk.TxResponse{},
expectedCode: 0,
respType: &sdk.TxResponse{},
},
"invalid coins": {
args: []string{
Expand All @@ -98,8 +95,8 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() {
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
},
expectErr: true,
respType: &sdk.TxResponse{},
expectedCode: 0,
respType: &sdk.TxResponse{},
},
"invalid end time": {
args: []string{
Expand All @@ -109,8 +106,8 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() {
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address),
},
expectErr: true,
respType: &sdk.TxResponse{},
expectedCode: 0,
respType: &sdk.TxResponse{},
},
}

Expand All @@ -133,7 +130,3 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() {
})
}
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
17 changes: 17 additions & 0 deletions x/authz/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -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 = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// +build norace

package cli_test
package testutil

import (
"fmt"
Expand All @@ -14,7 +12,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz/client/cli"

authztestutil "github.com/cosmos/cosmos-sdk/x/authz/client/testutil"
"github.com/cosmos/cosmos-sdk/x/authz/types"
)

Expand All @@ -24,7 +21,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() {
grantee := s.grantee
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

_, err := authztestutil.ExecGrantAuthorization(
_, err := ExecGrantAuthorization(
val,
[]string{
grantee.String(),
Expand Down Expand Up @@ -102,7 +99,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorization() {
grantee := s.grantee
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

_, err := authztestutil.ExecGrantAuthorization(
_, err := ExecGrantAuthorization(
val,
[]string{
grantee.String(),
Expand Down
Loading

0 comments on commit 3c65c3d

Please sign in to comment.