Search in sources :

Example 1 with TransactionTestFixture

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

Example 2 with TransactionTestFixture

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

Example 3 with TransactionTestFixture

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

Example 4 with TransactionTestFixture

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

Example 5 with TransactionTestFixture

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

Aggregations

TransactionTestFixture (org.hyperledger.besu.ethereum.core.TransactionTestFixture)39 Test (org.junit.Test)37 Transaction (org.hyperledger.besu.ethereum.core.Transaction)34 Optional (java.util.Optional)12 Account (org.hyperledger.besu.evm.account.Account)11 TransactionValidationParams (org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams)10 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)8 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)6 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)6 TransactionInvalidReason (org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason)6 Address (org.hyperledger.besu.datatypes.Address)5 ArrayList (java.util.ArrayList)4 Wei (org.hyperledger.besu.datatypes.Wei)4 ProcessableBlockHeader (org.hyperledger.besu.ethereum.core.ProcessableBlockHeader)4 KeyPair (org.hyperledger.besu.crypto.KeyPair)3 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)3 RespondingEthPeer (org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer)2 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)2 SignatureAlgorithm (org.hyperledger.besu.crypto.SignatureAlgorithm)1 TransactionWithMetadata (org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata)1