Skip to content

Commit

Permalink
move effective_gas_price to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
JereSalo committed Dec 2, 2024
1 parent bd801b7 commit 3af7fb0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
4 changes: 1 addition & 3 deletions cmd/ef_tests/levm/runner/levm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
report::{EFTestReport, TestVector},
runner::{EFTestRunnerError, InternalError},
types::EFTest,
utils,
utils::{self, effective_gas_price},
};
use ethrex_core::{
types::{code_hash, AccountInfo},
Expand All @@ -19,8 +19,6 @@ use ethrex_vm::db::StoreWrapper;
use keccak_hash::keccak;
use std::{collections::HashMap, sync::Arc};

use super::revm_runner::effective_gas_price;

pub fn run_ef_test(test: &EFTest) -> Result<EFTestReport, EFTestRunnerError> {
let mut ef_test_report = EFTestReport::new(
test.name.clone(),
Expand Down
19 changes: 3 additions & 16 deletions cmd/ef_tests/levm/runner/revm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::{
levm_runner::{self, post_state_root},
EFTestRunnerError, InternalError,
},
types::{EFTest, EFTestTransaction},
utils::load_initial_state,
types::EFTest,
utils::{effective_gas_price, load_initial_state},
};
use bytes::Bytes;
use ethrex_core::{types::TxKind, Address, H256, U256};
use ethrex_core::{types::TxKind, Address, H256};
use ethrex_levm::{
errors::{TransactionReport, TxResult},
Account, StorageSlot,
Expand Down Expand Up @@ -90,19 +90,6 @@ pub fn re_run_failed_ef_test_tx(
Ok(())
}

// If gas price is not provided, calculate it with current base fee and priority fee
pub fn effective_gas_price(test: &EFTest, tx: &&EFTestTransaction) -> U256 {
match tx.gas_price {
None => {
let current_base_fee = test.env.current_base_fee.unwrap();
let priority_fee = tx.max_priority_fee_per_gas.unwrap();
let max_fee_per_gas = tx.max_fee_per_gas.unwrap();
std::cmp::min(max_fee_per_gas, current_base_fee + priority_fee)
}
Some(price) => price,
}
}

pub fn prepare_revm_for_tx<'state>(
initial_state: &'state mut EvmState,
vector: &TestVector,
Expand Down
17 changes: 15 additions & 2 deletions cmd/ef_tests/levm/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::types::EFTest;
use ethrex_core::{types::Genesis, H256};
use crate::types::{EFTest, EFTestTransaction};
use ethrex_core::{types::Genesis, H256, U256};
use ethrex_storage::{EngineType, Store};
use ethrex_vm::{evm_state, EvmState};

Expand All @@ -17,3 +17,16 @@ pub fn load_initial_state(test: &EFTest) -> (EvmState, H256) {
genesis.get_block().header.compute_block_hash(),
)
}

// If gas price is not provided, calculate it with current base fee and priority fee
pub fn effective_gas_price(test: &EFTest, tx: &&EFTestTransaction) -> U256 {
match tx.gas_price {
None => {
let current_base_fee = test.env.current_base_fee.unwrap();
let priority_fee = tx.max_priority_fee_per_gas.unwrap();
let max_fee_per_gas = tx.max_fee_per_gas.unwrap();
std::cmp::min(max_fee_per_gas, current_base_fee + priority_fee)
}
Some(price) => price,
}
}

0 comments on commit 3af7fb0

Please sign in to comment.