Search in sources :

Example 21 with Transaction

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

Example 22 with Transaction

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

Example 23 with Transaction

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

Example 24 with Transaction

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));
}
Also used : Account(org.hyperledger.besu.evm.account.Account) TransactionTestFixture(org.hyperledger.besu.ethereum.core.TransactionTestFixture) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Test(org.junit.Test)

Example 25 with Transaction

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");
}
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)

Aggregations

Transaction (org.hyperledger.besu.ethereum.core.Transaction)249 Test (org.junit.Test)149 ArrayList (java.util.ArrayList)57 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)45 TransactionTestFixture (org.hyperledger.besu.ethereum.core.TransactionTestFixture)45 Optional (java.util.Optional)42 Hash (org.hyperledger.besu.datatypes.Hash)38 Wei (org.hyperledger.besu.datatypes.Wei)38 Block (org.hyperledger.besu.ethereum.core.Block)35 List (java.util.List)33 Address (org.hyperledger.besu.datatypes.Address)33 Account (org.hyperledger.besu.evm.account.Account)29 TransactionInvalidReason (org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason)28 TransactionReceipt (org.hyperledger.besu.ethereum.core.TransactionReceipt)26 Bytes (org.apache.tuweni.bytes.Bytes)24 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)22 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)22 TransactionValidationParams (org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams)22 KeyPair (org.hyperledger.besu.crypto.KeyPair)21 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)20