x/auth: turn sign --validate-sigantures into a standalone command (#6108)

--validate-signatures should not be a flag of the sign command
as the operation performed (transaction signatures verification)
is logically distinct.

cli_test is and has always been an horrible name for package
directory as it's very much Go anti-idiomatic - _test is the
suffix used by test packages, not directories. Plus, CLI test
cases can and should live alongside other testcases that don't
require binaries to be built beforehand. Thus:

x/module/client/cli_test/*.go -> x/module/client/cli/

Test files that require sim{cli,d} shall be tagged with // +build cli_test

With regard to cli test auxiliary functions, they should live in:

x/module/client/testutil/

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Alessio Treglia
2020-05-04 13:55:16 +00:00
committed by GitHub
co-authored by Alexander Bezobchuk
parent 54ecf7d629
commit 2414e5bdd4
20 changed files with 352 additions and 181 deletions
+8 -2
View File
@@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/require"
@@ -182,7 +181,14 @@ func AddFlags(cmd string, flags []string) string {
return strings.TrimSpace(cmd)
}
func UnmarshalStdTx(t *testing.T, c *codec.Codec, s string) (stdTx auth.StdTx) {
func UnmarshalStdTx(t require.TestingT, c *codec.Codec, s string) (stdTx auth.StdTx) {
require.Nil(t, c.UnmarshalJSON([]byte(s), &stdTx))
return
}
func MarshalStdTx(t require.TestingT, c *codec.Codec, stdTx auth.StdTx) []byte {
bz, err := c.MarshalBinaryBare(stdTx)
require.NoError(t, err)
return bz
}
+12 -8
View File
@@ -1,20 +1,24 @@
// +build cli_test
package cli_test
import (
"fmt"
"io/ioutil"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/tests/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/types"
"io/ioutil"
"path/filepath"
"testing"
)
func TestSimdCollectGentxs(t *testing.T) {
func TestCLISimdCollectGentxs(t *testing.T) {
t.Parallel()
var customMaxBytes, customMaxGas int64 = 99999999, 1234567
f := cli.NewFixtures(t)
@@ -62,7 +66,7 @@ func TestSimdCollectGentxs(t *testing.T) {
f.Cleanup(gentxDir)
}
func TestSimdAddGenesisAccount(t *testing.T) {
func TestCLISimdAddGenesisAccount(t *testing.T) {
t.Parallel()
f := cli.NewFixtures(t)
@@ -113,7 +117,7 @@ func TestSimdAddGenesisAccount(t *testing.T) {
f.Cleanup()
}
func TestValidateGenesis(t *testing.T) {
func TestCLIValidateGenesis(t *testing.T) {
t.Parallel()
f := cli.InitFixtures(t)
+14
View File
@@ -2,9 +2,12 @@ package tests
import (
"bytes"
"io/ioutil"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)
// ApplyMockIO replaces stdin/out/err with buffers that can be used during testing.
@@ -18,4 +21,15 @@ func ApplyMockIO(c *cobra.Command) (*strings.Reader, *bytes.Buffer, *bytes.Buffe
return mockIn, mockOut, mockErr
}
// Write the given string to a new temporary file
func WriteToNewTempFile(t require.TestingT, s string) (*os.File, func()) {
fp, err := ioutil.TempFile(os.TempDir(), "cosmos_cli_test_")
require.Nil(t, err)
_, err = fp.WriteString(s)
require.Nil(t, err)
return fp, func() { os.Remove(fp.Name()) }
}
// DONTCOVER
+6 -2
View File
@@ -6,7 +6,6 @@ import (
"net/http"
"os"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
@@ -213,10 +212,15 @@ func ExtractPortFromAddress(listenAddress string) string {
return stringList[2]
}
type NamedTestingT interface {
require.TestingT
Name() string
}
// NewTestCaseDir creates a new temporary directory for a test case.
// Returns the directory path and a cleanup function.
// nolint: errcheck
func NewTestCaseDir(t *testing.T) (string, func()) {
func NewTestCaseDir(t NamedTestingT) (string, func()) {
dir, err := ioutil.TempDir("", t.Name()+"_")
require.NoError(t, err)
return dir, func() { os.RemoveAll(dir) }