Skip to content

Commit

Permalink
add integration tests for double voting
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Nov 17, 2023
1 parent 22e6258 commit 86fb5cd
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tests/integration/double_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
blockID1 := testutil.MakeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
blockID2 := testutil.MakeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))

// Set the equivocation evidence min height to a the previous block height
equivocationEvidenceMinHeight := uint64(s.consumerCtx().BlockHeight() - 1)
s.providerApp.GetProviderKeeper().SetEquivocationEvidenceMinHeight(
s.providerCtx(),
s.consumerChain.ChainID,
equivocationEvidenceMinHeight,
)
// Note that votes are signed along with the chain ID
// see VoteSignBytes in https://github.com/cometbft/cometbft/blob/main/types/vote.go#L139

Expand Down Expand Up @@ -76,6 +83,17 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
s.consumerChain.ChainID,
)

// create a vote using the consumer validator key
// with block height that is smaller than the equivocation evidence min height
consuVoteOld := testutil.MakeAndSignVote(
blockID1,
int64(equivocationEvidenceMinHeight-1),
s.consumerCtx().BlockTime(),
consuValSet,
consuSigner,
s.consumerChain.ChainID,
)

testCases := []struct {
name string
ev *tmtypes.DuplicateVoteEvidence
Expand All @@ -84,7 +102,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
expPass bool
}{
{
"invalid consumer chain id - shouldn't pass",
"cannot find consumer chain for the given chain ID - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVote,
VoteB: consuBadVote,
Expand All @@ -96,6 +114,32 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
consuVal.PubKey,
false,
},
{
"evidence is older than equivocation evidence min height - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVoteOld,
VoteB: consuBadVote,
ValidatorPower: consuVal.VotingPower,
TotalVotingPower: consuVal.VotingPower,
Timestamp: s.consumerCtx().BlockTime(),
},
s.consumerChain.ChainID,
consuVal.PubKey,
false,
},
{
"the votes in the evidence are for different height - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVote,
VoteB: consuVoteOld,
ValidatorPower: consuVal.VotingPower,
TotalVotingPower: consuVal.VotingPower,
Timestamp: s.consumerCtx().BlockTime(),
},
s.consumerChain.ChainID,
consuVal.PubKey,
false,
},
{
"wrong public key - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
Expand Down

0 comments on commit 86fb5cd

Please sign in to comment.