use of com.radixdlt.crypto.ECKeyPair 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.crypto.ECKeyPair in project radixdlt by radixdlt.
the class BFTValidatorSetTest method testValidateWithUnequalPower.
@Test
public void testValidateWithUnequalPower() {
ECKeyPair k1 = ECKeyPair.generateNew();
ECKeyPair k2 = ECKeyPair.generateNew();
BFTNode node1 = BFTNode.create(k1.getPublicKey());
BFTNode node2 = BFTNode.create(k2.getPublicKey());
BFTValidator v1 = BFTValidator.from(node1, UInt256.THREE);
BFTValidator v2 = BFTValidator.from(node2, UInt256.ONE);
BFTValidatorSet vs = BFTValidatorSet.from(ImmutableSet.of(v1, v2));
HashCode message = HashUtils.random256();
ValidationState vst1 = vs.newValidationState();
assertTrue(vst1.addSignature(node1, 1L, k1.sign(message)));
assertTrue(vst1.complete());
assertEquals(1, vst1.signatures().count());
}
use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.
the class MempoolTest method replay_command_to_mempool.
@Test
public void replay_command_to_mempool() throws Exception {
// Arrange
getInjector().injectMembers(this);
ECKeyPair keyPair = ECKeyPair.generateNew();
var txn = createTxn(keyPair);
var proof = mock(LedgerProof.class);
when(proof.getAccumulatorState()).thenReturn(new AccumulatorState(genesisTxns.getTxns().size() + 1, HashUtils.random256()));
when(proof.getStateVersion()).thenReturn((long) genesisTxns.getTxns().size() + 1);
when(proof.getView()).thenReturn(View.of(1));
var commandsAndProof = VerifiedTxnsAndProof.create(List.of(txn), proof);
stateComputer.commit(commandsAndProof, null);
// Act
MempoolAdd mempoolAdd = MempoolAdd.create(txn);
processor.handleMessage(getFirstPeer(), mempoolAdd, null);
// Assert
assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isZero();
}
use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.
the class MempoolTest method add_local_command_to_mempool.
@Test
public void add_local_command_to_mempool() throws Exception {
// Arrange
getInjector().injectMembers(this);
ECKeyPair keyPair = ECKeyPair.generateNew();
var txn = createTxn(keyPair);
// Act
processor.handleMessage(self, MempoolAdd.create(txn), null);
// Assert
assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isEqualTo(1);
// FIXME: Added hack which requires genesis to be sent as message so ignore this check for now
// assertThat(network.allMessages())
// .hasOnlyOneElementSatisfying(m ->
// assertThat(m.message()).isInstanceOf(MempoolAddSuccess.class));
}
use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.
the class MempoolTest method relay_successful_local_add.
@Test
public void relay_successful_local_add() throws Exception {
// Arrange
getInjector().injectMembers(this);
ECKeyPair keyPair = ECKeyPair.generateNew();
var txn = createTxn(keyPair);
// Act
processor.handleMessage(self, MempoolAddSuccess.create(txn, null, null), null);
// Assert
assertThat(systemCounters.get(CounterType.MEMPOOL_RELAYS_SENT)).isEqualTo(NUM_PEERS);
}
Aggregations