Search in sources :

Example 1 with Vote

use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.

the class BFTEventReducerTest method when_process_vote_with_quorum_wrong_view__then_ignored.

@Test
public void when_process_vote_with_quorum_wrong_view__then_ignored() {
    Vote vote = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    this.bftEventReducer.processViewUpdate(ViewUpdate.create(View.of(3), mock(HighQC.class), mock(BFTNode.class), this.self));
    this.bftEventReducer.processVote(vote);
    verifyNoMoreInteractions(this.pendingVotes);
}
Also used : Vote(com.radixdlt.hotstuff.Vote) Test(org.junit.Test)

Example 2 with Vote

use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.

the class BFTEventReducerTest method when_process_vote_with_quorum__then_processed.

@Test
public void when_process_vote_with_quorum__then_processed() {
    BFTNode author = mock(BFTNode.class);
    Vote vote = mock(Vote.class);
    when(vote.getAuthor()).thenReturn(author);
    QuorumCertificate qc = mock(QuorumCertificate.class);
    HighQC highQc = mock(HighQC.class);
    QuorumCertificate highestCommittedQc = mock(QuorumCertificate.class);
    when(highQc.highestCommittedQC()).thenReturn(highestCommittedQc);
    when(vote.getView()).thenReturn(View.of(1));
    when(this.pendingVotes.insertVote(any(), any())).thenReturn(VoteProcessingResult.qcQuorum(qc));
    when(this.vertexStore.highQC()).thenReturn(highQc);
    // Move to view 1
    this.bftEventReducer.processViewUpdate(ViewUpdate.create(View.of(1), highQc, mock(BFTNode.class), this.self));
    this.bftEventReducer.processVote(vote);
    verify(this.viewQuorumReachedEventDispatcher, times(1)).dispatch(any());
    verify(this.pendingVotes, times(1)).insertVote(eq(vote), any());
    verifyNoMoreInteractions(this.pendingVotes);
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) Vote(com.radixdlt.hotstuff.Vote) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 3 with Vote

use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.

the class BFTEventVerifierTest method when_process_correct_vote_then_should_be_forwarded.

@Test
public void when_process_correct_vote_then_should_be_forwarded() {
    Vote vote = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    when(vote.getEpoch()).thenReturn(0L);
    BFTNode author = mock(BFTNode.class);
    when(vote.getAuthor()).thenReturn(author);
    ECDSASignature voteSignature = mock(ECDSASignature.class);
    ECDSASignature timeoutSignature = mock(ECDSASignature.class);
    when(vote.getSignature()).thenReturn(voteSignature);
    when(vote.getTimeoutSignature()).thenReturn(Optional.of(timeoutSignature));
    when(validatorSet.containsNode(eq(author))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(voteSignature))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(timeoutSignature))).thenReturn(true);
    when(safetyRules.verifyHighQcAgainstTheValidatorSet(any())).thenReturn(true);
    eventVerifier.processVote(vote);
    verify(forwardTo, times(1)).processVote(eq(vote));
}
Also used : Vote(com.radixdlt.hotstuff.Vote) ECDSASignature(com.radixdlt.crypto.ECDSASignature) Test(org.junit.Test)

Example 4 with Vote

use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.

the class BFTEventVerifierTest method when_process_bad_timeout_signature_vote_then_should_not_be_forwarded.

@Test
public void when_process_bad_timeout_signature_vote_then_should_not_be_forwarded() {
    Vote vote = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    when(vote.getEpoch()).thenReturn(0L);
    BFTNode author = mock(BFTNode.class);
    when(vote.getAuthor()).thenReturn(author);
    ECDSASignature voteSignature = mock(ECDSASignature.class);
    ECDSASignature timeoutSignature = mock(ECDSASignature.class);
    when(vote.getSignature()).thenReturn(voteSignature);
    when(vote.getTimeoutSignature()).thenReturn(Optional.of(timeoutSignature));
    when(validatorSet.containsNode(eq(author))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(voteSignature))).thenReturn(true);
    when(verifier.verify(any(), any(), eq(timeoutSignature))).thenReturn(false);
    eventVerifier.processVote(vote);
    verify(forwardTo, never()).processVote(any());
}
Also used : Vote(com.radixdlt.hotstuff.Vote) ECDSASignature(com.radixdlt.crypto.ECDSASignature) Test(org.junit.Test)

Example 5 with Vote

use of com.radixdlt.hotstuff.Vote in project radixdlt by radixdlt.

the class BFTEventVerifierTest method when_process_bad_signature_vote_then_should_not_be_forwarded.

@Test
public void when_process_bad_signature_vote_then_should_not_be_forwarded() {
    Vote vote = mock(Vote.class);
    BFTNode author = mock(BFTNode.class);
    when(vote.getAuthor()).thenReturn(author);
    when(vote.getSignature()).thenReturn(mock(ECDSASignature.class));
    when(validatorSet.containsNode(eq(author))).thenReturn(true);
    when(verifier.verify(any(), any(), any())).thenReturn(false);
    eventVerifier.processVote(vote);
    verify(forwardTo, never()).processVote(any());
}
Also used : Vote(com.radixdlt.hotstuff.Vote) ECDSASignature(com.radixdlt.crypto.ECDSASignature) Test(org.junit.Test)

Aggregations

Vote (com.radixdlt.hotstuff.Vote)26 Test (org.junit.Test)19 HighQC (com.radixdlt.hotstuff.HighQC)11 View (com.radixdlt.hotstuff.bft.View)9 BFTHeader (com.radixdlt.hotstuff.BFTHeader)8 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)7 Builder (com.radixdlt.hotstuff.safety.SafetyState.Builder)7 ECDSASignature (com.radixdlt.crypto.ECDSASignature)6 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)6 HashCode (com.google.common.hash.HashCode)4 ViewUpdate (com.radixdlt.hotstuff.bft.ViewUpdate)4 HashSigner (com.radixdlt.hotstuff.HashSigner)3 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)3 BFTInsertUpdate (com.radixdlt.hotstuff.bft.BFTInsertUpdate)3 AbstractModule (com.google.inject.AbstractModule)2 TypeLiteral (com.google.inject.TypeLiteral)2 SystemCounters (com.radixdlt.counters.SystemCounters)2 Hasher (com.radixdlt.crypto.Hasher)2 EventDispatcher (com.radixdlt.environment.EventDispatcher)2 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)2