|
|
@ -2,6 +2,7 @@ package types |
|
|
|
|
|
|
|
import ( |
|
|
|
"testing" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
abci "github.com/tendermint/tendermint/abci/types" |
|
|
@ -43,6 +44,9 @@ func TestABCIValidators(t *testing.T) { |
|
|
|
assert.Nil(t, err) |
|
|
|
assert.Equal(t, tmValExpected, tmVals[0]) |
|
|
|
|
|
|
|
abciVals := TM2PB.Validators(NewValidatorSet(tmVals)) |
|
|
|
assert.Equal(t, []abci.Validator{abciVal}, abciVals) |
|
|
|
|
|
|
|
// val with address
|
|
|
|
tmVal.Address = pkEd.Address() |
|
|
|
|
|
|
@ -67,3 +71,50 @@ func TestABCIConsensusParams(t *testing.T) { |
|
|
|
|
|
|
|
assert.Equal(t, *cp, cp2) |
|
|
|
} |
|
|
|
|
|
|
|
func TestABCIHeader(t *testing.T) { |
|
|
|
header := &Header{ |
|
|
|
Height: int64(3), |
|
|
|
Time: time.Now(), |
|
|
|
NumTxs: int64(10), |
|
|
|
} |
|
|
|
abciHeader := TM2PB.Header(header) |
|
|
|
|
|
|
|
assert.Equal(t, int64(3), abciHeader.Height) |
|
|
|
} |
|
|
|
|
|
|
|
func TestABCIEvidence(t *testing.T) { |
|
|
|
val := NewMockPV() |
|
|
|
blockID := makeBlockID("blockhash", 1000, "partshash") |
|
|
|
blockID2 := makeBlockID("blockhash2", 1000, "partshash") |
|
|
|
const chainID = "mychain" |
|
|
|
ev := &DuplicateVoteEvidence{ |
|
|
|
PubKey: val.GetPubKey(), |
|
|
|
VoteA: makeVote(val, chainID, 0, 10, 2, 1, blockID), |
|
|
|
VoteB: makeVote(val, chainID, 0, 10, 2, 1, blockID2), |
|
|
|
} |
|
|
|
abciEv := TM2PB.Evidence( |
|
|
|
ev, |
|
|
|
NewValidatorSet([]*Validator{NewValidator(val.GetPubKey(), 10)}), |
|
|
|
time.Now(), |
|
|
|
) |
|
|
|
|
|
|
|
assert.Equal(t, "duplicate/vote", abciEv.Type) |
|
|
|
} |
|
|
|
|
|
|
|
type pubKeyEddie struct{} |
|
|
|
|
|
|
|
func (pubKeyEddie) Address() Address { return []byte{} } |
|
|
|
func (pubKeyEddie) Bytes() []byte { return []byte{} } |
|
|
|
func (pubKeyEddie) VerifyBytes(msg []byte, sig crypto.Signature) bool { return false } |
|
|
|
func (pubKeyEddie) Equals(crypto.PubKey) bool { return false } |
|
|
|
|
|
|
|
func TestABCIValidatorFromPubKeyAndPower(t *testing.T) { |
|
|
|
pubkey := crypto.GenPrivKeyEd25519().PubKey() |
|
|
|
|
|
|
|
abciVal := TM2PB.ValidatorFromPubKeyAndPower(pubkey, 10) |
|
|
|
assert.Equal(t, int64(10), abciVal.Power) |
|
|
|
|
|
|
|
assert.Panics(t, func() { TM2PB.ValidatorFromPubKeyAndPower(nil, 10) }) |
|
|
|
assert.Panics(t, func() { TM2PB.ValidatorFromPubKeyAndPower(pubKeyEddie{}, 10) }) |
|
|
|
} |