Search in sources :

Example 6 with ECKeyPair

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

the class CMTokensTest method when_correct_1_input_to_2_outputs_token_send__then_should_not_error.

@Test
public void when_correct_1_input_to_2_outputs_token_send__then_should_not_error() {
    ECKeyPair sender = ECKeyPair.generateNew();
    RadixAddress senderAddress = new RadixAddress((byte) 0, sender.getPublicKey());
    RadixAddress receiverAddress = new RadixAddress((byte) 0, ECKeyPair.generateNew().getPublicKey());
    TransferrableTokensParticle input = new TransferrableTokensParticle(senderAddress, UInt256.THREE, this.granularity, this.token, this.permissions);
    TransferrableTokensParticle output0 = new TransferrableTokensParticle(senderAddress, UInt256.TWO, UInt256.ONE, this.token, this.permissions);
    TransferrableTokensParticle output1 = new TransferrableTokensParticle(receiverAddress, UInt256.ONE, this.granularity, this.token, this.permissions);
    HashCode witness = HashUtils.random256();
    CMInstruction cmInstruction = new CMInstruction(ImmutableList.of(CMMicroInstruction.checkSpinAndPush(input, Spin.UP), CMMicroInstruction.checkSpinAndPush(output0, Spin.NEUTRAL), CMMicroInstruction.checkSpinAndPush(output1, Spin.NEUTRAL), CMMicroInstruction.particleGroup()), ImmutableMap.of(sender.euid(), sender.sign(witness)));
    Optional<CMError> error = cm.validate(cmInstruction, witness, PermissionLevel.USER);
    error.map(CMError::getCmValidationState).ifPresent(System.out::println);
    assertThat(error).isEmpty();
}
Also used : HashCode(com.google.common.hash.HashCode) CMError(com.radixdlt.constraintmachine.CMError) ECKeyPair(com.radixdlt.crypto.ECKeyPair) CMInstruction(com.radixdlt.constraintmachine.CMInstruction) RadixAddress(com.radixdlt.identifiers.RadixAddress) TransferrableTokensParticle(com.radixdlt.application.tokens.TransferrableTokensParticle) Test(org.junit.Test)

Example 7 with ECKeyPair

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

the class ConsensusModuleTest method getExternalModule.

private Module getExternalModule() {
    return new AbstractModule() {

        @Override
        protected void configure() {
            bind(Ledger.class).toInstance(mock(Ledger.class));
            bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTInsertUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTRebuildUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTHighQCUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTCommittedUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LocalSyncRequest>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(requestSender);
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
            }).toInstance(responseSender);
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
            }).toInstance(errorResponseSender);
            bind(new TypeLiteral<EventDispatcher<NoVote>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<View>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
            bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
            bind(NextTxnsGenerator.class).toInstance(mock(NextTxnsGenerator.class));
            bind(SystemCounters.class).toInstance(mock(SystemCounters.class));
            bind(TimeSupplier.class).toInstance(mock(TimeSupplier.class));
            bind(BFTConfiguration.class).toInstance(bftConfiguration);
            bind(BFTValidatorSet.class).toInstance(bftConfiguration.getValidatorSet());
            LedgerProof proof = mock(LedgerProof.class);
            when(proof.getView()).thenReturn(View.genesis());
            bind(LedgerProof.class).annotatedWith(LastProof.class).toInstance(proof);
            bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
            bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(200);
            bindConstant().annotatedWith(PacemakerTimeout.class).to(1000L);
            bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
            bindConstant().annotatedWith(PacemakerMaxExponent.class).to(6);
            ECKeyPair ecKeyPair = ECKeyPair.generateNew();
            bind(HashSigner.class).toInstance(ecKeyPair::sign);
        }

        @Provides
        ViewUpdate viewUpdate(@Self BFTNode node) {
            return ViewUpdate.create(View.of(1), mock(HighQC.class), node, node);
        }

        @Provides
        @Self
        private BFTNode bftNode() {
            return BFTNode.create(ecKeyPair.getPublicKey());
        }
    };
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) TimeSupplier(com.radixdlt.utils.TimeSupplier) Self(com.radixdlt.hotstuff.bft.Self) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) EventDispatcher(com.radixdlt.environment.EventDispatcher) TypeLiteral(com.google.inject.TypeLiteral) LedgerProof(com.radixdlt.hotstuff.LedgerProof) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) NoVote(com.radixdlt.hotstuff.bft.NoVote) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) Ledger(com.radixdlt.hotstuff.Ledger) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ECKeyPair(com.radixdlt.crypto.ECKeyPair) HashSigner(com.radixdlt.hotstuff.HashSigner) SystemCounters(com.radixdlt.counters.SystemCounters) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) View(com.radixdlt.hotstuff.bft.View) AbstractModule(com.google.inject.AbstractModule) LastProof(com.radixdlt.store.LastProof) NoVote(com.radixdlt.hotstuff.bft.NoVote) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Proposal(com.radixdlt.hotstuff.Proposal)

Example 8 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 9 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 10 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)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