Search in sources :

Example 6 with StateComputerResult

use of com.radixdlt.ledger.StateComputerLedger.StateComputerResult in project radixdlt by radixdlt.

the class StateComputerLedgerTest method should_accumulate_when_next_command_valid.

@Test
public void should_accumulate_when_next_command_valid() {
    // Arrange
    genesisIsEndOfEpoch(false);
    when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
    // Act
    var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(nextTxn), BFTNode.random());
    var proposedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
    Optional<PreparedVertex> nextPrepared = sut.prepare(new LinkedList<>(), proposedVertex);
    // Assert
    assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().isEndOfEpoch()).isFalse());
    assertThat(nextPrepared.flatMap(x -> accumulatorVerifier.verifyAndGetExtension(ledgerHeader.getAccumulatorState(), List.of(nextTxn), txn -> txn.getId().asHashCode(), x.getLedgerHeader().getAccumulatorState()))).contains(List.of(nextTxn));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TypedMocks(com.radixdlt.utils.TypedMocks) Hasher(com.radixdlt.crypto.Hasher) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) PreparedTxn(com.radixdlt.ledger.StateComputerLedger.PreparedTxn) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) View(com.radixdlt.hotstuff.bft.View) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) HashUtils(com.radixdlt.crypto.HashUtils) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) SystemCounters(com.radixdlt.counters.SystemCounters) TimeSupplier(com.radixdlt.utils.TimeSupplier) ImmutableMap(com.google.common.collect.ImmutableMap) Txn(com.radixdlt.atom.Txn) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Stream(java.util.stream.Stream) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Pair(com.radixdlt.utils.Pair) Optional(java.util.Optional) Mempool(com.radixdlt.mempool.Mempool) Comparator(java.util.Comparator) Mockito.mock(org.mockito.Mockito.mock) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Aggregations

StateComputerResult (com.radixdlt.ledger.StateComputerLedger.StateComputerResult)6 Test (org.junit.Test)6 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)5 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)3 LedgerProof (com.radixdlt.hotstuff.LedgerProof)3 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)3 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)3 PreparedVertex (com.radixdlt.hotstuff.bft.PreparedVertex)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashCode (com.google.common.hash.HashCode)2 SystemCounters (com.radixdlt.counters.SystemCounters)2 ECKeyPair (com.radixdlt.crypto.ECKeyPair)2 HashUtils (com.radixdlt.crypto.HashUtils)2 Hasher (com.radixdlt.crypto.Hasher)2 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)2 Sha256Hasher (com.radixdlt.hotstuff.Sha256Hasher)2 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)2 BFTValidator (com.radixdlt.hotstuff.bft.BFTValidator)2 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)2 View (com.radixdlt.hotstuff.bft.View)2