Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/crisis: In-Process CLI Integration Tests #6634

Merged
merged 4 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions x/bank/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx.WithOutput(buf)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)

testCases := []struct {
name string
from, to sdk.AccAddress
Expand Down
96 changes: 96 additions & 0 deletions x/crisis/client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package cli_test

import (
"bytes"
"context"
"fmt"
"testing"

"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/crisis/client/cli"
)

type IntegrationTestSuite struct {
suite.Suite

cfg testutil.Config
network *testutil.Network
}

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

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

s.cfg = cfg
s.network = testutil.NewTestNetwork(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) TestNewMsgVerifyInvariantTxCmd() {
buf := new(bytes.Buffer)
val := s.network.Validators[0]
clientCtx := val.ClientCtx.WithOutput(buf)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)

testCases := []struct {
name string
args []string
expectErr bool
}{
{
"valid transaction",
[]string{
"bank", "total-supply",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
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,
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
buf.Reset()

cmd := cli.NewMsgVerifyInvariantTxCmd()
cmd.SetErr(buf)
cmd.SetOut(buf)
cmd.SetArgs(tc.args)

err := cmd.ExecuteContext(ctx)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
// s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out, tc.respType), string(out))

// txResp := tc.respType.(*sdk.TxResponse)
// s.Require().Equal(tc.expectedCode, txResp.Code)
}
})
}
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
15 changes: 10 additions & 5 deletions x/crisis/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// NewTxCmd returns a root CLI command handler for all x/crisis transaction commands.
func NewTxCmd(clientCtx client.Context) *cobra.Command {
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Crisis transactions subcommands",
Expand All @@ -19,20 +19,25 @@ func NewTxCmd(clientCtx client.Context) *cobra.Command {
RunE: client.ValidateCmd,
}

txCmd.AddCommand(NewMsgVerifyInvariantTxCmd(clientCtx))
txCmd.AddCommand(NewMsgVerifyInvariantTxCmd())

return txCmd
}

// NewMsgVerifyInvariantTxCmd returns a CLI command handler for creating a
// MsgVerifyInvariant transaction.
func NewMsgVerifyInvariantTxCmd(clientCtx client.Context) *cobra.Command {
func NewMsgVerifyInvariantTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "invariant-broken [module-name] [invariant-route]",
Short: "Submit proof that an invariant broken to halt the chain",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)

clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}

senderAddr := clientCtx.GetFromAddress()
moduleName, route := args[0], args[1]
Expand All @@ -42,7 +47,7 @@ func NewMsgVerifyInvariantTxCmd(clientCtx client.Context) *cobra.Command {
return err
}

return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down
4 changes: 2 additions & 2 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}

// GetTxCmd returns the root tx command for the crisis module.
func (b AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.NewTxCmd(clientCtx)
func (b AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command {
return cli.NewTxCmd()
}

// GetQueryCmd returns no root query command for the crisis module.
Expand Down