Search in sources :

Example 26 with KeyPair

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);
}
Also used : KeyPair(org.hyperledger.besu.crypto.KeyPair) Transaction(org.hyperledger.besu.ethereum.core.Transaction) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) ArrayList(java.util.ArrayList) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) Hash(org.hyperledger.besu.datatypes.Hash)

Example 27 with KeyPair

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();
}
Also used : Path(java.nio.file.Path) KeyPair(org.hyperledger.besu.crypto.KeyPair) SECPPrivateKey(org.hyperledger.besu.crypto.SECPPrivateKey) Test(org.junit.Test)

Example 28 with KeyPair

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;
}
Also used : KeyPair(org.hyperledger.besu.crypto.KeyPair) TransactionTestFixture(org.hyperledger.besu.ethereum.core.TransactionTestFixture) Transaction(org.hyperledger.besu.ethereum.core.Transaction) ArrayList(java.util.ArrayList)

Example 29 with KeyPair

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);
}
Also used : NodeRecord(org.ethereum.beacon.discovery.schema.NodeRecord) KeyPair(org.hyperledger.besu.crypto.KeyPair) MockPeerDiscoveryAgent(org.hyperledger.besu.ethereum.p2p.discovery.internal.MockPeerDiscoveryAgent) Test(org.junit.Test)

Example 30 with KeyPair

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();
}
Also used : KeyPair(org.hyperledger.besu.crypto.KeyPair) MockPeerDiscoveryAgent(org.hyperledger.besu.ethereum.p2p.discovery.internal.MockPeerDiscoveryAgent) Test(org.junit.Test)

Aggregations

KeyPair (org.hyperledger.besu.crypto.KeyPair)34 Test (org.junit.Test)21 Address (org.hyperledger.besu.datatypes.Address)14 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)13 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)10 IbftExtraData (org.hyperledger.besu.consensus.ibftlegacy.IbftExtraData)9 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)9 Transaction (org.hyperledger.besu.ethereum.core.Transaction)7 SignatureAlgorithm (org.hyperledger.besu.crypto.SignatureAlgorithm)5 ArrayList (java.util.ArrayList)4 SECPPrivateKey (org.hyperledger.besu.crypto.SECPPrivateKey)4 BigInteger (java.math.BigInteger)3 Bytes (org.apache.tuweni.bytes.Bytes)3 Path (java.nio.file.Path)2 Collection (java.util.Collection)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 NodeRecord (org.ethereum.beacon.discovery.schema.NodeRecord)2 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)2 Hash (org.hyperledger.besu.datatypes.Hash)2 BlockWithMetadata (org.hyperledger.besu.ethereum.api.query.BlockWithMetadata)2