From 62387c9c3ddd8d34a0d161d741472d6ddc5f3856 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Sun, 22 Oct 2023 00:42:18 +0800 Subject: [PATCH] test: adding test for the invalid decided just --- consensus/cp_decide.go | 1 - consensus/cp_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/consensus/cp_decide.go b/consensus/cp_decide.go index 85e447c05..a3c00ac08 100644 --- a/consensus/cp_decide.go +++ b/consensus/cp_decide.go @@ -38,7 +38,6 @@ func (s *cpDecideState) decide() { } s.signAddCPDecidedVote(*s.cpWeakValidity, s.cpRound, vote.CPValueZero, just) s.cpDecide(vote.CPValueZero) - s.cpDecided = 0 } else { // conflicting votes s.logger.Debug("conflicting main votes", "round", s.cpRound) diff --git a/consensus/cp_test.go b/consensus/cp_test.go index 9b04c11aa..3c8b27914 100644 --- a/consensus/cp_test.go +++ b/consensus/cp_test.go @@ -443,3 +443,34 @@ func TestInvalidJustMainVoteConflict(t *testing.T) { }) }) } + +func TestInvalidJustDecided(t *testing.T) { + td := setup(t) + + td.enterNewHeight(td.consX) + h := uint32(1) + r := int16(0) + just := &vote.JustDecided{ + QCert: td.GenerateTestCertificate(h), + } + + t.Run("invalid value: abstain", func(t *testing.T) { + v := vote.NewCPDecidedVote(td.RandHash(), h, r, 0, vote.CPValueAbstain, just, td.consB.valKey.Address()) + + err := td.consX.changeProposer.checkJust(v) + assert.ErrorIs(t, err, invalidJustificationError{ + JustType: just.Type(), + Reason: "invalid value: abstain", + }) + }) + + t.Run("invalid certificate", func(t *testing.T) { + v := vote.NewCPDecidedVote(td.RandHash(), h, r, 0, vote.CPValueOne, just, td.consB.valKey.Address()) + + err := td.consX.changeProposer.checkJust(v) + assert.ErrorIs(t, err, invalidJustificationError{ + JustType: just.Type(), + Reason: fmt.Sprintf("certificate has an unexpected committers: %v", just.QCert.Committers()), + }) + }) +}