mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: use EvmEnv when setting up Evm (#13800)
This commit is contained in:
@ -198,7 +198,7 @@ mod tests {
|
||||
primitives::{BlockEnv, CfgEnv, SpecId},
|
||||
JournaledState,
|
||||
};
|
||||
use revm_primitives::{EnvWithHandlerCfg, HandlerCfg};
|
||||
use revm_primitives::HandlerCfg;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[test]
|
||||
@ -272,12 +272,13 @@ mod tests {
|
||||
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg::default();
|
||||
let evm_env = EvmEnv::default();
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler.clone());
|
||||
let evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
|
||||
|
||||
// Check that the EVM environment
|
||||
assert_eq!(evm.context.evm.env, env_with_handler.env);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.evm.env.cfg, evm_env.cfg_env_with_handler_cfg.cfg_env);
|
||||
|
||||
// Default spec ID
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
@ -296,16 +297,15 @@ mod tests {
|
||||
// Create a custom configuration environment with a chain ID of 111
|
||||
let cfg = CfgEnv::default().with_chain_id(111);
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env {
|
||||
cfg: cfg.clone(),
|
||||
block: BlockEnv::default(),
|
||||
tx: TxEnv::default(),
|
||||
}),
|
||||
handler_cfg: Default::default(),
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: cfg.clone(),
|
||||
handler_cfg: Default::default(),
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler);
|
||||
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
|
||||
|
||||
// Check that the EVM environment is initialized with the custom environment
|
||||
assert_eq!(evm.context.evm.inner.env.cfg, cfg);
|
||||
@ -333,16 +333,19 @@ mod tests {
|
||||
};
|
||||
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env { cfg: CfgEnv::default(), block, tx }),
|
||||
handler_cfg: Default::default(),
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: CfgEnv::default(),
|
||||
handler_cfg: Default::default(),
|
||||
},
|
||||
block_env: block,
|
||||
};
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler.clone());
|
||||
let evm = evm_config.evm_with_env(db, evm_env.clone(), tx.clone());
|
||||
|
||||
// Verify that the block and transaction environments are set correctly
|
||||
assert_eq!(evm.context.evm.env.block, env_with_handler.env.block);
|
||||
assert_eq!(evm.context.evm.env.tx, env_with_handler.env.tx);
|
||||
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);
|
||||
@ -360,9 +363,15 @@ mod tests {
|
||||
|
||||
let handler_cfg = HandlerCfg { spec_id: SpecId::CONSTANTINOPLE, ..Default::default() };
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg { env: Box::new(Env::default()), handler_cfg };
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: Default::default(),
|
||||
handler_cfg,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler);
|
||||
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
|
||||
|
||||
// Check that the spec ID is setup properly
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::CONSTANTINOPLE);
|
||||
@ -422,13 +431,18 @@ mod tests {
|
||||
let evm_config = EthEvmConfig::new(MAINNET.clone());
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg::default();
|
||||
let evm_env = EvmEnv::default();
|
||||
|
||||
let evm =
|
||||
evm_config.evm_with_env_and_inspector(db, env_with_handler.clone(), NoOpInspector);
|
||||
let evm = evm_config.evm_with_env_and_inspector(
|
||||
db,
|
||||
evm_env.clone(),
|
||||
Default::default(),
|
||||
NoOpInspector,
|
||||
);
|
||||
|
||||
// Check that the EVM environment is set to default values
|
||||
assert_eq!(evm.context.evm.env, env_with_handler.env);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.evm.env.cfg, evm_env.cfg_env_with_handler_cfg.cfg_env);
|
||||
assert_eq!(evm.context.external, NoOpInspector);
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
|
||||
@ -442,18 +456,21 @@ mod tests {
|
||||
let evm_config = EthEvmConfig::new(MAINNET.clone());
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
let cfg = CfgEnv::default().with_chain_id(111);
|
||||
let cfg_env = CfgEnv::default().with_chain_id(111);
|
||||
let block = BlockEnv::default();
|
||||
let tx = TxEnv::default();
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env { cfg: cfg.clone(), block, tx }),
|
||||
handler_cfg: Default::default(),
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: cfg_env.clone(),
|
||||
handler_cfg: Default::default(),
|
||||
},
|
||||
block_env: block,
|
||||
};
|
||||
|
||||
let evm = evm_config.evm_with_env_and_inspector(db, env_with_handler, NoOpInspector);
|
||||
let evm = evm_config.evm_with_env_and_inspector(db, evm_env, tx, NoOpInspector);
|
||||
|
||||
// Check that the EVM environment is set with custom configuration
|
||||
assert_eq!(evm.context.evm.env.cfg, cfg);
|
||||
assert_eq!(evm.context.evm.env.cfg, cfg_env);
|
||||
assert_eq!(evm.context.external, NoOpInspector);
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
|
||||
@ -475,17 +492,14 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env { cfg: CfgEnv::default(), block, tx }),
|
||||
handler_cfg: Default::default(),
|
||||
};
|
||||
let evm_env = EvmEnv { block_env: block, ..Default::default() };
|
||||
|
||||
let evm =
|
||||
evm_config.evm_with_env_and_inspector(db, env_with_handler.clone(), NoOpInspector);
|
||||
evm_config.evm_with_env_and_inspector(db, evm_env.clone(), tx.clone(), NoOpInspector);
|
||||
|
||||
// Verify that the block and transaction environments are set correctly
|
||||
assert_eq!(evm.context.evm.env.block, env_with_handler.env.block);
|
||||
assert_eq!(evm.context.evm.env.tx, env_with_handler.env.tx);
|
||||
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);
|
||||
|
||||
@ -500,14 +514,26 @@ mod tests {
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
let handler_cfg = HandlerCfg { spec_id: SpecId::CONSTANTINOPLE, ..Default::default() };
|
||||
let env_with_handler = EnvWithHandlerCfg { env: Box::new(Env::default()), handler_cfg };
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
handler_cfg,
|
||||
cfg_env: Default::default(),
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let evm =
|
||||
evm_config.evm_with_env_and_inspector(db, env_with_handler.clone(), NoOpInspector);
|
||||
let evm = evm_config.evm_with_env_and_inspector(
|
||||
db,
|
||||
evm_env.clone(),
|
||||
Default::default(),
|
||||
NoOpInspector,
|
||||
);
|
||||
|
||||
// Check that the spec ID is set properly
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::CONSTANTINOPLE);
|
||||
assert_eq!(evm.context.evm.env, env_with_handler.env);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.evm.env.cfg, evm_env.cfg_env_with_handler_cfg.cfg_env);
|
||||
assert_eq!(evm.context.evm.env.tx, Default::default());
|
||||
assert_eq!(evm.context.external, NoOpInspector);
|
||||
|
||||
// No Optimism
|
||||
|
||||
Reference in New Issue
Block a user