use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class LedgerProofTest method testComparsionBetweenDifferentStateVersions.
@Test
public void testComparsionBetweenDifferentStateVersions() {
LedgerHeader l0 = mock(LedgerHeader.class);
when(l0.getEpoch()).thenReturn(2L);
AccumulatorState accumulatorState = mock(AccumulatorState.class);
when(accumulatorState.getStateVersion()).thenReturn(2L);
when(l0.getAccumulatorState()).thenReturn(accumulatorState);
LedgerProof s0 = new LedgerProof(HashUtils.random256(), l0, mock(TimestampedECDSASignatures.class));
LedgerHeader l1 = mock(LedgerHeader.class);
when(l1.getEpoch()).thenReturn(2L);
AccumulatorState accumulatorState1 = mock(AccumulatorState.class);
when(accumulatorState1.getStateVersion()).thenReturn(3L);
when(l1.getAccumulatorState()).thenReturn(accumulatorState1);
LedgerProof s1 = new LedgerProof(HashUtils.random256(), l1, mock(TimestampedECDSASignatures.class));
assertThat(headerComparator.compare(s0, s1)).isNegative();
assertThat(headerComparator.compare(s1, s0)).isPositive();
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method committing_epoch_change_with_additional_cmds_should_fail.
// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
public void committing_epoch_change_with_additional_cmds_should_fail() throws Exception {
// Arrange
var keyPair = ECKeyPair.generateNew();
var cmd0 = systemUpdateCommand(0, 2);
var cmd1 = registerCommand(keyPair);
var ledgerProof = new LedgerProof(HashUtils.random256(), LedgerHeader.create(0, View.of(9), new AccumulatorState(3, HashUtils.zero256()), 0), new TimestampedECDSASignatures());
var commandsAndProof = VerifiedTxnsAndProof.create(ImmutableList.of(cmd0, cmd1), ledgerProof);
// Act
// Assert
assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method setupGenesis.
private void setupGenesis() throws RadixEngineException {
var branch = radixEngine.transientBranch();
var result = branch.execute(genesisTxns.getTxns(), PermissionLevel.SYSTEM);
var genesisValidatorSet = result.getProcessedTxns().get(0).getEvents().stream().filter(REEvent.NextValidatorSetEvent.class::isInstance).map(REEvent.NextValidatorSetEvent.class::cast).findFirst().map(e -> BFTValidatorSet.from(e.nextValidators().stream().map(v -> BFTValidator.from(BFTNode.create(v.validatorKey()), v.amount())))).orElseThrow(() -> new IllegalStateException("No validator set in genesis."));
radixEngine.deleteBranches();
var genesisLedgerHeader = LedgerProof.genesis(new AccumulatorState(0, hasher.hash(genesisTxns.getTxns().get(0).getId())), genesisValidatorSet, 0);
if (!genesisLedgerHeader.isEndOfEpoch()) {
throw new IllegalStateException("Genesis must be end of epoch");
}
radixEngine.execute(genesisTxns.getTxns(), LedgerAndBFTProof.create(genesisLedgerHeader), PermissionLevel.SYSTEM);
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method committing_epoch_change_when_there_shouldnt_be_one__should_fail.
// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
public void committing_epoch_change_when_there_shouldnt_be_one__should_fail() throws TxBuilderException {
// Arrange
var cmd0 = systemUpdateCommand(1, 1);
var ledgerProof = new LedgerProof(HashUtils.random256(), LedgerHeader.create(0, View.of(9), new AccumulatorState(3, HashUtils.zero256()), 0, BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)))), new TimestampedECDSASignatures());
var commandsAndProof = VerifiedTxnsAndProof.create(ImmutableList.of(cmd0), ledgerProof);
// Act
// Assert
assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method committing_epoch_high_views_should_fail.
// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
// state not easily obtained where checked in the RadixEngine
@Ignore("FIXME: Reinstate when upper bound on epoch view is in place.")
public void committing_epoch_high_views_should_fail() throws TxBuilderException {
// Arrange
var cmd0 = systemUpdateCommand(10, 1);
var ledgerProof = new LedgerProof(HashUtils.random256(), LedgerHeader.create(0, View.of(11), new AccumulatorState(3, HashUtils.zero256()), 0), new TimestampedECDSASignatures());
var commandsAndProof = VerifiedTxnsAndProof.create(ImmutableList.of(cmd0), ledgerProof);
// Act
// Assert
assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
Aggregations