use of com.radixdlt.ledger.StateComputerLedger.StateComputerResult in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method executing_epoch_high_view_should_return_next_validator_set.
@Test
public void executing_epoch_high_view_should_return_next_validator_set() {
// Arrange
var qc = mock(QuorumCertificate.class);
var parentHeader = mock(BFTHeader.class);
when(parentHeader.getView()).thenReturn(View.of(0));
when(qc.getProposed()).thenReturn(parentHeader);
var unverified = UnverifiedVertex.create(qc, View.of(11), List.of(), BFTNode.random());
var vertex = new VerifiedVertex(unverified, mock(HashCode.class));
// Act
StateComputerResult result = sut.prepare(List.of(), vertex, 0);
// Assert
assertThat(result.getSuccessfulCommands()).hasSize(1);
assertThat(result.getFailedCommands()).isEmpty();
assertThat(result.getNextValidatorSet()).hasValueSatisfying(set -> assertThat(set.getValidators()).isNotEmpty().allMatch(v -> v.getNode().getKey().equals(unregisteredNode.getPublicKey()) || registeredNodes.stream().anyMatch(k -> k.getPublicKey().equals(v.getNode().getKey()))));
}
use of com.radixdlt.ledger.StateComputerLedger.StateComputerResult in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method executing_epoch_high_view_with_register_should_not_return_new_next_validator_set.
@Test
public void executing_epoch_high_view_with_register_should_not_return_new_next_validator_set() throws Exception {
// Arrange
ECKeyPair keyPair = ECKeyPair.generateNew();
var txn = registerCommand(keyPair);
BFTNode node = BFTNode.create(keyPair.getPublicKey());
var qc = mock(QuorumCertificate.class);
var parentHeader = mock(BFTHeader.class);
when(parentHeader.getView()).thenReturn(View.of(0));
when(qc.getProposed()).thenReturn(parentHeader);
var v = UnverifiedVertex.create(qc, View.of(11), List.of(txn), BFTNode.random());
var vertex = new VerifiedVertex(v, mock(HashCode.class));
// Act
StateComputerResult result = sut.prepare(List.of(), vertex, 0);
// Assert
assertThat(result.getSuccessfulCommands()).hasSize(// since high view, command is not executed
1);
assertThat(result.getNextValidatorSet()).hasValueSatisfying(s -> {
assertThat(s.getValidators()).hasSize(2);
assertThat(s.getValidators()).extracting(BFTValidator::getNode).doesNotContain(node);
});
}
use of com.radixdlt.ledger.StateComputerLedger.StateComputerResult in project radixdlt by radixdlt.
the class StateComputerLedgerTest method should_do_nothing_if_committing_lower_state_version.
@Test
public void should_do_nothing_if_committing_lower_state_version() {
// Arrange
genesisIsEndOfEpoch(false);
when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
final AccumulatorState accumulatorState = new AccumulatorState(genesisStateVersion - 1, HashUtils.zero256());
final LedgerHeader ledgerHeader = LedgerHeader.create(genesisEpoch, View.of(2), accumulatorState, 1234);
final LedgerProof header = new LedgerProof(HashUtils.random256(), ledgerHeader, new TimestampedECDSASignatures());
var verified = VerifiedTxnsAndProof.create(List.of(nextTxn), header);
// Act
sut.syncEventProcessor().process(verified);
// Assert
verify(stateComputer, never()).commit(any(), any());
verify(mempool, never()).committed(any());
}
use of com.radixdlt.ledger.StateComputerLedger.StateComputerResult 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.ledger.StateComputerLedger.StateComputerResult in project radixdlt by radixdlt.
the class StateComputerLedgerTest method should_not_change_accumulator_when_there_is_no_command.
@Test
public void should_not_change_accumulator_when_there_is_no_command() {
// Arrange
genesisIsEndOfEpoch(false);
when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(), ImmutableMap.of()));
var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(), 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()).isFalse());
assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().getAccumulatorState()).isEqualTo(ledgerHeader.getAccumulatorState()));
}
Aggregations