use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class PendingTransactionsSenderTest method testSendEth65PeersOnly.
@Test
public void testSendEth65PeersOnly() {
PeerPendingTransactionTracker peerPendingTransactionTracker = mock(PeerPendingTransactionTracker.class);
PendingTransactionsMessageSender pendingTransactionsMessageSender = mock(PendingTransactionsMessageSender.class);
EthContext ethContext = mock(EthContext.class);
EthScheduler ethScheduler = mock(EthScheduler.class);
when(ethContext.getScheduler()).thenReturn(ethScheduler);
PendingTransactionSender sender = new PendingTransactionSender(peerPendingTransactionTracker, pendingTransactionsMessageSender, ethContext);
EthPeer peer1 = mock(EthPeer.class);
EthPeer peer2 = mock(EthPeer.class);
Transaction tx = mock(Transaction.class);
Hash hash = Hash.wrap(Bytes32.random());
when(tx.getHash()).thenReturn(hash);
EthPeers ethPeers = mock(EthPeers.class);
when(ethContext.getEthPeers()).thenReturn(ethPeers);
when(ethPeers.streamAvailablePeers()).thenReturn(Arrays.asList(peer1, peer2).stream());
when(peerPendingTransactionTracker.isPeerSupported(peer1, EthProtocol.ETH65)).thenReturn(true);
when(peerPendingTransactionTracker.isPeerSupported(peer2, EthProtocol.ETH65)).thenReturn(false);
sender.onTransactionsAdded(Collections.singleton(tx));
verify(peerPendingTransactionTracker, times(1)).addToPeerSendQueue(peer1, hash);
verify(peerPendingTransactionTracker, never()).addToPeerSendQueue(peer2, hash);
}
use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class TransactionPoolTest method shouldRejectRemoteTransactionsWhenNotInSync.
@Test
public void shouldRejectRemoteTransactionsWhenNotInSync() {
SyncState syncState = mock(SyncState.class);
when(syncState.isInSync(anyLong())).thenReturn(false);
TransactionPool transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, batchAddedListener, pendingBatchAddedListener, syncState, ethContext, peerTransactionTracker, peerPendingTransactionTracker, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, TransactionPoolConfiguration.DEFAULT);
final TransactionTestFixture builder = new TransactionTestFixture();
final Transaction transaction1 = builder.nonce(1).createTransaction(KEY_PAIR1);
final Transaction transaction2 = builder.nonce(2).createTransaction(KEY_PAIR1);
final Transaction transaction3 = builder.nonce(3).createTransaction(KEY_PAIR1);
transactionPool.addRemoteTransactions(asList(transaction3, transaction1, transaction2));
assertTransactionNotPending(transaction1);
assertTransactionNotPending(transaction2);
assertTransactionNotPending(transaction3);
verifyNoInteractions(batchAddedListener);
}
use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class PeerPendingTransactionTrackerTest method setUp.
@Before
public void setUp() {
tracker = new PeerPendingTransactionTracker(pendingTransactions);
Transaction tx = mock(Transaction.class);
when(pendingTransactions.getTransactionByHash(any())).thenReturn(Optional.of(tx));
}
use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class MainnetTransactionValidatorTest method shouldRejectTransactionWhenEffectiveGasPriceIsTooLow.
@Test
public void shouldRejectTransactionWhenEffectiveGasPriceIsTooLow() {
final MainnetTransactionValidator validator = new MainnetTransactionValidator(gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), Set.of(TransactionType.values()), defaultGoQuorumCompatibilityMode);
validator.setTransactionFilter(transactionFilter(true));
final Transaction transaction = Transaction.builder().type(TransactionType.EIP1559).nonce(0).maxPriorityFeePerGas(Wei.ZERO).maxFeePerGas(Wei.of(4)).gasLimit(15).to(Address.ZERO).value(Wei.of(0)).payload(Bytes.EMPTY).chainId(BigInteger.ONE).signAndBuild(new SECP256K1().generateKeyPair());
final ValidationResult<TransactionInvalidReason> validationResult = validator.validate(transaction, Optional.of(Wei.ONE), transactionValidationParams);
assertThat(validationResult).isEqualTo(ValidationResult.invalid(INVALID_TRANSACTION_FORMAT));
assertThat(validationResult.getErrorMessage()).isEqualTo("effective gas price is too low to execute");
}
use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class BlockchainQueries method transactionByHash.
/**
* Given a transaction hash, returns the associated transaction.
*
* @param transactionHash The hash of the target transaction.
* @return The transaction associated with the given hash.
*/
public Optional<TransactionWithMetadata> transactionByHash(final Hash transactionHash) {
final Optional<TransactionLocation> maybeLocation = blockchain.getTransactionLocation(transactionHash);
if (maybeLocation.isEmpty()) {
return Optional.empty();
}
final TransactionLocation loc = maybeLocation.get();
final Hash blockHash = loc.getBlockHash();
// getTransactionLocation should not return if the TX or block doesn't exist, so throwing
// on a missing optional is appropriate.
final BlockHeader header = blockchain.getBlockHeader(blockHash).orElseThrow();
final Transaction transaction = blockchain.getTransactionByHash(transactionHash).orElseThrow();
return Optional.of(new TransactionWithMetadata(transaction, header.getNumber(), header.getBaseFee(), blockHash, loc.getTransactionIndex()));
}
Aggregations