separate mock evidence from real evidence (#2571)

Closes #2525
This commit is contained in:
Anton Kaliaev
2018-10-09 16:10:05 +04:00
committed by Alexander Simmerl
parent 989a2f32b1
commit 724e264ff5
7 changed files with 33 additions and 10 deletions

View File

@ -11,6 +11,9 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/client" "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/abci/example/kvstore"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
@ -22,9 +25,6 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func init() { func init() {
@ -97,6 +97,9 @@ func TestReactorBasic(t *testing.T) {
// Ensure we can process blocks with evidence // Ensure we can process blocks with evidence
func TestReactorWithEvidence(t *testing.T) { func TestReactorWithEvidence(t *testing.T) {
types.RegisterMockEvidences(cdc)
types.RegisterMockEvidences(types.GetCodec())
nValidators := 4 nValidators := 4
testName := "consensus_reactor_test" testName := "consensus_reactor_test"
tickerFunc := newMockTickerFunc(true) tickerFunc := newMockTickerFunc(true)

View File

@ -1,7 +1,7 @@
package types package types
import ( import (
"github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )

View File

@ -1,6 +1,7 @@
package evidence package evidence
import ( import (
"os"
"sync" "sync"
"testing" "testing"
@ -14,6 +15,13 @@ import (
var mockState = sm.State{} var mockState = sm.State{}
func TestMain(m *testing.M) {
types.RegisterMockEvidences(cdc)
code := m.Run()
os.Exit(code)
}
func initializeValidatorState(valAddr []byte, height int64) dbm.DB { func initializeValidatorState(valAddr []byte, height int64) dbm.DB {
stateDB := dbm.NewMemDB() stateDB := dbm.NewMemDB()

View File

@ -6,14 +6,12 @@ import (
"testing" "testing"
"time" "time"
"github.com/go-kit/kit/log/term"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/go-kit/kit/log/term" cfg "github.com/tendermint/tendermint/config"
dbm "github.com/tendermint/tendermint/libs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )

View File

@ -3,6 +3,7 @@ package types
import ( import (
"crypto/rand" "crypto/rand"
"math" "math"
"os"
"testing" "testing"
"time" "time"
@ -13,6 +14,13 @@ import (
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func TestMain(m *testing.M) {
RegisterMockEvidences(cdc)
code := m.Run()
os.Exit(code)
}
func TestBlockAddEvidence(t *testing.T) { func TestBlockAddEvidence(t *testing.T) {
txs := []Tx{Tx("foo"), Tx("bar")} txs := []Tx{Tx("foo"), Tx("bar")}
lastID := makeBlockIDRandom() lastID := makeBlockIDRandom()

View File

@ -46,8 +46,9 @@ type Evidence interface {
func RegisterEvidences(cdc *amino.Codec) { func RegisterEvidences(cdc *amino.Codec) {
cdc.RegisterInterface((*Evidence)(nil), nil) cdc.RegisterInterface((*Evidence)(nil), nil)
cdc.RegisterConcrete(&DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence", nil) cdc.RegisterConcrete(&DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence", nil)
}
// mocks func RegisterMockEvidences(cdc *amino.Codec) {
cdc.RegisterConcrete(MockGoodEvidence{}, "tendermint/MockGoodEvidence", nil) cdc.RegisterConcrete(MockGoodEvidence{}, "tendermint/MockGoodEvidence", nil)
cdc.RegisterConcrete(MockBadEvidence{}, "tendermint/MockBadEvidence", nil) cdc.RegisterConcrete(MockBadEvidence{}, "tendermint/MockBadEvidence", nil)
} }

View File

@ -1,7 +1,7 @@
package types package types
import ( import (
"github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/encoding/amino" "github.com/tendermint/tendermint/crypto/encoding/amino"
) )
@ -15,3 +15,8 @@ func RegisterBlockAmino(cdc *amino.Codec) {
cryptoAmino.RegisterAmino(cdc) cryptoAmino.RegisterAmino(cdc)
RegisterEvidences(cdc) RegisterEvidences(cdc)
} }
// GetCodec returns a codec used by the package. For testing purposes only.
func GetCodec() *amino.Codec {
return cdc
}