mirror of
https://github.com/tendermint/tendermint.git
synced 2026-10-01 04:05:45 +00:00
e2e: clean up generation of evidence (#6904)
This commit is contained in:
+19
-10
@@ -46,15 +46,20 @@ type DuplicateVoteEvidence struct {
|
||||
var _ Evidence = &DuplicateVoteEvidence{}
|
||||
|
||||
// NewDuplicateVoteEvidence creates DuplicateVoteEvidence with right ordering given
|
||||
// two conflicting votes. If one of the votes is nil, evidence returned is nil as well
|
||||
func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, valSet *ValidatorSet) *DuplicateVoteEvidence {
|
||||
// two conflicting votes. If either of the votes is nil, the val set is nil or the voter is
|
||||
// not in the val set, an error is returned
|
||||
func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, valSet *ValidatorSet,
|
||||
) (*DuplicateVoteEvidence, error) {
|
||||
var voteA, voteB *Vote
|
||||
if vote1 == nil || vote2 == nil || valSet == nil {
|
||||
return nil
|
||||
if vote1 == nil || vote2 == nil {
|
||||
return nil, errors.New("missing vote")
|
||||
}
|
||||
if valSet == nil {
|
||||
return nil, errors.New("missing validator set")
|
||||
}
|
||||
idx, val := valSet.GetByAddress(vote1.ValidatorAddress)
|
||||
if idx == -1 {
|
||||
return nil
|
||||
return nil, errors.New("validator not in validator set")
|
||||
}
|
||||
|
||||
if strings.Compare(vote1.BlockID.Key(), vote2.BlockID.Key()) == -1 {
|
||||
@@ -70,7 +75,7 @@ func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, valSet *V
|
||||
TotalVotingPower: valSet.TotalVotingPower(),
|
||||
ValidatorPower: val.VotingPower,
|
||||
Timestamp: blockTime,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ABCI returns the application relevant representation of the evidence
|
||||
@@ -92,7 +97,7 @@ func (dve *DuplicateVoteEvidence) Bytes() []byte {
|
||||
pbe := dve.ToProto()
|
||||
bz, err := pbe.Marshal()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic("marshaling duplicate vote evidence to bytes: " + err.Error())
|
||||
}
|
||||
|
||||
return bz
|
||||
@@ -260,11 +265,11 @@ func (l *LightClientAttackEvidence) ABCI() []abci.Evidence {
|
||||
func (l *LightClientAttackEvidence) Bytes() []byte {
|
||||
pbe, err := l.ToProto()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic("converting light client attack evidence to proto: " + err.Error())
|
||||
}
|
||||
bz, err := pbe.Marshal()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic("marshaling light client attack evidence to bytes: " + err.Error())
|
||||
}
|
||||
return bz
|
||||
}
|
||||
@@ -684,7 +689,11 @@ func NewMockDuplicateVoteEvidenceWithValidator(height int64, time time.Time,
|
||||
vB := voteB.ToProto()
|
||||
_ = pv.SignVote(context.Background(), chainID, vB)
|
||||
voteB.Signature = vB.Signature
|
||||
return NewDuplicateVoteEvidence(voteA, voteB, time, NewValidatorSet([]*Validator{val}))
|
||||
ev, err := NewDuplicateVoteEvidence(voteA, voteB, time, NewValidatorSet([]*Validator{val}))
|
||||
if err != nil {
|
||||
panic("constructing mock duplicate vote evidence: " + err.Error())
|
||||
}
|
||||
return ev
|
||||
}
|
||||
|
||||
func makeMockVote(height int64, round, index int32, addr Address,
|
||||
|
||||
@@ -85,7 +85,8 @@ func TestDuplicateVoteEvidenceValidation(t *testing.T) {
|
||||
vote1 := makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, math.MaxInt32, 0x02, blockID, defaultVoteTime)
|
||||
vote2 := makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, math.MaxInt32, 0x02, blockID2, defaultVoteTime)
|
||||
valSet := NewValidatorSet([]*Validator{val.ExtractIntoValidator(10)})
|
||||
ev := NewDuplicateVoteEvidence(vote1, vote2, defaultVoteTime, valSet)
|
||||
ev, err := NewDuplicateVoteEvidence(vote1, vote2, defaultVoteTime, valSet)
|
||||
require.NoError(t, err)
|
||||
tc.malleateEvidence(ev)
|
||||
assert.Equal(t, tc.expectErr, ev.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user