chore: audit testutil (#11954)
## Description Ref: https://github.com/cosmos/cosmos-sdk/issues/11362 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
7a31a28e24
commit
16c8e2739f
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue