From 7a07abecc7a7c9858d805e0ab22d61ae08d9af2b Mon Sep 17 00:00:00 2001 From: Callum Date: Mon, 27 Apr 2020 07:29:12 +0200 Subject: [PATCH] cleaned up tests --- consensus/reactor_test.go | 10 ++++++++++ state/helpers_test.go | 1 + state/services.go | 2 ++ state/validation.go | 3 +++ 4 files changed, 16 insertions(+) diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index fcf22ddd6..f3d88e1e6 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -225,6 +225,16 @@ func (m *mockEvidencePool) Update(block *types.Block, state sm.State) { m.height++ } func (m *mockEvidencePool) IsCommitted(types.Evidence) bool { return false } +func (m *mockEvidencePool) IsPending(evidence types.Evidence) bool { + if m.height > 0 { + for _, e := range m.ev { + if e.Equal(evidence) { + return true + } + } + } + return false +} //------------------------------------ diff --git a/state/helpers_test.go b/state/helpers_test.go index a85e35748..c60a4b4dd 100644 --- a/state/helpers_test.go +++ b/state/helpers_test.go @@ -29,6 +29,7 @@ func (m mockEvPoolAlwaysCommitted) PendingEvidence(int64) []types.Evidence { ret func (m mockEvPoolAlwaysCommitted) AddEvidence(types.Evidence) error { return nil } func (m mockEvPoolAlwaysCommitted) Update(*types.Block, sm.State) {} func (m mockEvPoolAlwaysCommitted) IsCommitted(types.Evidence) bool { return true } +func (m mockEvPoolAlwaysCommitted) IsPending(types.Evidence) bool { return false } func newTestApp() proxy.AppConns { app := &testApp{} diff --git a/state/services.go b/state/services.go index a30956bdc..b6fb33722 100644 --- a/state/services.go +++ b/state/services.go @@ -43,6 +43,7 @@ type EvidencePool interface { Update(*types.Block, State) // IsCommitted indicates if this evidence was already marked committed in another block. IsCommitted(types.Evidence) bool + IsPending(types.Evidence) bool } // MockEvidencePool is an empty implementation of EvidencePool, useful for testing. @@ -52,3 +53,4 @@ func (m MockEvidencePool) PendingEvidence(int64) []types.Evidence { return nil } func (m MockEvidencePool) AddEvidence(types.Evidence) error { return nil } func (m MockEvidencePool) Update(*types.Block, State) {} func (m MockEvidencePool) IsCommitted(types.Evidence) bool { return false } +func (m MockEvidencePool) IsPending(types.Evidence) bool { return false } diff --git a/state/validation.go b/state/validation.go index e1e577e5c..aecfd42c8 100644 --- a/state/validation.go +++ b/state/validation.go @@ -136,6 +136,9 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block if evidencePool.IsCommitted(ev) { return types.NewErrEvidenceInvalid(ev, errors.New("evidence was already committed")) } + if evidencePool.IsPending(ev) { + return nil + } } if err := VerifyEvidence(stateDB, state, ev, &block.Header); err != nil { return types.NewErrEvidenceInvalid(ev, err)