use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class EthGetUncleByBlockNumberAndIndexTest method blockWithMetadata.
public BlockWithMetadata<TransactionWithMetadata, Hash> blockWithMetadata(final BlockHeader header) {
final KeyPair keyPair = SignatureAlgorithmFactory.getInstance().generateKeyPair();
final List<TransactionWithMetadata> transactions = new ArrayList<>();
for (int i = 0; i < 3; i++) {
final Transaction transaction = transactionTestFixture.createTransaction(keyPair);
transactions.add(new TransactionWithMetadata(transaction, header.getNumber(), Optional.empty(), header.getHash(), 0));
}
final List<Hash> ommers = new ArrayList<>();
ommers.add(Hash.ZERO);
return new BlockWithMetadata<>(header, transactions, ommers, header.getDifficulty(), 0);
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class PublicKeySubCommandTest method callingPublicKeyExportSubCommandWithPrivateKeyFileMustWriteKeyToStandardOutput.
@Test
public void callingPublicKeyExportSubCommandWithPrivateKeyFileMustWriteKeyToStandardOutput() throws IOException {
final SECPPrivateKey privateKey = SECPPrivateKey.create(Bytes32.fromHexString("0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"), ALGORITHM);
final KeyPair keyPair = KeyPair.create(privateKey, curve, ALGORITHM);
final Path privateKeyFile = Files.createTempFile("private", "address");
Files.writeString(privateKeyFile, privateKey.toString());
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, PUBLIC_KEY_EXPORT_SUBCOMMAND_NAME, "--node-private-key-file", privateKeyFile.toString());
final String expectedOutputStart = keyPair.getPublicKey().toString();
assertThat(commandOutput.toString(UTF_8)).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class GetPooledTransactionsFromPeerTaskTest method generateDataToBeRequested.
@Override
protected List<Transaction> generateDataToBeRequested() {
final List<Transaction> requestedData = new ArrayList<>();
KeyPair keyPair = SignatureAlgorithmFactory.getInstance().generateKeyPair();
for (int i = 0; i < 3; i++) {
Transaction tx = new TransactionTestFixture().nonce(i).gasLimit(100000).chainId(Optional.empty()).createTransaction(keyPair);
assertThat(transactionPool.getPendingTransactions().addLocalTransaction(tx)).isEqualTo(TransactionAddedStatus.ADDED);
requestedData.add(tx);
}
return requestedData;
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class PeerDiscoveryAgentTest method testNodeRecordCreatedUpdatesDiscoveryPeer.
@Test
public void testNodeRecordCreatedUpdatesDiscoveryPeer() {
KeyPair keyPair = SIGNATURE_ALGORITHM.get().createKeyPair(SIGNATURE_ALGORITHM.get().createPrivateKey(Bytes32.fromHexString("0xb71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")));
final MockPeerDiscoveryAgent agent = helper.startDiscoveryAgent(helper.agentBuilder().nodeKey(NodeKeyUtils.createFrom(keyPair)).advertisedHost("127.0.0.1").bindPort(30303));
agent.start(30303);
final NodeRecord pre = agent.getLocalNode().get().getNodeRecord().get();
agent.updateNodeRecord();
final NodeRecord post = agent.getLocalNode().get().getNodeRecord().get();
assertThat(pre).isNotEqualTo(post);
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class PeerDiscoveryAgentTest method testNodeRecordNotUpdatedIfNoPeerDiscovery.
@Test
public void testNodeRecordNotUpdatedIfNoPeerDiscovery() {
KeyPair keyPair = SIGNATURE_ALGORITHM.get().createKeyPair(SIGNATURE_ALGORITHM.get().createPrivateKey(Bytes32.fromHexString("0xb71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")));
final MockPeerDiscoveryAgent agent = helper.startDiscoveryAgent(helper.agentBuilder().nodeKey(NodeKeyUtils.createFrom(keyPair)).advertisedHost("127.0.0.1").bindPort(30303).active(false));
assertThatCode(agent::updateNodeRecord).doesNotThrowAnyException();
}
Aggregations