Search in sources :

Example 1 with TransactionInvalidReason

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");
}
Also used : Transaction(org.hyperledger.besu.ethereum.core.Transaction) SECP256K1(org.hyperledger.besu.crypto.SECP256K1) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Test(org.junit.Test)

Example 2 with TransactionInvalidReason

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");
}
Also used : Transaction(org.hyperledger.besu.ethereum.core.Transaction) SECP256K1(org.hyperledger.besu.crypto.SECP256K1) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Test(org.junit.Test)

Example 3 with TransactionInvalidReason

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;
        }
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)

Example 4 with TransactionInvalidReason

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);
}
Also used : EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Transaction(org.hyperledger.besu.ethereum.core.Transaction) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Wei(org.hyperledger.besu.datatypes.Wei) Test(org.junit.Test)

Example 5 with TransactionInvalidReason

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);
}
Also used : EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) TransactionTestFixture(org.hyperledger.besu.ethereum.core.TransactionTestFixture) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Optional(java.util.Optional) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Test(org.junit.Test)

Aggregations

TransactionInvalidReason (org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason)25 Transaction (org.hyperledger.besu.ethereum.core.Transaction)17 Wei (org.hyperledger.besu.datatypes.Wei)9 Test (org.junit.Test)9 Optional (java.util.Optional)7 TransactionTestFixture (org.hyperledger.besu.ethereum.core.TransactionTestFixture)6 TransactionProcessingResult (org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)6 Bytes (org.apache.tuweni.bytes.Bytes)5 Address (org.hyperledger.besu.datatypes.Address)5 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)5 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)5 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)4 MainnetTransactionValidator (org.hyperledger.besu.ethereum.mainnet.MainnetTransactionValidator)4 TransactionValidationParams (org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams)4 Account (org.hyperledger.besu.evm.account.Account)4 EvmAccount (org.hyperledger.besu.evm.account.EvmAccount)4 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 HashSet (java.util.HashSet)3