use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class StateComputerLedgerTest method setup.
@Before
public void setup() {
this.mempool = TypedMocks.rmock(Mempool.class);
// No type check issues with mocking generic here
this.stateComputer = mock(StateComputer.class);
this.counters = mock(SystemCounters.class);
this.headerComparator = TypedMocks.rmock(Comparator.class);
this.accumulator = new SimpleLedgerAccumulatorAndVerifier(hasher);
this.accumulatorVerifier = new SimpleLedgerAccumulatorAndVerifier(hasher);
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
this.ledgerHeader = LedgerHeader.genesis(accumulatorState, null, 0);
this.genesis = UnverifiedVertex.createGenesis(ledgerHeader);
this.genesisVertex = new VerifiedVertex(genesis, hasher.hash(genesis));
this.genesisQC = QuorumCertificate.ofGenesis(genesisVertex, ledgerHeader);
this.currentLedgerHeader = this.genesisQC.getCommittedAndLedgerStateProof(hasher).map(Pair::getSecond).orElseThrow();
this.sut = new StateComputerLedger(mock(TimeSupplier.class), currentLedgerHeader, headerComparator, stateComputer, accumulator, accumulatorVerifier, counters);
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class MessageCentralValidatorSyncTest method when_send_response__then_message_central_will_send_response.
@Test
public void when_send_response__then_message_central_will_send_response() {
VerifiedVertex vertex = mock(VerifiedVertex.class);
when(vertex.toSerializable()).thenReturn(mock(UnverifiedVertex.class));
ImmutableList<VerifiedVertex> vertices = ImmutableList.of(vertex);
BFTNode node = mock(BFTNode.class);
ECPublicKey ecPublicKey = mock(ECPublicKey.class);
when(node.getKey()).thenReturn(ecPublicKey);
sync.verticesResponseDispatcher().dispatch(node, new GetVerticesResponse(vertices));
verify(messageCentral, times(1)).send(any(), any(GetVerticesResponseMessage.class));
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class SafetyRulesTest method when_vote_on_proposal_two_after_genesis__then_returned_vote_has_no_commit.
@Test
public void when_vote_on_proposal_two_after_genesis__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(true);
when(proposal.hasDirectParent()).thenReturn(true);
when(proposal.parentHasDirectParent()).thenReturn(true);
BFTHeader parent = mock(BFTHeader.class);
when(parent.getView()).thenReturn(View.of(1));
when(proposal.getParentHeader()).thenReturn(parent);
when(proposal.getView()).thenReturn(View.of(2));
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();
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class SafetyRulesTest method when_vote_on_proposal_three_after_genesis__then_returned_vote_has_commit.
@Test
public void when_vote_on_proposal_three_after_genesis__then_returned_vote_has_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(true);
when(proposal.parentHasDirectParent()).thenReturn(true);
BFTHeader grandparentHeader = mock(BFTHeader.class);
when(grandparentHeader.getView()).thenReturn(mock(View.class));
when(proposal.getGrandParentHeader()).thenReturn(grandparentHeader);
BFTHeader parent = mock(BFTHeader.class);
when(parent.getView()).thenReturn(View.of(2));
when(proposal.getParentHeader()).thenReturn(parent);
when(proposal.getView()).thenReturn(View.of(3));
Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
assertThat(voteMaybe).isNotEmpty();
Vote vote = voteMaybe.get();
assertThat(vote.getVoteData().getCommitted()).hasValue(grandparentHeader);
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class SafetyRulesTest method when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit.
@Test
public void when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit() {
when(safetyState.getLastVotedView()).thenReturn(View.of(0));
when(safetyState.getLockedView()).thenReturn(View.of(0));
when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
VerifiedVertex vertex = mock(VerifiedVertex.class);
when(vertex.hasDirectParent()).thenReturn(true);
when(vertex.touchesGenesis()).thenReturn(true);
when(vertex.parentHasDirectParent()).thenReturn(true);
when(vertex.getView()).thenReturn(View.of(1));
BFTHeader parent = mock(BFTHeader.class);
when(parent.getView()).thenReturn(View.of(0));
when(vertex.getParentHeader()).thenReturn(parent);
BFTHeader grandParent = mock(BFTHeader.class);
when(grandParent.getView()).thenReturn(mock(View.class));
when(vertex.getGrandParentHeader()).thenReturn(grandParent);
BFTHeader header = mock(BFTHeader.class);
Optional<Vote> voteMaybe = safetyRules.voteFor(vertex, header, 1L, mock(HighQC.class));
assertThat(voteMaybe).isNotEmpty();
Vote vote = voteMaybe.get();
assertThat(vote.getVoteData().getProposed()).isEqualTo(header);
assertThat(vote.getVoteData().getParent()).isEqualTo(parent);
assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
Aggregations