use of com.radixdlt.hotstuff.bft.VerifiedVertex 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();
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class SafetyRulesTest method when_vote_on_same_view__then_exception_is_thrown.
@Test
public void when_vote_on_same_view__then_exception_is_thrown() {
View view = mock(View.class);
when(view.lte(view)).thenReturn(true);
when(safetyState.getLastVotedView()).thenReturn(view);
VerifiedVertex vertex = mock(VerifiedVertex.class);
when(vertex.getView()).thenReturn(view);
assertThat(this.safetyRules.voteFor(vertex, mock(BFTHeader.class), 0L, mock(HighQC.class))).isEmpty();
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class StateComputerLedgerTest method genesisIsEndOfEpoch.
public void genesisIsEndOfEpoch(boolean endOfEpoch) {
this.ledgerHeader = LedgerHeader.create(genesisEpoch, View.of(5), new AccumulatorState(genesisStateVersion, HashUtils.zero256()), 12345, endOfEpoch ? BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE))) : null);
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 StateComputerLedgerTest method should_not_change_header_when_past_end_of_epoch_even_with_command.
@Test
public void should_not_change_header_when_past_end_of_epoch_even_with_command() {
// Arrange
genesisIsEndOfEpoch(true);
when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(nextTxn), BFTNode.random());
var proposedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
// Act
Optional<PreparedVertex> nextPrepared = sut.prepare(new LinkedList<>(), proposedVertex);
// Assert
assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().isEndOfEpoch()).isTrue());
assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().getAccumulatorState()).isEqualTo(ledgerHeader.getAccumulatorState()));
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class GetVerticesErrorResponseMessageSerializeTest method get.
private static GetVerticesErrorResponseMessage get() {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
LedgerHeader ledgerHeader = LedgerHeaderMock.get();
VerifiedVertex verifiedVertex = new VerifiedVertex(UnverifiedVertex.createGenesis(ledgerHeader), HashUtils.zero256());
QuorumCertificate qc = QuorumCertificate.ofGenesis(verifiedVertex, ledgerHeader);
HighQC highQC = HighQC.from(qc, qc, Optional.empty());
final var request = new GetVerticesRequestMessage(HashUtils.random256(), 3);
return new GetVerticesErrorResponseMessage(highQC, request);
}
Aggregations