reth_evm/
noop.rs

1//! Helpers for testing.
2
3use crate::{ConfigureEvm, EvmEnvFor};
4use reth_primitives_traits::{BlockTy, HeaderTy, SealedBlock, SealedHeader};
5
6/// A no-op EVM config that panics on any call. Used as a typesystem hack to satisfy
7/// [`ConfigureEvm`] bounds.
8#[derive(Debug, Clone)]
9pub struct NoopEvmConfig<Inner>(core::marker::PhantomData<Inner>);
10
11impl<Inner> Default for NoopEvmConfig<Inner> {
12    fn default() -> Self {
13        Self::new()
14    }
15}
16
17impl<Inner> NoopEvmConfig<Inner> {
18    /// Create a new instance of the no-op EVM config.
19    pub const fn new() -> Self {
20        Self(core::marker::PhantomData)
21    }
22
23    fn inner(&self) -> &Inner {
24        unimplemented!("NoopEvmConfig should never be called")
25    }
26}
27
28impl<Inner> ConfigureEvm for NoopEvmConfig<Inner>
29where
30    Inner: ConfigureEvm,
31{
32    type Primitives = Inner::Primitives;
33    type Error = Inner::Error;
34    type NextBlockEnvCtx = Inner::NextBlockEnvCtx;
35    type BlockExecutorFactory = Inner::BlockExecutorFactory;
36    type BlockAssembler = Inner::BlockAssembler;
37
38    fn block_executor_factory(&self) -> &Self::BlockExecutorFactory {
39        self.inner().block_executor_factory()
40    }
41
42    fn block_assembler(&self) -> &Self::BlockAssembler {
43        self.inner().block_assembler()
44    }
45
46    fn evm_env(&self, header: &HeaderTy<Self::Primitives>) -> EvmEnvFor<Self> {
47        self.inner().evm_env(header)
48    }
49
50    fn next_evm_env(
51        &self,
52        parent: &HeaderTy<Self::Primitives>,
53        attributes: &Self::NextBlockEnvCtx,
54    ) -> Result<EvmEnvFor<Self>, Self::Error> {
55        self.inner().next_evm_env(parent, attributes)
56    }
57
58    fn context_for_block<'a>(
59        &self,
60        block: &'a SealedBlock<BlockTy<Self::Primitives>>,
61    ) -> crate::ExecutionCtxFor<'a, Self> {
62        self.inner().context_for_block(block)
63    }
64
65    fn context_for_next_block(
66        &self,
67        parent: &SealedHeader<HeaderTy<Self::Primitives>>,
68        attributes: Self::NextBlockEnvCtx,
69    ) -> crate::ExecutionCtxFor<'_, Self> {
70        self.inner().context_for_next_block(parent, attributes)
71    }
72}