From ebd08b7caa60fe91ac74ff36f4549754d2576bb5 Mon Sep 17 00:00:00 2001 From: Wodann Date: Mon, 6 May 2024 20:58:55 +0000 Subject: [PATCH] test: fix Hardhat tests --- crates/edr_provider/src/error.rs | 5 +- .../edr_provider/src/requests/validation.rs | 4 + crates/edr_provider/tests/eip4844.rs | 94 ++++++++++++++++++- .../provider/modules/eth/methods/call.ts | 2 +- .../modules/eth/methods/estimateGas.ts | 2 +- .../modules/eth/methods/sendRawTransaction.ts | 13 --- .../modules/eth/methods/sendTransaction.ts | 2 +- 7 files changed, 103 insertions(+), 19 deletions(-) diff --git a/crates/edr_provider/src/error.rs b/crates/edr_provider/src/error.rs index 4c745e457..a8fb27c92 100644 --- a/crates/edr_provider/src/error.rs +++ b/crates/edr_provider/src/error.rs @@ -54,7 +54,9 @@ pub enum ProviderError { Creation(#[from] CreationError), #[error(transparent)] DebugTrace(#[from] DebugTraceError), - #[error("An EIP-4844 (shard blob) transaction was sent using `eth_sendTransaction`, but Hardhat only supports them via `eth_sendRawTransaction`. See https://github.com/NomicFoundation/hardhat/issues/5023")] + #[error("An EIP-4844 (shard blob) call request was received, but Hardhat only supports them via `eth_sendRawTransaction`. See https://github.com/NomicFoundation/hardhat/issues/5182")] + Eip4844CallRequestUnsupported, + #[error("An EIP-4844 (shard blob) transaction was received, but Hardhat only supports them via `eth_sendRawTransaction`. See https://github.com/NomicFoundation/hardhat/issues/5023")] Eip4844TransactionUnsupported, #[error("An EIP-4844 (shard blob) transaction is missing the to (receiver) parameter.")] Eip4844TransactionMissingReceiver, @@ -225,6 +227,7 @@ impl From> for jsonrpc::Error { ProviderError::Blockchain(_) => INVALID_INPUT, ProviderError::Creation(_) => INVALID_INPUT, ProviderError::DebugTrace(_) => INTERNAL_ERROR, + ProviderError::Eip4844CallRequestUnsupported => INVALID_INPUT, ProviderError::Eip4844TransactionMissingReceiver => INVALID_INPUT, ProviderError::Eip4844TransactionUnsupported => INVALID_INPUT, ProviderError::Eip712Error(_) => INVALID_INPUT, diff --git a/crates/edr_provider/src/requests/validation.rs b/crates/edr_provider/src/requests/validation.rs index f5471b99f..65b895501 100644 --- a/crates/edr_provider/src/requests/validation.rs +++ b/crates/edr_provider/src/requests/validation.rs @@ -187,6 +187,10 @@ pub fn validate_call_request( ) -> Result<(), ProviderError> { validate_post_merge_block_tags(spec_id, block_spec)?; + if call_request.blobs.is_some() | call_request.blob_hashes.is_some() { + return Err(ProviderError::Eip4844CallRequestUnsupported); + } + validate_transaction_and_call_request( spec_id, call_request diff --git a/crates/edr_provider/tests/eip4844.rs b/crates/edr_provider/tests/eip4844.rs index 26a812d8a..89c4701a4 100644 --- a/crates/edr_provider/tests/eip4844.rs +++ b/crates/edr_provider/tests/eip4844.rs @@ -4,7 +4,7 @@ use std::{convert::Infallible, str::FromStr}; use edr_defaults::SECRET_KEYS; use edr_eth::{ - remote::{self, PreEip1898BlockSpec}, + remote::{self, eth::CallRequest, PreEip1898BlockSpec}, rlp::{self, Decodable}, signature::{secret_key_from_str, secret_key_to_address}, transaction::{ @@ -14,7 +14,7 @@ use edr_eth::{ }, Eip4844TransactionRequest, EthTransactionRequest, SignedTransaction, Transaction, }, - AccountInfo, Address, Bytes, B256, U256, + AccountInfo, Address, Bytes, SpecId, B256, U256, }; use edr_evm::{EnvKzgSettings, ExecutableTransaction, KECCAK_EMPTY}; use edr_provider::{ @@ -130,6 +130,34 @@ fn fake_transaction() -> SignedTransaction { fake_pooled_transaction().into_payload() } +fn fake_call_request() -> anyhow::Result { + let transaction = fake_pooled_transaction(); + let blobs = transaction.blobs().map(|blobs| { + blobs + .iter() + .map(|blob| Bytes::copy_from_slice(blob.as_ref())) + .collect() + }); + let transaction = transaction.into_payload(); + let from = transaction.recover()?; + + Ok(CallRequest { + from: Some(from), + to: transaction.to(), + max_fee_per_gas: transaction.max_fee_per_gas(), + max_priority_fee_per_gas: transaction.max_priority_fee_per_gas(), + gas: Some(transaction.gas_limit()), + value: Some(transaction.value()), + data: Some(transaction.data().clone()), + access_list: transaction + .access_list() + .map(|access_list| access_list.0.clone()), + blobs, + blob_hashes: transaction.blob_hashes(), + ..CallRequest::default() + }) +} + fn fake_transaction_request() -> anyhow::Result { let transaction = fake_pooled_transaction(); let blobs = transaction.blobs().map(|blobs| { @@ -162,6 +190,68 @@ fn fake_transaction_request() -> anyhow::Result { }) } +#[tokio::test(flavor = "multi_thread")] +async fn call_unsupported() -> anyhow::Result<()> { + let request = fake_call_request()?; + + let logger = Box::new(NoopLogger); + let subscriber = Box::new(|_event| {}); + let mut config = create_test_config(); + config.hardfork = SpecId::SHANGHAI; + + let provider = Provider::new( + runtime::Handle::current(), + logger, + subscriber, + config, + CurrentTime, + )?; + + let error = provider + .handle_request(ProviderRequest::Single(MethodInvocation::Call( + request, None, None, + ))) + .expect_err("Must return an error"); + + assert!(matches!( + error, + ProviderError::Eip4844CallRequestUnsupported + )); + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn estimate_gas_unsupported() -> anyhow::Result<()> { + let request = fake_call_request()?; + + let logger = Box::new(NoopLogger); + let subscriber = Box::new(|_event| {}); + let mut config = create_test_config(); + config.hardfork = SpecId::SHANGHAI; + + let provider = Provider::new( + runtime::Handle::current(), + logger, + subscriber, + config, + CurrentTime, + )?; + + let error = provider + .handle_request(ProviderRequest::Single(MethodInvocation::EstimateGas( + request, None, + ))) + .expect_err("Must return an error"); + + assert!(matches!( + error, + ProviderError::Eip4844CallRequestUnsupported + )); + + Ok(()) +} + #[tokio::test(flavor = "multi_thread")] async fn send_transaction_unsupported() -> anyhow::Result<()> { let transaction = fake_transaction_request()?; diff --git a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/call.ts b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/call.ts index ec635c679..5740a86f7 100644 --- a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/call.ts +++ b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/call.ts @@ -1617,7 +1617,7 @@ contract C { ], }, ], - "An EIP-4844 (shard blob) transaction was received, but Hardhat doesn't have support for them yet." + "An EIP-4844 (shard blob) call request was received, but Hardhat only supports them via `eth_sendRawTransaction`. See https://github.com/NomicFoundation/hardhat/issues/5182" ); }); diff --git a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/estimateGas.ts b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/estimateGas.ts index f7f0f4088..8f6be6a06 100644 --- a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/estimateGas.ts +++ b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/estimateGas.ts @@ -214,7 +214,7 @@ describe("Eth module", function () { ], }, ], - "An EIP-4844 (shard blob) transaction was received, but Hardhat doesn't have support for them yet." + "An EIP-4844 (shard blob) call request was received, but Hardhat only supports them via `eth_sendRawTransaction`. See https://github.com/NomicFoundation/hardhat/issues/5182" ); }); diff --git a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendRawTransaction.ts b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendRawTransaction.ts index eb1976e9d..da512ccde 100644 --- a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendRawTransaction.ts +++ b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendRawTransaction.ts @@ -109,19 +109,6 @@ describe("Eth module", function () { assertReceiptMatchesGethOne(receipt, receiptFromGeth, 1); }); - it("should reject blob transactions", async function () { - // blob tx signed with the private key of the first default account - const rawBlobTx = - "0x03f88380808080809400000000000000000000000000000000000000108080c080e1a0000000000000000000000000000000000000001012345678901234567890123401a0f3f7e5408804e3a0e3c4ac30a4f14b2995656a02d8b0279d7d48044d3cdf05e6a004e7606fef78d5221916053b3ec8a5fefddaa8a62ac6440f24a7c860ca25aa9f"; - - await assertInvalidInputError( - this.provider, - "eth_sendRawTransaction", - [rawBlobTx], - "An EIP-4844 (shard blob) transaction was received, but Hardhat doesn't have support for them yet." - ); - }); - describe("Transaction hash returned within the error data", function () { describe("Set lower baseFeePerGas", function () { // setting a lower baseFeePerGas here to avoid having to re-create the raw tx diff --git a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendTransaction.ts b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendTransaction.ts index f40bbe2df..c287a5a89 100644 --- a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendTransaction.ts +++ b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/methods/sendTransaction.ts @@ -1158,7 +1158,7 @@ describe("Eth module", function () { ], }, ], - "An EIP-4844 (shard blob) transaction was received, but Hardhat doesn't have support for them yet." + "An EIP-4844 (shard blob) transaction was received, but Hardhat only supports them via `eth_sendRawTransaction`. See https://github.com/NomicFoundation/hardhat/issues/5023" ); }); });