Search in sources :

Example 16 with ECKeyPair

use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.

the class MempoolTest method add_remote_command_to_mempool.

@Test
public void add_remote_command_to_mempool() throws Exception {
    // Arrange
    getInjector().injectMembers(this);
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = createTxn(keyPair);
    // Act
    processor.handleMessage(getFirstPeer(), 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 17 with ECKeyPair

use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.

the class MempoolTest method add_same_command_to_mempool.

@Test
public void add_same_command_to_mempool() throws Exception {
    // Arrange
    getInjector().injectMembers(this);
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = createTxn(keyPair);
    MempoolAdd mempoolAdd = MempoolAdd.create(txn);
    processor.handleMessage(getFirstPeer(), mempoolAdd, null);
    // Act
    processor.handleMessage(getFirstPeer(), mempoolAdd, null);
    // Assert
    assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isEqualTo(1);
}
Also used : ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Example 18 with ECKeyPair

use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.

the class MempoolTest method mempool_removes_conflicts_on_commit.

@Test
public void mempool_removes_conflicts_on_commit() throws Exception {
    // Arrange
    getInjector().injectMembers(this);
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = createTxn(keyPair, 2);
    MempoolAdd mempoolAdd = MempoolAdd.create(txn);
    processor.handleMessage(getFirstPeer(), mempoolAdd, null);
    // Act
    var txn2 = createTxn(keyPair, 1);
    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(txn2), proof);
    stateComputer.commit(commandsAndProof, 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 19 with ECKeyPair

use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.

the class MempoolTest method relay_successful_remote_add.

@Test
public void relay_successful_remote_add() throws Exception {
    // Arrange
    getInjector().injectMembers(this);
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = createTxn(keyPair);
    // Act
    processor.handleMessage(self, MempoolAddSuccess.create(txn, null, getFirstPeer()), null);
    // Assert
    assertThat(systemCounters.get(CounterType.MEMPOOL_RELAYS_SENT)).isEqualTo(NUM_PEERS - 1);
}
Also used : ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Example 20 with ECKeyPair

use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.

the class SimulationNodes method createBFTModule.

private Module createBFTModule(ECKeyPair self) {
    Module module = Modules.combine(new AbstractModule() {

        @Provides
        @Self
        private BFTNode self() {
            return BFTNode.create(self.getPublicKey());
        }

        @Provides
        @Self
        private ECPublicKey key() {
            return self.getPublicKey();
        }

        @Provides
        private ECKeyPair keyPair() {
            return self;
        }

        @Provides
        @LocalSigner
        HashSigner hashSigner() {
            return self::sign;
        }
    }, new NodeNetworkMessagesModule(underlyingNetwork), baseModule);
    // can break network behavior if incorrect modules are used
    if (overrideModules.containsKey(self.getPublicKey())) {
        final var nodeOverrideModules = overrideModules.get(self.getPublicKey());
        module = Modules.override(module).with(nodeOverrideModules);
    }
    return module;
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ECPublicKey(com.radixdlt.crypto.ECPublicKey) LocalSigner(com.radixdlt.qualifier.LocalSigner) NodeNetworkMessagesModule(com.radixdlt.harness.simulation.NodeNetworkMessagesModule) ECKeyPair(com.radixdlt.crypto.ECKeyPair) HashSigner(com.radixdlt.hotstuff.HashSigner) Self(com.radixdlt.hotstuff.bft.Self) Module(com.google.inject.Module) NodeNetworkMessagesModule(com.radixdlt.harness.simulation.NodeNetworkMessagesModule) AbstractModule(com.google.inject.AbstractModule) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule)

Aggregations

ECKeyPair (com.radixdlt.crypto.ECKeyPair)26 Test (org.junit.Test)19 HashCode (com.google.common.hash.HashCode)10 AbstractModule (com.google.inject.AbstractModule)6 SystemCounters (com.radixdlt.counters.SystemCounters)5 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)5 TypeLiteral (com.google.inject.TypeLiteral)4 TransferrableTokensParticle (com.radixdlt.application.tokens.TransferrableTokensParticle)4 CMError (com.radixdlt.constraintmachine.CMError)4 CMInstruction (com.radixdlt.constraintmachine.CMInstruction)4 ImmutableList (com.google.common.collect.ImmutableList)3 Guice (com.google.inject.Guice)3 Provides (com.google.inject.Provides)3 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)3 ECPublicKey (com.radixdlt.crypto.ECPublicKey)3 EventDispatcher (com.radixdlt.environment.EventDispatcher)3 Self (com.radixdlt.hotstuff.bft.Self)3 RadixAddress (com.radixdlt.identifiers.RadixAddress)3 AccumulatorState (com.radixdlt.ledger.AccumulatorState)3 Key (com.google.inject.Key)2