use of org.hyperledger.besu.ethereum.core.Transaction 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.Transaction 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());
}
use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class MainnetTransactionValidatorTest method shouldValidate1559TransactionWithPriceLowerThanBaseFeeForTransactionPool.
@Test
public void shouldValidate1559TransactionWithPriceLowerThanBaseFeeForTransactionPool() {
final MainnetTransactionValidator validator = new MainnetTransactionValidator(gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), Set.of(TransactionType.FRONTIER, TransactionType.EIP1559), defaultGoQuorumCompatibilityMode);
final Transaction transaction = new TransactionTestFixture().maxPriorityFeePerGas(Optional.of(Wei.of(1))).maxFeePerGas(Optional.of(Wei.of(1))).type(TransactionType.EIP1559).chainId(Optional.of(BigInteger.ONE)).createTransaction(senderKeys);
when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(50L);
assertThat(validator.validate(transaction, Optional.of(Wei.ONE), TransactionValidationParams.transactionPool())).isEqualTo(ValidationResult.valid());
}
use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class MainnetTransactionValidatorTest method shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce.
@Test
public void shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce() {
final MainnetTransactionValidator validator = new MainnetTransactionValidator(gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode);
final Transaction transaction = new TransactionTestFixture().nonce(11).createTransaction(senderKeys);
final Account account = accountWithNonce(5);
assertThat(validator.validateForSender(transaction, account, false)).isEqualTo(ValidationResult.invalid(TransactionInvalidReason.INCORRECT_NONCE));
}
use of org.hyperledger.besu.ethereum.core.Transaction in project besu by hyperledger.
the class MainnetTransactionValidatorTest method shouldRejectTransactionWithMaxPriorityFeeGreaterThanMaxFee.
@Test
public void shouldRejectTransactionWithMaxPriorityFeeGreaterThanMaxFee() {
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.of(7)).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(MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS));
assertThat(validationResult.getErrorMessage()).isEqualTo("max priority fee per gas cannot be greater than max fee per gas");
}
Aggregations