From 86fb5cd3c110e4a60463cba4cc8c992c619e5f28 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Fri, 17 Nov 2023 13:36:55 +0100 Subject: [PATCH] add integration tests for double voting --- tests/integration/double_vote.go | 46 +++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/integration/double_vote.go b/tests/integration/double_vote.go index 60fc0ce635..cc9331adc6 100644 --- a/tests/integration/double_vote.go +++ b/tests/integration/double_vote.go @@ -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 @@ -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 @@ -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, @@ -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{