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

chore: audit testutil #11954

Merged
merged 10 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
2 changes: 1 addition & 1 deletion testutil/mock/privval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions testutil/mock/privval_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 4 additions & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
6 changes: 4 additions & 2 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package network

import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"time"
Expand All @@ -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"
Expand Down Expand Up @@ -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("can't cast %T to NodeService", val.tmNode)
blushi marked this conversation as resolved.
Show resolved Hide resolved
blushi marked this conversation as resolved.
Show resolved Hide resolved
}
val.RPCClient, err = local.New(node)
if err != nil {
panic("cant create a local node")
return errors.Wrap(err, "can't create a local node")
blushi marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down