use of org.hyperledger.besu.ethereum.core.TransactionTestFixture 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.TransactionTestFixture in project besu by hyperledger.
the class BaseFeeBlockBodyValidatorTest method BlockBodyValidatorFail_MaxFeePerGas.
@Test
public void BlockBodyValidatorFail_MaxFeePerGas() {
when(blockHeader.getBaseFee()).thenReturn(Optional.of(Wei.of(10L)));
when(block.getBody()).thenReturn(new BlockBody(List.of(// underpriced eip1559 transaction
new TransactionTestFixture().maxFeePerGas(Optional.of(Wei.of(1L))).maxPriorityFeePerGas(Optional.of(Wei.of(10L))).type(TransactionType.EIP1559).createTransaction(keyPair)), Collections.emptyList()));
assertThat(blockBodyValidator.validateTransactionGasPrice(block)).isFalse();
}
use of org.hyperledger.besu.ethereum.core.TransactionTestFixture in project besu by hyperledger.
the class BaseFeeBlockBodyValidatorTest method BlockBodyValidatorFail_GasPrice.
@Test
public void BlockBodyValidatorFail_GasPrice() {
when(blockHeader.getBaseFee()).thenReturn(Optional.of(Wei.of(10L)));
when(block.getBody()).thenReturn(new BlockBody(List.of(// underpriced frontier transaction
new TransactionTestFixture().gasPrice(Wei.of(9L)).createTransaction(keyPair)), Collections.emptyList()));
assertThat(blockBodyValidator.validateTransactionGasPrice(block)).isFalse();
}
use of org.hyperledger.besu.ethereum.core.TransactionTestFixture in project besu by hyperledger.
the class MainnetTransactionValidatorTest method shouldRejectTransactionIfIntrinsicGasExceedsGasLimit.
@Test
public void shouldRejectTransactionIfIntrinsicGasExceedsGasLimit() {
final MainnetTransactionValidator validator = new MainnetTransactionValidator(gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode);
final Transaction transaction = new TransactionTestFixture().gasLimit(10).chainId(Optional.empty()).createTransaction(senderKeys);
when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(50L);
assertThat(validator.validate(transaction, Optional.empty(), transactionValidationParams)).isEqualTo(ValidationResult.invalid(TransactionInvalidReason.INTRINSIC_GAS_EXCEEDS_GAS_LIMIT));
}
use of org.hyperledger.besu.ethereum.core.TransactionTestFixture in project besu by hyperledger.
the class MainnetTransactionValidatorTest method shouldAcceptOnlyTransactionsInAcceptedTransactionTypes.
@Test
public void shouldAcceptOnlyTransactionsInAcceptedTransactionTypes() {
final MainnetTransactionValidator frontierValidator = new MainnetTransactionValidator(gasCalculator, FeeMarket.legacy(), false, Optional.of(BigInteger.ONE), Set.of(TransactionType.FRONTIER), defaultGoQuorumCompatibilityMode);
final MainnetTransactionValidator eip1559Validator = new MainnetTransactionValidator(gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), Set.of(TransactionType.FRONTIER, TransactionType.EIP1559), defaultGoQuorumCompatibilityMode);
final Transaction transaction = new TransactionTestFixture().type(TransactionType.EIP1559).maxPriorityFeePerGas(Optional.of(Wei.of(3))).maxFeePerGas(Optional.of(Wei.of(6))).gasLimit(21000).chainId(Optional.of(BigInteger.ONE)).createTransaction(senderKeys);
assertThat(frontierValidator.validate(transaction, Optional.empty(), transactionValidationParams)).isEqualTo(ValidationResult.invalid(INVALID_TRANSACTION_FORMAT));
when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(0L);
assertThat(eip1559Validator.validate(transaction, Optional.of(Wei.ONE), transactionValidationParams)).isEqualTo(ValidationResult.valid());
}
Aggregations