From f9d9387c9a2ae43e5e52a2eac918dae70125328c Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 29 Jun 2023 19:26:35 +0200 Subject: [PATCH] docs: update call fees docs on fallback (#3471) Co-authored-by: Alexey Shekhirin --- crates/rpc/rpc/src/eth/revm_utils.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/crates/rpc/rpc/src/eth/revm_utils.rs b/crates/rpc/rpc/src/eth/revm_utils.rs index 54e996870a..cd552b398a 100644 --- a/crates/rpc/rpc/src/eth/revm_utils.rs +++ b/crates/rpc/rpc/src/eth/revm_utils.rs @@ -374,8 +374,8 @@ pub(crate) struct CallFees { impl CallFees { /// Ensures the fields of a [CallRequest] are not conflicting. /// - /// If no `gasPrice` or `maxFeePerGas` is set, then the `gas_price` in the response will - /// fallback to the given `basefee`. + /// If no `gasPrice` or `maxFeePerGas` is set, then the `gas_price` in the returned `gas_price` + /// will be `0`. See: fn ensure_fees( call_gas_price: Option, call_max_fee: Option, @@ -383,14 +383,10 @@ impl CallFees { base_fee: U256, ) -> EthResult { match (call_gas_price, call_max_fee, call_priority_fee) { - (None, None, None) => { - // when none are specified, they are all set to zero - Ok(CallFees { gas_price: U256::ZERO, max_priority_fee_per_gas: None }) - } (gas_price, None, None) => { - // request for a legacy transaction - // set everything to zero - let gas_price = gas_price.unwrap_or(base_fee); + // either legacy transaction or no fee fields are specified + // when no fields are specified, set gas price to zero + let gas_price = gas_price.unwrap_or(U256::ZERO); Ok(CallFees { gas_price, max_priority_fee_per_gas: None }) } (None, max_fee_per_gas, max_priority_fee_per_gas) => { @@ -525,3 +521,15 @@ where db: Default::default(), } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_ensure_0_fallback() { + let CallFees { gas_price, .. } = + CallFees::ensure_fees(None, None, None, U256::from(99)).unwrap(); + assert_eq!(gas_price, U256::ZERO); + } +}