chore: simplify evm setup (#13864)

This commit is contained in:
Arsenii Kulikov
2025-01-20 00:07:20 +04:00
committed by GitHub
parent 88de40a678
commit f28c71c006
13 changed files with 39 additions and 130 deletions

View File

@ -230,18 +230,12 @@ impl ConfigureEvmEnv for EthEvmConfig {
impl ConfigureEvm for EthEvmConfig {
type Evm<'a, DB: Database + 'a, I: 'a> = EthEvm<'a, I, DB>;
fn evm_with_env<DB: Database>(
&self,
db: DB,
evm_env: EvmEnv,
tx: TxEnv,
) -> Self::Evm<'_, DB, ()> {
fn evm_with_env<DB: Database>(&self, db: DB, evm_env: EvmEnv) -> Self::Evm<'_, DB, ()> {
EthEvm(
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(),
)
}
@ -250,7 +244,6 @@ impl ConfigureEvm for EthEvmConfig {
&self,
db: DB,
evm_env: EvmEnv,
tx: TxEnv,
inspector: I,
) -> Self::Evm<'_, DB, I>
where
@ -263,7 +256,6 @@ impl ConfigureEvm for EthEvmConfig {
.with_external_context(inspector)
.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(),
)
@ -319,7 +311,7 @@ mod tests {
let evm_env = EvmEnv::default();
let evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
let evm = evm_config.evm_with_env(db, evm_env.clone());
// Check that the EVM environment
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
@ -350,7 +342,7 @@ mod tests {
..Default::default()
};
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
let evm = evm_config.evm_with_env(db, evm_env);
// Check that the EVM environment is initialized with the custom environment
assert_eq!(evm.context.evm.inner.env.cfg, cfg);
@ -376,7 +368,6 @@ mod tests {
number: U256::from(42),
..Default::default()
};
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
let evm_env = EvmEnv {
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
@ -386,11 +377,10 @@ mod tests {
block_env: block,
};
let evm = evm_config.evm_with_env(db, evm_env.clone(), tx.clone());
let evm = evm_config.evm_with_env(db, evm_env.clone());
// Verify that the block and transaction environments are set correctly
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
assert_eq!(evm.context.evm.env.tx, tx);
// Default spec ID
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
@ -416,7 +406,7 @@ mod tests {
..Default::default()
};
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
let evm = evm_config.evm_with_env(db, evm_env);
// Check that the spec ID is setup properly
assert_eq!(evm.handler.spec_id(), SpecId::PETERSBURG);
@ -436,12 +426,7 @@ mod tests {
let evm_env = EvmEnv::default();
let evm = evm_config.evm_with_env_and_inspector(
db,
evm_env.clone(),
Default::default(),
NoOpInspector,
);
let evm = evm_config.evm_with_env_and_inspector(db, evm_env.clone(), NoOpInspector);
// Check that the EVM environment is set to default values
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
@ -461,7 +446,6 @@ mod tests {
let cfg_env = CfgEnv::default().with_chain_id(111);
let block = BlockEnv::default();
let tx = TxEnv::default();
let evm_env = EvmEnv {
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
cfg_env: cfg_env.clone(),
@ -470,7 +454,7 @@ mod tests {
block_env: block,
};
let evm = evm_config.evm_with_env_and_inspector(db, evm_env, tx, NoOpInspector);
let evm = evm_config.evm_with_env_and_inspector(db, evm_env, NoOpInspector);
// Check that the EVM environment is set with custom configuration
assert_eq!(evm.context.evm.env.cfg, cfg_env);
@ -494,15 +478,12 @@ mod tests {
number: U256::from(42),
..Default::default()
};
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
let evm_env = EvmEnv { block_env: block, ..Default::default() };
let evm =
evm_config.evm_with_env_and_inspector(db, evm_env.clone(), tx.clone(), NoOpInspector);
let evm = evm_config.evm_with_env_and_inspector(db, evm_env.clone(), NoOpInspector);
// Verify that the block and transaction environments are set correctly
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
assert_eq!(evm.context.evm.env.tx, tx);
assert_eq!(evm.context.external, NoOpInspector);
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
@ -525,12 +506,7 @@ mod tests {
..Default::default()
};
let evm = evm_config.evm_with_env_and_inspector(
db,
evm_env.clone(),
Default::default(),
NoOpInspector,
);
let evm = evm_config.evm_with_env_and_inspector(db, evm_env.clone(), NoOpInspector);
// Check that the spec ID is set properly
assert_eq!(evm.handler.spec_id(), SpecId::PETERSBURG);