mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-26 15:48:13 -05:00
refactor: remove CallFees re-export and relocate tests (#16981)
This commit is contained in:
@@ -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!(
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user