Skip to content

Commit

Permalink
test: fix Hardhat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed May 6, 2024
1 parent b19a247 commit ebd08b7
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 19 deletions.
5 changes: 4 additions & 1 deletion crates/edr_provider/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ pub enum ProviderError<LoggerErrorT> {
Creation(#[from] CreationError),
#[error(transparent)]
DebugTrace(#[from] DebugTraceError<BlockchainError, StateError>),
#[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,
Expand Down Expand Up @@ -225,6 +227,7 @@ impl<LoggerErrorT: Debug> From<ProviderError<LoggerErrorT>> 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,
Expand Down
4 changes: 4 additions & 0 deletions crates/edr_provider/src/requests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ pub fn validate_call_request<LoggerErrorT: Debug>(
) -> Result<(), ProviderError<LoggerErrorT>> {
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
Expand Down
94 changes: 92 additions & 2 deletions crates/edr_provider/tests/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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::{
Expand Down Expand Up @@ -130,6 +130,34 @@ fn fake_transaction() -> SignedTransaction {
fake_pooled_transaction().into_payload()
}

fn fake_call_request() -> anyhow::Result<CallRequest> {
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<EthTransactionRequest> {
let transaction = fake_pooled_transaction();
let blobs = transaction.blobs().map(|blobs| {
Expand Down Expand Up @@ -162,6 +190,68 @@ fn fake_transaction_request() -> anyhow::Result<EthTransactionRequest> {
})
}

#[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()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
});
Expand Down

0 comments on commit ebd08b7

Please sign in to comment.