From 26c83d1cd15ab9225cb13d7324ac721b00a3fcd1 Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Mon, 8 Apr 2019 16:14:27 +0800 Subject: core: refine VerifyAgreementResult (#553) * Pass notary set directly to VerifyAgreementResult * Fix core.Consensus * Fix syncer --- core/utils_test.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'core/utils_test.go') diff --git a/core/utils_test.go b/core/utils_test.go index 560e923..e1bbb1e 100644 --- a/core/utils_test.go +++ b/core/utils_test.go @@ -71,52 +71,55 @@ func (s *UtilsTestSuite) TestVerifyAgreementResult() { s.Require().NoError(signer.SignVote(vote)) baResult.Votes = append(baResult.Votes, *vote) } - s.Require().NoError(VerifyAgreementResult(baResult, cache)) + nSet, err := cache.GetNotarySet(pos.Round) + s.Require().NoError(err) + s.Require().NotEmpty(nSet) + s.Require().NoError(VerifyAgreementResult(baResult, nSet)) // Test negative case. // All period should be the same. baResult.Votes[1].Period++ - s.Equal(ErrIncorrectVotePeriod, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrIncorrectVotePeriod, VerifyAgreementResult(baResult, nSet)) baResult.Votes[1].Period-- // Blockhash should match the one in votes. baResult.BlockHash = common.NewRandomHash() - s.Equal(ErrIncorrectVoteBlockHash, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrIncorrectVoteBlockHash, VerifyAgreementResult(baResult, nSet)) baResult.BlockHash = hash // Position should match. baResult.Position.Height++ - s.Equal(ErrIncorrectVotePosition, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrIncorrectVotePosition, VerifyAgreementResult(baResult, nSet)) baResult.Position = pos // types.VotePreCom is not accepted in agreement result. baResult.Votes[0].Type = types.VotePreCom - s.Equal(ErrIncorrectVoteType, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrIncorrectVoteType, VerifyAgreementResult(baResult, nSet)) baResult.Votes[0].Type = types.VoteCom // Vote type should be the same. baResult.Votes[1].Type = types.VoteFastCom - s.Equal(ErrIncorrectVoteType, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrIncorrectVoteType, VerifyAgreementResult(baResult, nSet)) baResult.Votes[1].Type = types.VoteCom // Only vote proposed by notarySet is valid. baResult.Votes[0].ProposerID = types.NodeID{Hash: common.NewRandomHash()} - s.Equal(ErrIncorrectVoteProposer, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrIncorrectVoteProposer, VerifyAgreementResult(baResult, nSet)) baResult.Votes[0].ProposerID = types.NewNodeID(pubKeys[0]) // Vote shuold have valid signature. baResult.Votes[0].Signature, err = prvKeys[0].Sign(common.NewRandomHash()) s.Require().NoError(err) - s.Equal(ErrIncorrectVoteSignature, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrIncorrectVoteSignature, VerifyAgreementResult(baResult, nSet)) s.Require().NoError(signers[0].SignVote(&baResult.Votes[0])) // Unique votes shuold be more than threshold. baResult.Votes = baResult.Votes[:1] - s.Equal(ErrNotEnoughVotes, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrNotEnoughVotes, VerifyAgreementResult(baResult, nSet)) for range signers { baResult.Votes = append(baResult.Votes, baResult.Votes[0]) } - s.Equal(ErrNotEnoughVotes, VerifyAgreementResult(baResult, cache)) + s.Equal(ErrNotEnoughVotes, VerifyAgreementResult(baResult, nSet)) } func TestUtils(t *testing.T) { -- cgit v1.2.3