Search in sources :

Example 1 with SECP256K1

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

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));
}
Also used : SECP256K1(org.hyperledger.besu.crypto.SECP256K1) Test(org.junit.Test)

Example 3 with SECP256K1

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

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));
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) SECP256K1(org.hyperledger.besu.crypto.SECP256K1) BftProtocolManager(org.hyperledger.besu.consensus.common.bft.protocol.BftProtocolManager) IbftSubProtocol(org.hyperledger.besu.consensus.ibft.protocol.IbftSubProtocol) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) MergeMiningCoordinator(org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator) MiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) PeerConnectionTracker(org.hyperledger.besu.consensus.common.bft.network.PeerConnectionTracker) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) SubProtocolConfiguration(org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) KeyPairSecurityModule(org.hyperledger.besu.crypto.KeyPairSecurityModule) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) DefaultBlockchain(org.hyperledger.besu.ethereum.chain.DefaultBlockchain) NodeKey(org.hyperledger.besu.crypto.NodeKey) Before(org.junit.Before)

Aggregations

SECP256K1 (org.hyperledger.besu.crypto.SECP256K1)4 Test (org.junit.Test)3 Transaction (org.hyperledger.besu.ethereum.core.Transaction)2 TransactionInvalidReason (org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason)2 BftEventQueue (org.hyperledger.besu.consensus.common.bft.BftEventQueue)1 PeerConnectionTracker (org.hyperledger.besu.consensus.common.bft.network.PeerConnectionTracker)1 BftProtocolManager (org.hyperledger.besu.consensus.common.bft.protocol.BftProtocolManager)1 IbftSubProtocol (org.hyperledger.besu.consensus.ibft.protocol.IbftSubProtocol)1 MergeMiningCoordinator (org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator)1 KeyPairSecurityModule (org.hyperledger.besu.crypto.KeyPairSecurityModule)1 NodeKey (org.hyperledger.besu.crypto.NodeKey)1 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 MiningCoordinator (org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator)1 PoWMiningCoordinator (org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator)1 DefaultBlockchain (org.hyperledger.besu.ethereum.chain.DefaultBlockchain)1 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)1 PrivacyParameters (org.hyperledger.besu.ethereum.core.PrivacyParameters)1 Synchronizer (org.hyperledger.besu.ethereum.core.Synchronizer)1 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)1 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)1