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();
}
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());
}
};
}
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