From c552a5b21eca7f6134ea219db9e968569c3e9d3d Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 10 Jul 2020 17:33:14 +0200 Subject: [PATCH] rpc: /broadcast_evidence nil evidence check (#5109) --- rpc/client/evidence_test.go | 7 +++++++ rpc/core/evidence.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/rpc/client/evidence_test.go b/rpc/client/evidence_test.go index 6f61b4356..a4ce2176b 100644 --- a/rpc/client/evidence_test.go +++ b/rpc/client/evidence_test.go @@ -222,3 +222,10 @@ func TestBroadcastEvidence_ConflictingHeadersEvidence(t *testing.T) { assert.Equal(t, ev.Hash(), result.Hash, "expected result hash to match evidence hash") } } + +func TestBroadcastEmptyEvidence(t *testing.T) { + for _, c := range GetClients() { + _, err := c.BroadcastEvidence(nil) + assert.Error(t, err) + } +} diff --git a/rpc/core/evidence.go b/rpc/core/evidence.go index 4c489fe48..b8fd2e2e2 100644 --- a/rpc/core/evidence.go +++ b/rpc/core/evidence.go @@ -1,6 +1,7 @@ package core import ( + "errors" "fmt" ctypes "github.com/tendermint/tendermint/rpc/core/types" @@ -11,6 +12,10 @@ import ( // BroadcastEvidence broadcasts evidence of the misbehavior. // More: https://docs.tendermint.com/master/rpc/#/Info/broadcast_evidence func BroadcastEvidence(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { + if ev == nil { + return nil, errors.New("no evidence was provided") + } + if err := ev.ValidateBasic(); err != nil { return nil, fmt.Errorf("evidence.ValidateBasic failed: %w", err) }