Skip to content

Commit

Permalink
Fix codecov: `consensus: calculate prevote message delay metric (back…
Browse files Browse the repository at this point in the history
…port #7551) (#7617)`
  • Loading branch information
tnasu committed Feb 28, 2022
1 parent c6d0882 commit 946a63e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions types/vote_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ func randVoteSetForPrivKeys(
return NewVoteSet("test_chain_id", height, round, signedMsgType, voterSet), vals, voterSet, privValidators
}

func addVoteByAllVoterSet(t *testing.T, voteSet *VoteSet, privVals []PrivValidator, height int64, round int32) []Vote {
votes := make([]Vote, voteSet.Size())
for i, voter := range voteSet.voterSet.Voters {
vote := &Vote{
Type: tmproto.PrevoteType,
Height: height,
Round: round,
BlockID: randBlockID(),
Timestamp: tmtime.Now(),
ValidatorAddress: voter.Address,
ValidatorIndex: int32(i),
}
v := vote.ToProto()
err := privVals[i].SignVote(voteSet.chainID, v)
require.NoError(t, err)
vote.Signature = v.Signature
added, err := voteSet.AddVote(vote)
require.NoError(t, err)
require.True(t, added)
votes[i] = *vote
}
return votes
}

// Convenience: Return new vote with different validator address/index
func withValidator(vote *Vote, addr []byte, idx int32) *Vote {
vote = vote.Copy()
Expand Down Expand Up @@ -207,6 +231,29 @@ func TestVoteSet_AddVote_Bad(t *testing.T) {
}
}

func TestVoteSet_List(t *testing.T) {
height, round := int64(1), int32(0)
voteSet, _, _, privVals := randVoteSet(height, round, tmproto.PrevoteType, 10, 1)

votes := addVoteByAllVoterSet(t, voteSet, privVals, height, round)
assert.Equal(t, votes, voteSet.List())

voteSet = nil
assert.Nil(t, voteSet.List())
}

func TestVoteSet_HasAll(t *testing.T) {
height, round := int64(1), int32(0)
voteSet, _, _, privVals := randVoteSet(height, round, tmproto.PrevoteType, 10, 1)
assert.False(t, voteSet.HasAll())

addVoteByAllVoterSet(t, voteSet, privVals, height, round)
assert.True(t, voteSet.HasAll())

voteSet = nil
assert.False(t, voteSet.HasAll())
}

func TestVoteSet_2_3Majority(t *testing.T) {
height, round := int64(1), int32(0)
voteSet, _, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1)
Expand Down

0 comments on commit 946a63e

Please sign in to comment.