diff --git a/testutil/mock/privval.go b/testutil/mock/privval.go index 6aaceedd2e34..9c5a745d1b55 100644 --- a/testutil/mock/privval.go +++ b/testutil/mock/privval.go @@ -14,7 +14,7 @@ import ( var _ tmtypes.PrivValidator = PV{} -// MockPV implements PrivValidator without any safety or persistence. +// PV implements PrivValidator without any safety or persistence. // Only use it for testing. type PV struct { PrivKey cryptotypes.PrivKey diff --git a/testutil/mock/privval_test.go b/testutil/mock/privval_test.go new file mode 100644 index 000000000000..a3326dbe4a09 --- /dev/null +++ b/testutil/mock/privval_test.go @@ -0,0 +1,32 @@ +package mock + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +) + +func TestGetPubKey(t *testing.T) { + pv := NewPV() + pb, err := pv.GetPubKey(context.Background()) + require.NoError(t, err) + require.NotNil(t, pb) +} + +func TestSignVote(t *testing.T) { + pv := NewPV() + v := tmproto.Vote{} + err := pv.SignVote(context.Background(), "chain-id", &v) + require.NoError(t, err) + require.NotNil(t, v.Signature) +} + +func TestSignProposal(t *testing.T) { + pv := NewPV() + p := tmproto.Proposal{} + err := pv.SignProposal(context.Background(), "chain-id", &p) + require.NoError(t, err) + require.NotNil(t, p.Signature) +} diff --git a/testutil/network/network.go b/testutil/network/network.go index 995eb56889df..2d89c4e69e9c 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -181,18 +181,22 @@ type Logger interface { var _ Logger = (*testing.T)(nil) var _ Logger = (*CLILogger)(nil) +// CLILogger wraps a cobra.Command and provides command logging methods. type CLILogger struct { cmd *cobra.Command } +// Log logs given args. func (s CLILogger) Log(args ...interface{}) { s.cmd.Println(args...) } +// Logf logs given args according to a format specifier. func (s CLILogger) Logf(format string, args ...interface{}) { s.cmd.Printf(format, args...) } +// NewCLILogger creates a new CLILogger. func NewCLILogger(cmd *cobra.Command) CLILogger { return CLILogger{cmd} } diff --git a/testutil/network/util.go b/testutil/network/util.go index 6e5d2865c725..79777ed09881 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -2,6 +2,7 @@ package network import ( "encoding/json" + "fmt" "io/ioutil" "path/filepath" "time" @@ -16,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/api" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" srvtypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -55,11 +57,11 @@ func startInProcess(cfg Config, val *Validator) error { if val.RPCAddress != "" { node, ok := val.tmNode.(local.NodeService) if !ok { - panic("can't cast service.Service to NodeService") + return fmt.Errorf("failed to cast %T to NodeService", val.tmNode) } val.RPCClient, err = local.New(node) if err != nil { - panic("cant create a local node") + return errors.Wrap(err, "failed to create a local node") } }