use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method getExternalModule.
private Module getExternalModule() {
return new AbstractModule() {
@Override
public void configure() {
var validatorSet = BFTValidatorSet.from(registeredNodes.stream().map(ECKeyPair::getPublicKey).map(BFTNode::create).map(n -> BFTValidator.from(n, UInt256.ONE)));
bind(ProposerElection.class).toInstance(new WeightedRotatingLeaders(validatorSet));
bind(Serialization.class).toInstance(serialization);
bind(Hasher.class).toInstance(Sha256Hasher.withDefaultSerialization());
bind(new TypeLiteral<EngineStore<LedgerAndBFTProof>>() {
}).toInstance(engineStore);
bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
install(MempoolConfig.asModule(10, 10));
install(new MainnetForksModule());
install(new RadixEngineForksLatestOnlyModule());
install(new ForksModule());
// HACK
bind(CommittedReader.class).toInstance(new NoOpCommittedReader());
bind(ForksEpochStore.class).toInstance(new NoOpForksEpochStore());
bind(LedgerAccumulator.class).to(SimpleLedgerAccumulatorAndVerifier.class);
bind(new TypeLiteral<EventDispatcher<MempoolAddSuccess>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<InvalidProposedTxn>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<TxnsRemovedFromMempool>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<REOutput>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<MempoolRelayTrigger>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(SystemCounters.class).to(SystemCountersImpl.class);
}
};
}
use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.
the class P2PTestNetworkRunner method createInjector.
private static Injector createInjector(MockP2PNetwork p2pNetwork, DeterministicNetwork network, P2PConfig p2pConfig, ECKeyPair nodeKey, RadixNodeUri selfUri, int selfNodeIndex) throws ParseException {
final var properties = new RuntimeProperties(new JSONObject(), new String[] {});
return Guice.createInjector(Modules.override(new P2PModule(properties)).with(new AbstractModule() {
@Override
protected void configure() {
bind(TestCounters.class).toInstance(new TestCounters());
bind(P2PConfig.class).toInstance(p2pConfig);
bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
bind(SystemCounters.class).to(SystemCountersImpl.class).in(Scopes.SINGLETON);
}
@Provides
public PeerOutboundBootstrap peerOutboundBootstrap(TestCounters testCounters) {
return uri -> {
testCounters.outboundChannelsBootstrapped += 1;
p2pNetwork.createChannel(selfNodeIndex, uri);
};
}
}), new PeerDiscoveryModule(), new PeerLivenessMonitorModule(), new DispatcherModule(), new AbstractModule() {
@Override
protected void configure() {
final var dbDir = new TemporaryFolder();
try {
dbDir.create();
} catch (IOException e) {
throw new RuntimeException(e);
}
bindConstant().annotatedWith(NetworkId.class).to(Network.LOCALNET.getId());
bind(Addressing.class).toInstance(Addressing.ofNetwork(Network.LOCALNET));
bindConstant().annotatedWith(DatabaseLocation.class).to(dbDir.getRoot().getAbsolutePath());
bindConstant().annotatedWith(DatabaseCacheSize.class).to(100_000L);
bind(ECKeyPair.class).annotatedWith(Self.class).toInstance(nodeKey);
bind(ECPublicKey.class).annotatedWith(Self.class).toInstance(nodeKey.getPublicKey());
bind(BFTNode.class).annotatedWith(Self.class).toInstance(BFTNode.create(nodeKey.getPublicKey()));
bind(String.class).annotatedWith(Self.class).toInstance(Addressing.ofNetwork(Network.LOCALNET).forValidators().of(nodeKey.getPublicKey()).substring(0, 10));
bind(ECKeyOps.class).toInstance(ECKeyOps.fromKeyPair(nodeKey));
bind(Environment.class).toInstance(network.createSender(BFTNode.create(nodeKey.getPublicKey())));
bind(RuntimeProperties.class).toInstance(properties);
bind(Serialization.class).toInstance(DefaultSerialization.getInstance());
bind(DeterministicProcessor.class);
Multibinder.newSetBinder(binder(), StartProcessorOnRunner.class);
bind(ForkConfig.class).annotatedWith(NewestForkConfig.class).toInstance(new FixedEpochForkConfig("genesis", null, 0L));
}
});
}
use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.
the class KeySignTestScenarioRunner method doRunTestVector.
@Override
public void doRunTestVector(KeySignTestVector testVector) throws AssertionError {
ECKeyPair keyPair = null;
try {
keyPair = ECKeyPair.fromPrivateKey(Bytes.fromHexString(testVector.input.privateKey));
} catch (Exception e) {
throw new AssertionError("Failed to construct private key from hex", e);
}
byte[] unhashedEncodedMessage = testVector.input.messageToSign.getBytes(StandardCharsets.UTF_8);
byte[] hashedMessageToSign = sha256Hash(unhashedEncodedMessage);
ECDSASignature signature = keyPair.sign(hashedMessageToSign, true, true);
assertEquals(testVector.expected.signature.r, signature.getR().toString(16));
assertEquals(testVector.expected.signature.s, signature.getS().toString(16));
}
use of com.radixdlt.crypto.ECKeyPair in project radixdlt by radixdlt.
the class MempoolTest method mempool_removes_multiple_conflicts_on_commit.
@Test
public void mempool_removes_multiple_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);
var txn2 = createTxn(keyPair, 3);
processor.handleMessage(getFirstPeer(), MempoolAdd.create(txn2), null);
// Act
var txn3 = 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(txn3), proof);
stateComputer.commit(commandsAndProof, 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_conflicting_commands_to_mempool.
@Test
public void add_conflicting_commands_to_mempool() 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);
MempoolAdd mempoolAddSuccess2 = MempoolAdd.create(txn2);
processor.handleMessage(getFirstPeer(), mempoolAddSuccess2, null);
// Assert
assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isEqualTo(2);
}
Aggregations