Skip to content

Commit

Permalink
refactor: x/bank integration and e2e tests (#12779)
Browse files Browse the repository at this point in the history
* retain x/bank integration tests

* Move bank end to end tests

* refactor: move bank e2e tests and move common code to testutil/cli/cmd.go

* refactor x/bank integration tests to remove simapp dep
  • Loading branch information
kocubinski authored Aug 2, 2022
1 parent f002e54 commit 0f7e56c
Show file tree
Hide file tree
Showing 13 changed files with 1,791 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
//go:build e2e
// +build e2e

package testutil
package client

import (
"testing"

"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, testutil.NewIntegrationTestSuite(cfg))
suite.Run(t, NewEndToEndTestSuite(cfg))
}
11 changes: 6 additions & 5 deletions x/bank/client/testutil/grpc.go → tests/e2e/bank/client/grpc.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package testutil
package client

import (
"fmt"

"cosmossdk.io/math"
"github.com/gogo/protobuf/proto"

"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/rest"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -14,7 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

func (s *IntegrationTestSuite) TestTotalSupplyGRPCHandler() {
func (s *EndToEndTestSuite) TestTotalSupplyGRPCHandler() {
val := s.network.Validators[0]
baseURL := val.APIAddress

Expand Down Expand Up @@ -100,7 +101,7 @@ func (s *IntegrationTestSuite) TestTotalSupplyGRPCHandler() {
}
}

func (s *IntegrationTestSuite) TestDenomMetadataGRPCHandler() {
func (s *EndToEndTestSuite) TestDenomMetadataGRPCHandler() {
val := s.network.Validators[0]
baseURL := val.APIAddress

Expand Down Expand Up @@ -225,7 +226,7 @@ func (s *IntegrationTestSuite) TestDenomMetadataGRPCHandler() {
}
}

func (s *IntegrationTestSuite) TestBalancesGRPCHandler() {
func (s *EndToEndTestSuite) TestBalancesGRPCHandler() {
val := s.network.Validators[0]
baseURL := val.APIAddress

Expand Down
49 changes: 32 additions & 17 deletions x/bank/client/testutil/suite.go → tests/e2e/bank/client/suite.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package testutil
package client

import (
"fmt"
"io/ioutil"
"os"

"cosmossdk.io/math"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/testutil"

"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
Expand All @@ -20,18 +23,18 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

type IntegrationTestSuite struct {
type EndToEndTestSuite struct {
suite.Suite

cfg network.Config
network *network.Network
}

func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
return &IntegrationTestSuite{cfg: cfg}
func NewEndToEndTestSuite(cfg network.Config) *EndToEndTestSuite {
return &EndToEndTestSuite{cfg: cfg}
}

func (s *IntegrationTestSuite) SetupSuite() {
func (s *EndToEndTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

genesisState := s.cfg.GenesisState
Expand Down Expand Up @@ -90,12 +93,12 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.Require().NoError(err)
}

func (s *IntegrationTestSuite) TearDownSuite() {
func (s *EndToEndTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
s.network.Cleanup()
}

func (s *IntegrationTestSuite) TestGetBalancesCmd() {
func (s *EndToEndTestSuite) TestGetBalancesCmd() {
val := s.network.Validators[0]

testCases := []struct {
Expand Down Expand Up @@ -166,7 +169,7 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
}
}

func (s *IntegrationTestSuite) TestGetCmdQueryTotalSupply() {
func (s *EndToEndTestSuite) TestGetCmdQueryTotalSupply() {
val := s.network.Validators[0]

testCases := []struct {
Expand Down Expand Up @@ -238,7 +241,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryTotalSupply() {
}
}

func (s *IntegrationTestSuite) TestGetCmdQueryDenomsMetadata() {
func (s *EndToEndTestSuite) TestGetCmdQueryDenomsMetadata() {
val := s.network.Validators[0]

testCases := []struct {
Expand Down Expand Up @@ -365,7 +368,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDenomsMetadata() {
}
}

func (s *IntegrationTestSuite) TestNewSendTxCmdGenOnly() {
func (s *EndToEndTestSuite) TestNewSendTxCmdGenOnly() {
val := s.network.Validators[0]

clientCtx := val.ClientCtx
Expand All @@ -383,14 +386,14 @@ func (s *IntegrationTestSuite) TestNewSendTxCmdGenOnly() {
fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),
}

bz, err := MsgSendExec(clientCtx, from, to, amount, args...)
bz, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, args...)
s.Require().NoError(err)
tx, err := s.cfg.TxConfig.TxJSONDecoder()(bz.Bytes())
s.Require().NoError(err)
s.Require().Equal([]sdk.Msg{types.NewMsgSend(from, to, amount)}, tx.GetMsgs())
}

func (s *IntegrationTestSuite) TestNewSendTxCmdDryRun() {
func (s *EndToEndTestSuite) TestNewSendTxCmdDryRun() {
val := s.network.Validators[0]

clientCtx := val.ClientCtx
Expand All @@ -412,7 +415,7 @@ func (s *IntegrationTestSuite) TestNewSendTxCmdDryRun() {
r, w, _ := os.Pipe()
os.Stderr = w

_, err := MsgSendExec(clientCtx, from, to, amount, args...)
_, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, args...)
s.Require().NoError(err)

w.Close()
Expand All @@ -422,7 +425,7 @@ func (s *IntegrationTestSuite) TestNewSendTxCmdDryRun() {
s.Require().Regexp("gas estimate: [0-9]+", string(out))
}

func (s *IntegrationTestSuite) TestNewSendTxCmd() {
func (s *EndToEndTestSuite) TestNewSendTxCmd() {
val := s.network.Validators[0]

testCases := []struct {
Expand Down Expand Up @@ -510,7 +513,7 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
s.Run(tc.name, func() {
clientCtx := val.ClientCtx

bz, err := MsgSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...)
bz, err := clitestutil.MsgSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...)
if tc.expectErr {
s.Require().Error(err)
} else {
Expand All @@ -524,7 +527,7 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
}
}

func (s *IntegrationTestSuite) TestNewMultiSendTxCmd() {
func (s *EndToEndTestSuite) TestNewMultiSendTxCmd() {
val := s.network.Validators[0]
testAddr := sdk.AccAddress("cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5")

Expand Down Expand Up @@ -663,3 +666,15 @@ func NewCoin(denom string, amount math.Int) *sdk.Coin {
coin := sdk.NewCoin(denom, amount)
return &coin
}

func MsgMultiSendExec(clientCtx client.Context, from sdk.AccAddress, to []sdk.AccAddress, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{from.String()}
for _, addr := range to {
args = append(args, addr.String())
}

args = append(args, amount.String())
args = append(args, extraArgs...)

return clitestutil.ExecTestCLICmd(clientCtx, cli.NewMultiSendTxCmd(), args)
}
Loading

0 comments on commit 0f7e56c

Please sign in to comment.