Search in sources :

Example 11 with Vote

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

the class SafetyRulesTest method when_vote_on_proposal_three_after_genesis_with_skip__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_three_after_genesis_with_skip__then_returned_vote_has_no_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(1));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex proposal = mock(VerifiedVertex.class);
    when(proposal.touchesGenesis()).thenReturn(false);
    when(proposal.hasDirectParent()).thenReturn(false);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(2));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(4));
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(proposal.getGrandParentHeader()).thenReturn(grandParent);
    Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Vote(com.radixdlt.hotstuff.Vote) Builder(com.radixdlt.hotstuff.safety.SafetyState.Builder) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Example 12 with Vote

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

the class SafetyRulesTest method when_vote_with_qc_on_different_locked_view__then_exception_is_thrown.

@Test
public void when_vote_with_qc_on_different_locked_view__then_exception_is_thrown() {
    Hasher hasher = mock(Hasher.class);
    when(hasher.hash(any())).thenReturn(mock(HashCode.class));
    HashSigner hashSigner = mock(HashSigner.class);
    when(hashSigner.sign(any(HashCode.class))).thenReturn(ECDSASignature.zeroSignature());
    Vote lastVote = mock(Vote.class);
    when(lastVote.getView()).thenReturn(View.of(1));
    final var hashVerifier = mock(HashVerifier.class);
    final var validatorSet = mock(BFTValidatorSet.class);
    final var safetyRules = new SafetyRules(BFTNode.random(), new SafetyState(View.of(2), Optional.of(lastVote)), mock(PersistentSafetyStateStore.class), hasher, hashSigner, hashVerifier, validatorSet);
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.getView()).thenReturn(View.of(3));
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(0));
    when(vertex.getParentHeader()).thenReturn(parent);
    assertThat(safetyRules.voteFor(vertex, mock(BFTHeader.class), 0L, mock(HighQC.class))).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Hasher(com.radixdlt.crypto.Hasher) Vote(com.radixdlt.hotstuff.Vote) HashCode(com.google.common.hash.HashCode) HashSigner(com.radixdlt.hotstuff.HashSigner) Test(org.junit.Test)

Example 13 with Vote

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

the class SafetyRulesTest method when_timeout_a_vote_than_it_has_a_timeout_signature.

@Test
public void when_timeout_a_vote_than_it_has_a_timeout_signature() {
    Vote vote = mock(Vote.class);
    Vote voteWithTimeout = mock(Vote.class);
    when(vote.getView()).thenReturn(View.of(1));
    when(vote.getEpoch()).thenReturn(1L);
    when(vote.withTimeoutSignature(any())).thenReturn(voteWithTimeout);
    when(vote.isTimeout()).thenReturn(false);
    Builder builder = mock(Builder.class);
    when(builder.lastVote(any())).thenReturn(builder);
    when(builder.build()).thenReturn(this.safetyState);
    when(safetyState.toBuilder()).thenReturn(builder);
    Vote resultVote = safetyRules.timeoutVote(vote);
    verify(vote, times(1)).withTimeoutSignature(any());
    assertEquals(voteWithTimeout, resultVote);
}
Also used : Vote(com.radixdlt.hotstuff.Vote) Builder(com.radixdlt.hotstuff.safety.SafetyState.Builder) Test(org.junit.Test)

Example 14 with Vote

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

the class SafetyRulesTest method when_timeout_already_timed_out_vote_than_the_same_vote_is_returned.

@Test
public void when_timeout_already_timed_out_vote_than_the_same_vote_is_returned() {
    Vote vote = mock(Vote.class);
    when(vote.isTimeout()).thenReturn(true);
    assertEquals(vote, safetyRules.timeoutVote(vote));
}
Also used : Vote(com.radixdlt.hotstuff.Vote) Test(org.junit.Test)

Example 15 with Vote

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

the class SafetyStateTest method when_build_with_new_last_vote__then_should_build_with_new_last_vote.

@Test
public void when_build_with_new_last_vote__then_should_build_with_new_last_vote() {
    SafetyState safetyState = SafetyState.initialState();
    Builder builder = safetyState.toBuilder();
    Vote vote = mock(Vote.class);
    builder.lastVote(vote);
    SafetyState nextSafetyState = builder.build();
    assertThat(nextSafetyState.getLastVote()).isEqualTo(Optional.of(vote));
    assertThat(nextSafetyState.getLockedView()).isEqualTo(safetyState.getLockedView());
}
Also used : Vote(com.radixdlt.hotstuff.Vote) Builder(com.radixdlt.hotstuff.safety.SafetyState.Builder) 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