@ -4,20 +4,23 @@ import (
"testing"
"time"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
evmock "github.com/tendermint/tendermint/evidence/mock"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/mempool/mock"
memmock "github.com/tendermint/tendermint/mempool/mock"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/state/mocks"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
const validationTestsStopHeight int64 = 10
var defaultTestTime = time . Date ( 2019 , 1 , 1 , 0 , 0 , 0 , 0 , time . UTC )
func TestValidateBlockHeader ( t * testing . T ) {
proxyApp := newTestApp ( )
require . NoError ( t , proxyApp . Start ( ) )
@ -28,8 +31,8 @@ func TestValidateBlockHeader(t *testing.T) {
stateDB ,
log . TestingLogger ( ) ,
proxyApp . Consensus ( ) ,
mock . Mempool { } ,
evmock . NewDefaultEvidencePool ( ) ,
memm ock . Mempool { } ,
sm . MockEvidencePool { } ,
)
lastCommit := types . NewCommit ( 0 , 0 , types . BlockID { } , nil )
@ -98,8 +101,8 @@ func TestValidateBlockCommit(t *testing.T) {
stateDB ,
log . TestingLogger ( ) ,
proxyApp . Consensus ( ) ,
mock . Mempool { } ,
evmock . NewDefaultEvidencePool ( ) ,
memm ock . Mempool { } ,
sm . MockEvidencePool { } ,
)
lastCommit := types . NewCommit ( 0 , 0 , types . BlockID { } , nil )
wrongSigsCommit := types . NewCommit ( 1 , 0 , types . BlockID { } , nil )
@ -205,8 +208,8 @@ func TestValidateBlockEvidence(t *testing.T) {
stateDB ,
log . TestingLogger ( ) ,
proxyApp . Consensus ( ) ,
mock . Mempool { } ,
evmock . NewDefaultEvidencePool ( ) ,
memm ock . Mempool { } ,
sm . MockEvidencePool { } ,
)
lastCommit := types . NewCommit ( 0 , 0 , types . BlockID { } , nil )
@ -259,9 +262,17 @@ func TestValidateBlockEvidence(t *testing.T) {
func TestValidateFailBlockOnCommittedEvidence ( t * testing . T ) {
var height int64 = 1
state , stateDB , _ := makeState ( 1 , int ( height ) )
state , stateDB , _ := makeState ( 2 , int ( height ) )
addr , _ := state . Validators . GetByIndex ( 0 )
addr2 , _ := state . Validators . GetByIndex ( 1 )
ev := types . NewMockEvidence ( height , defaultTestTime , addr )
ev2 := types . NewMockEvidence ( height , defaultTestTime , addr2 )
evpool := & mocks . EvidencePool { }
evpool . On ( "IsPending" , mock . AnythingOfType ( "types.MockEvidence" ) ) . Return ( false )
evpool . On ( "IsCommitted" , ev ) . Return ( false )
evpool . On ( "IsCommitted" , ev2 ) . Return ( true )
evpool := evmock . NewDefaultEvidencePool ( )
blockExec := sm . NewBlockExecutor (
stateDB , log . TestingLogger ( ) ,
nil ,
@ -269,9 +280,7 @@ func TestValidateFailBlockOnCommittedEvidence(t *testing.T) {
evpool )
// A block with a couple pieces of evidence passes.
block := makeBlock ( state , height )
addr , _ := state . Validators . GetByIndex ( 0 )
evpool . CommitEvidence ( evpool . AddMockEvidence ( height , addr ) )
block . Evidence . Evidence = evpool . CommittedEvidenceList
block . Evidence . Evidence = [ ] types . Evidence { ev , ev2 }
block . EvidenceHash = block . Evidence . Hash ( )
err := blockExec . ValidateBlock ( state , block )
@ -282,8 +291,16 @@ func TestValidateFailBlockOnCommittedEvidence(t *testing.T) {
func TestValidateAlreadyPendingEvidence ( t * testing . T ) {
var height int64 = 1
state , stateDB , _ := makeState ( 2 , int ( height ) )
addr , _ := state . Validators . GetByIndex ( 0 )
addr2 , _ := state . Validators . GetByIndex ( 1 )
ev := types . NewMockEvidence ( height , defaultTestTime , addr )
ev2 := types . NewMockEvidence ( height , defaultTestTime , addr2 )
evpool := & mocks . EvidencePool { }
evpool . On ( "IsPending" , ev ) . Return ( false )
evpool . On ( "IsPending" , ev2 ) . Return ( true )
evpool . On ( "IsCommitted" , mock . AnythingOfType ( "types.MockEvidence" ) ) . Return ( false )
evpool := evmock . NewDefaultEvidencePool ( )
blockExec := sm . NewBlockExecutor (
stateDB , log . TestingLogger ( ) ,
nil ,
@ -291,13 +308,8 @@ func TestValidateAlreadyPendingEvidence(t *testing.T) {
evpool )
// A block with a couple pieces of evidence passes.
block := makeBlock ( state , height )
addr , _ := state . Validators . GetByIndex ( 0 )
addr2 , _ := state . Validators . GetByIndex ( 0 )
// add pending evidence
pendingEv := evpool . AddMockEvidence ( height , addr )
// add evidence that hasn't seen before
ev := types . NewMockEvidence ( height , time . Now ( ) , addr2 )
block . Evidence . Evidence = [ ] types . Evidence { pendingEv , ev }
// add one evidence seen before and one evidence that hasn't
block . Evidence . Evidence = [ ] types . Evidence { ev , ev2 }
block . EvidenceHash = block . Evidence . Hash ( )
err := blockExec . ValidateBlock ( state , block )