|
|
@ -16,6 +16,8 @@ package org.hyperledger.besu.ethereum.mainnet; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.GAS_PRICE_MUST_BE_ZERO; |
|
|
|
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.GAS_PRICE_MUST_BE_ZERO; |
|
|
|
|
|
|
|
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.INVALID_TRANSACTION_FORMAT; |
|
|
|
|
|
|
|
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.anyBoolean; |
|
|
|
import static org.mockito.ArgumentMatchers.anyBoolean; |
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
@ -24,6 +26,7 @@ import static org.mockito.Mockito.verifyZeroInteractions; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
import org.hyperledger.besu.crypto.KeyPair; |
|
|
|
import org.hyperledger.besu.crypto.KeyPair; |
|
|
|
|
|
|
|
import org.hyperledger.besu.crypto.SECP256K1; |
|
|
|
import org.hyperledger.besu.crypto.SignatureAlgorithm; |
|
|
|
import org.hyperledger.besu.crypto.SignatureAlgorithm; |
|
|
|
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; |
|
|
|
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; |
|
|
|
import org.hyperledger.besu.ethereum.core.Account; |
|
|
|
import org.hyperledger.besu.ethereum.core.Account; |
|
|
@ -45,6 +48,7 @@ import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.base.Supplier; |
|
|
|
import com.google.common.base.Supplier; |
|
|
|
import com.google.common.base.Suppliers; |
|
|
|
import com.google.common.base.Suppliers; |
|
|
|
|
|
|
|
import org.apache.tuweni.bytes.Bytes; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
@ -205,6 +209,63 @@ public class MainnetTransactionValidatorTest { |
|
|
|
.isEqualTo(ValidationResult.valid()); |
|
|
|
.isEqualTo(ValidationResult.valid()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void shouldRejectTransactionWithMaxFeeTimesGasLimitGreaterThanBalance() { |
|
|
|
|
|
|
|
final MainnetTransactionValidator validator = |
|
|
|
|
|
|
|
new MainnetTransactionValidator( |
|
|
|
|
|
|
|
gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); |
|
|
|
|
|
|
|
validator.setTransactionFilter(transactionFilter(true)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat( |
|
|
|
|
|
|
|
validator.validateForSender( |
|
|
|
|
|
|
|
Transaction.builder() |
|
|
|
|
|
|
|
.type(TransactionType.EIP1559) |
|
|
|
|
|
|
|
.nonce(0) |
|
|
|
|
|
|
|
.maxPriorityFeePerGas(Wei.of(5)) |
|
|
|
|
|
|
|
.maxFeePerGas(Wei.of(7)) |
|
|
|
|
|
|
|
.gasLimit(15) |
|
|
|
|
|
|
|
.to(Address.ZERO) |
|
|
|
|
|
|
|
.value(Wei.of(0)) |
|
|
|
|
|
|
|
.payload(Bytes.EMPTY) |
|
|
|
|
|
|
|
.chainId(BigInteger.ONE) |
|
|
|
|
|
|
|
.signAndBuild(new SECP256K1().generateKeyPair()), |
|
|
|
|
|
|
|
account(Wei.of(100), 0), |
|
|
|
|
|
|
|
true)) |
|
|
|
|
|
|
|
.isEqualTo(ValidationResult.invalid(UPFRONT_COST_EXCEEDS_BALANCE)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void shouldRejectTransactionWithMaxPriorityFeeGreaterThanMaxFee() { |
|
|
|
|
|
|
|
final MainnetTransactionValidator validator = |
|
|
|
|
|
|
|
new MainnetTransactionValidator( |
|
|
|
|
|
|
|
gasCalculator, |
|
|
|
|
|
|
|
Optional.of(TransactionPriceCalculator.eip1559()), |
|
|
|
|
|
|
|
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(1L)); |
|
|
|
|
|
|
|
assertThat(validationResult).isEqualTo(ValidationResult.invalid(INVALID_TRANSACTION_FORMAT)); |
|
|
|
|
|
|
|
assertThat(validationResult.getErrorMessage()) |
|
|
|
|
|
|
|
.isEqualTo("max priority fee per gas cannot be greater than max fee per gas"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void shouldPropagateCorrectStateChangeParamToTransactionFilter() { |
|
|
|
public void shouldPropagateCorrectStateChangeParamToTransactionFilter() { |
|
|
|
final ArgumentCaptor<Boolean> stateChangeLocalParamCaptor = |
|
|
|
final ArgumentCaptor<Boolean> stateChangeLocalParamCaptor = |
|
|
|