Search in sources :

Example 1 with ECKeyPair

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);
    });
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) BFTNode(com.radixdlt.consensus.bft.BFTNode) HashCode(com.google.common.hash.HashCode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 2 with ECKeyPair

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());
}
Also used : HashCode(com.google.common.hash.HashCode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Example 3 with ECKeyPair

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();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Example 4 with ECKeyPair

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));
}
Also used : ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Example 5 with ECKeyPair

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);
}
Also used : ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Aggregations

ECKeyPair (com.radixdlt.crypto.ECKeyPair)22 Test (org.junit.Test)17 HashCode (com.google.common.hash.HashCode)8 AbstractModule (com.google.inject.AbstractModule)4 TransferrableTokensParticle (com.radixdlt.application.tokens.TransferrableTokensParticle)4 BFTNode (com.radixdlt.consensus.bft.BFTNode)4 CMError (com.radixdlt.constraintmachine.CMError)4 CMInstruction (com.radixdlt.constraintmachine.CMInstruction)4 RadixAddress (com.radixdlt.identifiers.RadixAddress)4 AccumulatorState (com.radixdlt.ledger.AccumulatorState)4 TypeLiteral (com.google.inject.TypeLiteral)3 SystemCounters (com.radixdlt.counters.SystemCounters)3 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)3 ImmutableList (com.google.common.collect.ImmutableList)2 Guice (com.google.inject.Guice)2 Amount (com.radixdlt.application.tokens.Amount)2 TxAction (com.radixdlt.atom.TxAction)2 LedgerProof (com.radixdlt.consensus.LedgerProof)2 PersistentVertexStore (com.radixdlt.consensus.bft.PersistentVertexStore)2 Self (com.radixdlt.consensus.bft.Self)2