aboutsummaryrefslogtreecommitdiffstats
path: root/core/utils_test.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-04-08 16:14:27 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2019-04-08 16:14:27 +0800
commit26c83d1cd15ab9225cb13d7324ac721b00a3fcd1 (patch)
tree619536ead56abe2eacb4d165422ddddf6f7bbf23 /core/utils_test.go
parent337b5729c1cea837ac5ee8e1646dca587f52ebbd (diff)
downloadtangerine-consensus-26c83d1cd15ab9225cb13d7324ac721b00a3fcd1.tar
tangerine-consensus-26c83d1cd15ab9225cb13d7324ac721b00a3fcd1.tar.gz
tangerine-consensus-26c83d1cd15ab9225cb13d7324ac721b00a3fcd1.tar.bz2
tangerine-consensus-26c83d1cd15ab9225cb13d7324ac721b00a3fcd1.tar.lz
tangerine-consensus-26c83d1cd15ab9225cb13d7324ac721b00a3fcd1.tar.xz
tangerine-consensus-26c83d1cd15ab9225cb13d7324ac721b00a3fcd1.tar.zst
tangerine-consensus-26c83d1cd15ab9225cb13d7324ac721b00a3fcd1.zip
core: refine VerifyAgreementResult (#553)
* Pass notary set directly to VerifyAgreementResult * Fix core.Consensus * Fix syncer
Diffstat (limited to 'core/utils_test.go')
-rw-r--r--core/utils_test.go23
1 files changed, 13 insertions, 10 deletions
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) {