use of org.hyperledger.besu.crypto.SECP256K1 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.crypto.SECP256K1 in project besu by hyperledger.
the class MainnetTransactionValidatorTest method shouldRejectTransactionWithMaxFeeTimesGasLimitGreaterThanBalance.
@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));
}
use of org.hyperledger.besu.crypto.SECP256K1 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.crypto.SECP256K1 in project besu by hyperledger.
the class RunnerBuilderTest method setup.
@Before
public void setup() {
final SubProtocolConfiguration subProtocolConfiguration = mock(SubProtocolConfiguration.class);
final EthProtocolManager ethProtocolManager = mock(EthProtocolManager.class);
final EthContext ethContext = mock(EthContext.class);
final ProtocolContext protocolContext = mock(ProtocolContext.class);
final NodeKey nodeKey = new NodeKey(new KeyPairSecurityModule(new SECP256K1().generateKeyPair()));
when(subProtocolConfiguration.getProtocolManagers()).thenReturn(Collections.singletonList(new BftProtocolManager(mock(BftEventQueue.class), mock(PeerConnectionTracker.class), IbftSubProtocol.IBFV1, IbftSubProtocol.get().getName())));
when(ethContext.getScheduler()).thenReturn(mock(EthScheduler.class));
when(ethProtocolManager.ethContext()).thenReturn(ethContext);
when(subProtocolConfiguration.getSubProtocols()).thenReturn(Collections.singletonList(new IbftSubProtocol()));
when(protocolContext.getBlockchain()).thenReturn(mock(DefaultBlockchain.class));
when(besuController.getProtocolManager()).thenReturn(ethProtocolManager);
when(besuController.getSubProtocolConfiguration()).thenReturn(subProtocolConfiguration);
when(besuController.getProtocolContext()).thenReturn(protocolContext);
when(besuController.getProtocolSchedule()).thenReturn(mock(ProtocolSchedule.class));
when(besuController.getNodeKey()).thenReturn(nodeKey);
when(besuController.getMiningParameters()).thenReturn(mock(MiningParameters.class));
when(besuController.getPrivacyParameters()).thenReturn(mock(PrivacyParameters.class));
when(besuController.getTransactionPool()).thenReturn(mock(TransactionPool.class));
when(besuController.getSynchronizer()).thenReturn(mock(Synchronizer.class));
when(besuController.getMiningCoordinator()).thenReturn(mock(MiningCoordinator.class));
}
Aggregations