mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: trim ConfigureEvm trait (#13807)
This commit is contained in:
@ -168,19 +168,41 @@ impl ConfigureEvmEnv for OpEvmConfig {
|
||||
}
|
||||
|
||||
impl ConfigureEvm for OpEvmConfig {
|
||||
fn evm<DB: Database>(&self, db: DB) -> Evm<'_, (), DB> {
|
||||
EvmBuilder::default().with_db(db).optimism().build()
|
||||
fn evm_with_env<DB: Database>(
|
||||
&self,
|
||||
db: DB,
|
||||
mut evm_env: EvmEnv,
|
||||
tx: TxEnv,
|
||||
) -> Evm<'_, (), DB> {
|
||||
evm_env.cfg_env_with_handler_cfg.handler_cfg.is_optimism = true;
|
||||
|
||||
EvmBuilder::default()
|
||||
.with_db(db)
|
||||
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
|
||||
.with_block_env(evm_env.block_env)
|
||||
.with_tx_env(tx)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn evm_with_inspector<DB, I>(&self, db: DB, inspector: I) -> Evm<'_, I, DB>
|
||||
fn evm_with_env_and_inspector<DB, I>(
|
||||
&self,
|
||||
db: DB,
|
||||
mut evm_env: EvmEnv,
|
||||
tx: TxEnv,
|
||||
inspector: I,
|
||||
) -> Evm<'_, I, DB>
|
||||
where
|
||||
DB: Database,
|
||||
I: GetInspector<DB>,
|
||||
{
|
||||
evm_env.cfg_env_with_handler_cfg.handler_cfg.is_optimism = true;
|
||||
|
||||
EvmBuilder::default()
|
||||
.with_db(db)
|
||||
.with_external_context(inspector)
|
||||
.optimism()
|
||||
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
|
||||
.with_block_env(evm_env.block_env)
|
||||
.with_tx_env(tx)
|
||||
.append_handler_register(inspector_handle_register)
|
||||
.build()
|
||||
}
|
||||
@ -189,14 +211,10 @@ impl ConfigureEvm for OpEvmConfig {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use alloy_consensus::{constants::KECCAK_EMPTY, Header, Receipt};
|
||||
use alloy_consensus::{Header, Receipt};
|
||||
use alloy_eips::eip7685::Requests;
|
||||
use alloy_genesis::Genesis;
|
||||
use alloy_primitives::{
|
||||
bytes,
|
||||
map::{HashMap, HashSet},
|
||||
Address, LogData, B256, U256,
|
||||
};
|
||||
use alloy_primitives::{bytes, map::HashMap, Address, LogData, B256, U256};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_evm::execute::ProviderError;
|
||||
use reth_execution_types::{
|
||||
@ -209,7 +227,6 @@ mod tests {
|
||||
db::{BundleState, CacheDB, EmptyDBTyped},
|
||||
inspectors::NoOpInspector,
|
||||
primitives::{AccountInfo, BlockEnv, CfgEnv, SpecId},
|
||||
JournaledState,
|
||||
};
|
||||
use revm_primitives::HandlerCfg;
|
||||
use std::sync::Arc;
|
||||
@ -244,47 +261,6 @@ mod tests {
|
||||
assert_eq!(cfg_env_with_handler_cfg.chain_id, chain_spec.chain().id());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_evm_configure() {
|
||||
// Create a default `OpEvmConfig`
|
||||
let evm_config = test_evm_config();
|
||||
|
||||
// Initialize an empty database wrapped in CacheDB
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
// Create an EVM instance using the configuration and the database
|
||||
let evm = evm_config.evm(db);
|
||||
|
||||
// Check that the EVM environment is initialized with default values
|
||||
assert_eq!(evm.context.evm.inner.env, Box::default());
|
||||
|
||||
// Latest spec ID and no warm preloaded addresses
|
||||
assert_eq!(
|
||||
evm.context.evm.inner.journaled_state,
|
||||
JournaledState::new(SpecId::LATEST, HashSet::default())
|
||||
);
|
||||
|
||||
// Ensure that the accounts database is empty
|
||||
assert!(evm.context.evm.inner.db.accounts.is_empty());
|
||||
|
||||
// Ensure that the block hashes database is empty
|
||||
assert!(evm.context.evm.inner.db.block_hashes.is_empty());
|
||||
|
||||
// Verify that there are two default contracts in the contracts database
|
||||
assert_eq!(evm.context.evm.inner.db.contracts.len(), 2);
|
||||
assert!(evm.context.evm.inner.db.contracts.contains_key(&KECCAK_EMPTY));
|
||||
assert!(evm.context.evm.inner.db.contracts.contains_key(&B256::ZERO));
|
||||
|
||||
// Ensure that the logs database is empty
|
||||
assert!(evm.context.evm.inner.db.logs.is_empty());
|
||||
|
||||
// Optimism in handler
|
||||
assert_eq!(evm.handler.cfg, HandlerCfg { spec_id: SpecId::LATEST, is_optimism: true });
|
||||
|
||||
// Default spec ID
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_evm_with_env_default_spec() {
|
||||
let evm_config = test_evm_config();
|
||||
@ -389,50 +365,6 @@ mod tests {
|
||||
assert_eq!(evm.handler.cfg, HandlerCfg { spec_id: SpecId::ECOTONE, is_optimism: true });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_evm_with_inspector() {
|
||||
let evm_config = test_evm_config();
|
||||
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
// No operation inspector
|
||||
let noop = NoOpInspector;
|
||||
|
||||
let evm = evm_config.evm_with_inspector(db, noop);
|
||||
|
||||
// Check that the inspector is set correctly
|
||||
assert_eq!(evm.context.external, noop);
|
||||
|
||||
// Check that the EVM environment is initialized with default values
|
||||
assert_eq!(evm.context.evm.inner.env, Box::default());
|
||||
|
||||
// Latest spec ID and no warm preloaded addresses
|
||||
assert_eq!(
|
||||
evm.context.evm.inner.journaled_state,
|
||||
JournaledState::new(SpecId::LATEST, HashSet::default())
|
||||
);
|
||||
|
||||
// Ensure that the accounts database is empty
|
||||
assert!(evm.context.evm.inner.db.accounts.is_empty());
|
||||
|
||||
// Ensure that the block hashes database is empty
|
||||
assert!(evm.context.evm.inner.db.block_hashes.is_empty());
|
||||
|
||||
// Verify that there are two default contracts in the contracts database
|
||||
assert_eq!(evm.context.evm.inner.db.contracts.len(), 2);
|
||||
assert!(evm.context.evm.inner.db.contracts.contains_key(&KECCAK_EMPTY));
|
||||
assert!(evm.context.evm.inner.db.contracts.contains_key(&B256::ZERO));
|
||||
|
||||
// Ensure that the logs database is empty
|
||||
assert!(evm.context.evm.inner.db.logs.is_empty());
|
||||
|
||||
// Default spec ID
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
|
||||
// Optimism in handler
|
||||
assert_eq!(evm.handler.cfg, HandlerCfg { spec_id: SpecId::LATEST, is_optimism: true });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_evm_with_env_and_default_inspector() {
|
||||
let evm_config = test_evm_config();
|
||||
|
||||
Reference in New Issue
Block a user