From 9cf910ce2eed65b7ff66a63adeec3e1a3470425a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 21 Jun 2025 11:46:52 +0200 Subject: [PATCH] refactor: remove CallFees re-export and relocate tests (#16981) --- crates/rpc/rpc-eth-types/src/revm_utils.rs | 113 -------------------- crates/rpc/rpc-types-compat/src/fees.rs | 116 +++++++++++++++++++++ 2 files changed, 116 insertions(+), 113 deletions(-) diff --git a/crates/rpc/rpc-eth-types/src/revm_utils.rs b/crates/rpc/rpc-eth-types/src/revm_utils.rs index 47671b8987..83deef5346 100644 --- a/crates/rpc/rpc-eth-types/src/revm_utils.rs +++ b/crates/rpc/rpc-eth-types/src/revm_utils.rs @@ -15,8 +15,6 @@ use std::collections::{BTreeMap, HashMap}; use super::{EthApiError, EthResult, RpcInvalidTransactionError}; -pub use reth_rpc_types_compat::CallFees; - /// Calculates the caller gas allowance. /// /// `allowance = (account.balance - tx.value) / tx.gas_price` @@ -206,120 +204,9 @@ where #[cfg(test)] mod tests { use super::*; - use alloy_consensus::constants::GWEI_TO_WEI; use alloy_primitives::{address, bytes}; use reth_revm::db::EmptyDB; - #[test] - fn test_ensure_0_fallback() { - let CallFees { gas_price, .. } = - CallFees::ensure_fees(None, None, None, U256::from(99), None, None, Some(U256::ZERO)) - .unwrap(); - assert!(gas_price.is_zero()); - } - - #[test] - fn test_ensure_max_fee_0_exception() { - let CallFees { gas_price, .. } = - CallFees::ensure_fees(None, Some(U256::ZERO), None, U256::from(99), None, None, None) - .unwrap(); - assert!(gas_price.is_zero()); - } - - #[test] - fn test_blob_fees() { - let CallFees { gas_price, max_fee_per_blob_gas, .. } = - CallFees::ensure_fees(None, None, None, U256::from(99), None, None, Some(U256::ZERO)) - .unwrap(); - assert!(gas_price.is_zero()); - assert_eq!(max_fee_per_blob_gas, None); - - let CallFees { gas_price, max_fee_per_blob_gas, .. } = CallFees::ensure_fees( - None, - None, - None, - U256::from(99), - Some(&[B256::from(U256::ZERO)]), - None, - Some(U256::from(99)), - ) - .unwrap(); - assert!(gas_price.is_zero()); - assert_eq!(max_fee_per_blob_gas, Some(U256::from(99))); - } - - #[test] - fn test_eip_1559_fees() { - let CallFees { gas_price, .. } = CallFees::ensure_fees( - None, - Some(U256::from(25 * GWEI_TO_WEI)), - Some(U256::from(15 * GWEI_TO_WEI)), - U256::from(15 * GWEI_TO_WEI), - None, - None, - Some(U256::ZERO), - ) - .unwrap(); - assert_eq!(gas_price, U256::from(25 * GWEI_TO_WEI)); - - let CallFees { gas_price, .. } = CallFees::ensure_fees( - None, - Some(U256::from(25 * GWEI_TO_WEI)), - Some(U256::from(5 * GWEI_TO_WEI)), - U256::from(15 * GWEI_TO_WEI), - None, - None, - Some(U256::ZERO), - ) - .unwrap(); - assert_eq!(gas_price, U256::from(20 * GWEI_TO_WEI)); - - let CallFees { gas_price, .. } = CallFees::ensure_fees( - None, - Some(U256::from(30 * GWEI_TO_WEI)), - Some(U256::from(30 * GWEI_TO_WEI)), - U256::from(15 * GWEI_TO_WEI), - None, - None, - Some(U256::ZERO), - ) - .unwrap(); - assert_eq!(gas_price, U256::from(30 * GWEI_TO_WEI)); - - let call_fees = CallFees::ensure_fees( - None, - Some(U256::from(30 * GWEI_TO_WEI)), - Some(U256::from(31 * GWEI_TO_WEI)), - U256::from(15 * GWEI_TO_WEI), - None, - None, - Some(U256::ZERO), - ); - assert!(call_fees.is_err()); - - let call_fees = CallFees::ensure_fees( - None, - Some(U256::from(5 * GWEI_TO_WEI)), - Some(U256::from(GWEI_TO_WEI)), - U256::from(15 * GWEI_TO_WEI), - None, - None, - Some(U256::ZERO), - ); - assert!(call_fees.is_err()); - - let call_fees = CallFees::ensure_fees( - None, - Some(U256::MAX), - Some(U256::MAX), - U256::from(5 * GWEI_TO_WEI), - None, - None, - Some(U256::ZERO), - ); - assert!(call_fees.is_err()); - } - #[test] fn state_override_state() { let code = bytes!( diff --git a/crates/rpc/rpc-types-compat/src/fees.rs b/crates/rpc/rpc-types-compat/src/fees.rs index 45ee7628fc..46f8fc8c20 100644 --- a/crates/rpc/rpc-types-compat/src/fees.rs +++ b/crates/rpc/rpc-types-compat/src/fees.rs @@ -163,3 +163,119 @@ pub enum CallFeesError { #[error("blob transaction missing blob hashes")] BlobTransactionMissingBlobHashes, } + +#[cfg(test)] +mod tests { + use super::*; + use alloy_consensus::constants::GWEI_TO_WEI; + + #[test] + fn test_ensure_0_fallback() { + let CallFees { gas_price, .. } = + CallFees::ensure_fees(None, None, None, U256::from(99), None, None, Some(U256::ZERO)) + .unwrap(); + assert!(gas_price.is_zero()); + } + + #[test] + fn test_ensure_max_fee_0_exception() { + let CallFees { gas_price, .. } = + CallFees::ensure_fees(None, Some(U256::ZERO), None, U256::from(99), None, None, None) + .unwrap(); + assert!(gas_price.is_zero()); + } + + #[test] + fn test_blob_fees() { + let CallFees { gas_price, max_fee_per_blob_gas, .. } = + CallFees::ensure_fees(None, None, None, U256::from(99), None, None, Some(U256::ZERO)) + .unwrap(); + assert!(gas_price.is_zero()); + assert_eq!(max_fee_per_blob_gas, None); + + let CallFees { gas_price, max_fee_per_blob_gas, .. } = CallFees::ensure_fees( + None, + None, + None, + U256::from(99), + Some(&[B256::from(U256::ZERO)]), + None, + Some(U256::from(99)), + ) + .unwrap(); + assert!(gas_price.is_zero()); + assert_eq!(max_fee_per_blob_gas, Some(U256::from(99))); + } + + #[test] + fn test_eip_1559_fees() { + let CallFees { gas_price, .. } = CallFees::ensure_fees( + None, + Some(U256::from(25 * GWEI_TO_WEI)), + Some(U256::from(15 * GWEI_TO_WEI)), + U256::from(15 * GWEI_TO_WEI), + None, + None, + Some(U256::ZERO), + ) + .unwrap(); + assert_eq!(gas_price, U256::from(25 * GWEI_TO_WEI)); + + let CallFees { gas_price, .. } = CallFees::ensure_fees( + None, + Some(U256::from(25 * GWEI_TO_WEI)), + Some(U256::from(5 * GWEI_TO_WEI)), + U256::from(15 * GWEI_TO_WEI), + None, + None, + Some(U256::ZERO), + ) + .unwrap(); + assert_eq!(gas_price, U256::from(20 * GWEI_TO_WEI)); + + let CallFees { gas_price, .. } = CallFees::ensure_fees( + None, + Some(U256::from(30 * GWEI_TO_WEI)), + Some(U256::from(30 * GWEI_TO_WEI)), + U256::from(15 * GWEI_TO_WEI), + None, + None, + Some(U256::ZERO), + ) + .unwrap(); + assert_eq!(gas_price, U256::from(30 * GWEI_TO_WEI)); + + let call_fees = CallFees::ensure_fees( + None, + Some(U256::from(30 * GWEI_TO_WEI)), + Some(U256::from(31 * GWEI_TO_WEI)), + U256::from(15 * GWEI_TO_WEI), + None, + None, + Some(U256::ZERO), + ); + assert!(call_fees.is_err()); + + let call_fees = CallFees::ensure_fees( + None, + Some(U256::from(5 * GWEI_TO_WEI)), + Some(U256::from(GWEI_TO_WEI)), + U256::from(15 * GWEI_TO_WEI), + None, + None, + Some(U256::ZERO), + ); + assert!(call_fees.is_err()); + + let call_fees = CallFees::ensure_fees( + None, + Some(U256::MAX), + Some(U256::MAX), + U256::from(5 * GWEI_TO_WEI), + None, + None, + Some(U256::ZERO), + ); + assert!(call_fees.is_err()); + } +}