use of org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason 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.transaction.TransactionInvalidReason 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");
}
use of org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason in project besu by hyperledger.
the class TransactionTest method milestone.
public void milestone(final TransactionTestCaseSpec spec, final String name, final String milestone, final GasCalculator gasCalculator, final Optional<Wei> baseFee) {
final TransactionTestCaseSpec.Expectation expected = spec.expectation(milestone);
try {
Bytes rlp = spec.getRlp();
// non-frontier transactions need to be opaque for parsing to work
if (rlp.get(0) > 0) {
final BytesValueRLPOutput output = new BytesValueRLPOutput();
output.writeBytes(rlp);
rlp = output.encoded();
}
// Test transaction deserialization (will throw an exception if it fails).
final Transaction transaction = Transaction.readFrom(RLP.input(rlp));
final ValidationResult<TransactionInvalidReason> validation = transactionValidator(milestone).validate(transaction, baseFee, TransactionValidationParams.processingBlock());
if (!validation.isValid()) {
throw new RuntimeException(String.format("Transaction is invalid %s - %s", validation.getInvalidReason(), transaction));
}
// Test rlp encoding
final Bytes actualRlp = RLP.encode(transaction::writeTo);
assertThat(expected.isSucceeds()).withFailMessage("Transaction " + name + "/" + milestone + " was supposed to be invalid").isTrue();
assertThat(actualRlp).isEqualTo(rlp);
assertThat(transaction.getSender()).isEqualTo(expected.getSender());
assertThat(transaction.getHash()).isEqualTo(expected.getHash());
final long intrinsicGasCost = gasCalculator.transactionIntrinsicGasCost(transaction.getPayload(), transaction.isContractCreation()) + (transaction.getAccessList().map(gasCalculator::accessListGasCost).orElse(0L));
assertThat(intrinsicGasCost).isEqualTo(expected.getIntrinsicGas());
} catch (final Exception e) {
if (expected.isSucceeds()) {
throw e;
}
}
}
use of org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason in project besu by hyperledger.
the class TransactionPoolTest method shouldRejectGoQuorumTransactionWithNonZeroValue.
@Test
public void shouldRejectGoQuorumTransactionWithNonZeroValue() {
when(transactionValidator.getGoQuorumCompatibilityMode()).thenReturn(true);
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
final EthContext ethContext = ethProtocolManager.ethContext();
final Wei twoEthers = Wei.fromEth(2);
final TransactionPool transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, transactionBroadcaster, ethContext, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, ImmutableTransactionPoolConfiguration.builder().txFeeCap(twoEthers).build());
final Transaction transaction37 = Transaction.builder().v(BigInteger.valueOf(37)).value(Wei.ONE).build();
final Transaction transaction38 = Transaction.builder().v(BigInteger.valueOf(38)).value(Wei.ONE).build();
final ValidationResult<TransactionInvalidReason> result37 = transactionPool.addLocalTransaction(transaction37);
final ValidationResult<TransactionInvalidReason> result38 = transactionPool.addLocalTransaction(transaction38);
assertThat(result37.getInvalidReason()).isEqualTo(TransactionInvalidReason.ETHER_VALUE_NOT_SUPPORTED);
assertThat(result38.getInvalidReason()).isEqualTo(TransactionInvalidReason.ETHER_VALUE_NOT_SUPPORTED);
}
use of org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason in project besu by hyperledger.
the class TransactionPoolTest method shouldIgnoreEIP1559TransactionWhenNotAllowed.
@Test
public void shouldIgnoreEIP1559TransactionWhenNotAllowed() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
final EthContext ethContext = ethProtocolManager.ethContext();
final TransactionPool transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, transactionBroadcaster, ethContext, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, ImmutableTransactionPoolConfiguration.builder().txFeeCap(Wei.ONE).build());
when(transactionValidator.validate(any(Transaction.class), any(Optional.class), any())).thenReturn(valid());
final Transaction transaction = new TransactionTestFixture().nonce(1).type(TransactionType.EIP1559).maxFeePerGas(Optional.of(Wei.ONE)).maxPriorityFeePerGas(Optional.of(Wei.ONE)).gasLimit(10).gasPrice(null).createTransaction(KEY_PAIR1);
final ValidationResult<TransactionInvalidReason> result = transactionPool.addLocalTransaction(transaction);
assertThat(result.getInvalidReason()).isEqualTo(TransactionInvalidReason.INVALID_TRANSACTION_FORMAT);
}
Aggregations