Skip to content

Commit

Permalink
test: adding test for the invalid decided just
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Oct 21, 2023
1 parent 418f0e4 commit 62387c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion consensus/cp_decide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions consensus/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
})
})
}

0 comments on commit 62387c9

Please sign in to comment.