Skip to content

Commit

Permalink
evidence: add CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Dec 2, 2020
1 parent 5085587 commit f607b10
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions x/evidence/client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cli_test

import (
"strings"
"testing"

"github.com/stretchr/testify/suite"

clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/evidence/client/cli"
)

type IntegrationTestSuite struct {
suite.Suite

cfg testnet.Config
network *testnet.Network
}

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

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

s.cfg = cfg
s.network = testnet.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 TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}

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

testCases := map[string]struct {
args []string
expectedOutput string
expectErr bool
}{
"non-existant evidence": {
[]string{"DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660"},
"evidence DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660 not found",
true,
},
"all evidence (default pagination)": {
[]string{},
"evidence: []\npagination:\n next_key: null\n total: \"0\"",
false,
},
}

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

s.Run(name, func() {
cmd := cli.GetQueryCmd()
clientCtx := val.ClientCtx

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
}

s.Require().Contains(strings.TrimSpace(out.String()), tc.expectedOutput)
})
}
}

0 comments on commit f607b10

Please sign in to comment.