From 553c75edc975800ecd3875418fc0330b69caa57e Mon Sep 17 00:00:00 2001 From: blushi Date: Thu, 12 May 2022 16:59:08 +0200 Subject: [PATCH 1/9] Update PV doc --- testutil/mock/privval.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7a229c888060bc6f858a25836396bd096d6819c4 Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 13 May 2022 11:48:21 +0200 Subject: [PATCH 2/9] Add privval tests --- testutil/mock/privval_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 testutil/mock/privval_test.go diff --git a/testutil/mock/privval_test.go b/testutil/mock/privval_test.go new file mode 100644 index 000000000000..a26dbdf423fa --- /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.TODO()) + require.NoError(t, err) + require.NotNil(t, pb) +} + +func TestSignVote(t *testing.T) { + pv := NewPV() + v := tmproto.Vote{} + err := pv.SignVote(context.TODO(), "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.TODO(), "chain-id", &p) + require.NoError(t, err) + require.NotNil(t, p.Signature) +} From 6f108e696361dc4c11f80fd8811f75ff95ac4ad7 Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 13 May 2022 11:57:56 +0200 Subject: [PATCH 3/9] Add godoc --- testutil/network/network.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testutil/network/network.go b/testutil/network/network.go index 995eb56889df..926b965ada09 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} } From d2d14ee39c0a2aaae1f6b541e237534aeba1fbe0 Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 13 May 2022 12:37:59 +0200 Subject: [PATCH 4/9] Return error instead of panicking --- testutil/network/util.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testutil/network/util.go b/testutil/network/util.go index 6e5d2865c725..97ebb41585d9 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("can't 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, "cant create a local node") } } From fe090bf20f63a809cfc562960c824a973a110cef Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 13 May 2022 12:38:15 +0200 Subject: [PATCH 5/9] Fix typo --- testutil/network/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil/network/util.go b/testutil/network/util.go index 97ebb41585d9..8dba2e2a8046 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -61,7 +61,7 @@ func startInProcess(cfg Config, val *Validator) error { } val.RPCClient, err = local.New(node) if err != nil { - return errors.Wrap(err, "cant create a local node") + return errors.Wrap(err, "can't create a local node") } } From 535d55579923ef839d127650b3652ede63ab2b4b Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 13 May 2022 13:11:14 +0200 Subject: [PATCH 6/9] Add punctuation --- testutil/network/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index 926b965ada09..2d89c4e69e9c 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -196,7 +196,7 @@ func (s CLILogger) Logf(format string, args ...interface{}) { s.cmd.Printf(format, args...) } -// NewCLILogger creates a new CLILogger +// NewCLILogger creates a new CLILogger. func NewCLILogger(cmd *cobra.Command) CLILogger { return CLILogger{cmd} } From 37407bdae8744176fe43c4d9cdc4a09eeac4fdce Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 13 May 2022 13:14:55 +0200 Subject: [PATCH 7/9] Use context background --- testutil/mock/privval_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testutil/mock/privval_test.go b/testutil/mock/privval_test.go index a26dbdf423fa..a3326dbe4a09 100644 --- a/testutil/mock/privval_test.go +++ b/testutil/mock/privval_test.go @@ -10,7 +10,7 @@ import ( func TestGetPubKey(t *testing.T) { pv := NewPV() - pb, err := pv.GetPubKey(context.TODO()) + pb, err := pv.GetPubKey(context.Background()) require.NoError(t, err) require.NotNil(t, pb) } @@ -18,7 +18,7 @@ func TestGetPubKey(t *testing.T) { func TestSignVote(t *testing.T) { pv := NewPV() v := tmproto.Vote{} - err := pv.SignVote(context.TODO(), "chain-id", &v) + err := pv.SignVote(context.Background(), "chain-id", &v) require.NoError(t, err) require.NotNil(t, v.Signature) } @@ -26,7 +26,7 @@ func TestSignVote(t *testing.T) { func TestSignProposal(t *testing.T) { pv := NewPV() p := tmproto.Proposal{} - err := pv.SignProposal(context.TODO(), "chain-id", &p) + err := pv.SignProposal(context.Background(), "chain-id", &p) require.NoError(t, err) require.NotNil(t, p.Signature) } From 6755663ffd1ca6682f1029db7625891251264e08 Mon Sep 17 00:00:00 2001 From: Marie Gauthier Date: Fri, 13 May 2022 16:28:43 +0200 Subject: [PATCH 8/9] Update testutil/network/util.go Co-authored-by: Aleksandr Bezobchuk --- testutil/network/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil/network/util.go b/testutil/network/util.go index 8dba2e2a8046..cf64f63ef9ac 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -61,7 +61,7 @@ func startInProcess(cfg Config, val *Validator) error { } val.RPCClient, err = local.New(node) if err != nil { - return errors.Wrap(err, "can't create a local node") + return errors.Wrap(err, "failed to create a local node") } } From af4f013cb91c116383932c1c27cada55c7d67482 Mon Sep 17 00:00:00 2001 From: Marie Gauthier Date: Fri, 13 May 2022 16:28:51 +0200 Subject: [PATCH 9/9] Update testutil/network/util.go Co-authored-by: Aleksandr Bezobchuk --- testutil/network/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil/network/util.go b/testutil/network/util.go index cf64f63ef9ac..79777ed09881 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -57,7 +57,7 @@ func startInProcess(cfg Config, val *Validator) error { if val.RPCAddress != "" { node, ok := val.tmNode.(local.NodeService) if !ok { - return fmt.Errorf("can't cast %T to NodeService", val.tmNode) + return fmt.Errorf("failed to cast %T to NodeService", val.tmNode) } val.RPCClient, err = local.New(node) if err != nil {