Skip to main content

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    #[cfg(feature = "std")]
37    type BlockAssembler = Inner::BlockAssembler;
38
39    #[cfg(feature = "std")]
40    fn block_executor_factory(&self) -> &Self::BlockExecutorFactory {
41        self.inner().block_executor_factory()
42    }
43
44    #[cfg(feature = "std")]
45    fn block_assembler(&self) -> &Self::BlockAssembler {
46        self.inner().block_assembler()
47    }
48
49    fn evm_env(&self, header: &HeaderTy<Self::Primitives>) -> Result<EvmEnvFor<Self>, Self::Error> {
50        self.inner().evm_env(header)
51    }
52
53    fn next_evm_env(
54        &self,
55        parent: &HeaderTy<Self::Primitives>,
56        attributes: &Self::NextBlockEnvCtx,
57    ) -> Result<EvmEnvFor<Self>, Self::Error> {
58        self.inner().next_evm_env(parent, attributes)
59    }
60
61    fn context_for_block<'a>(
62        &self,
63        block: &'a SealedBlock<BlockTy<Self::Primitives>>,
64    ) -> Result<crate::ExecutionCtxFor<'a, Self>, Self::Error>
65    where
66        Self: 'a,
67    {
68        self.inner().context_for_block(block)
69    }
70
71    fn context_for_next_block(
72        &self,
73        parent: &SealedHeader<HeaderTy<Self::Primitives>>,
74        attributes: Self::NextBlockEnvCtx,
75    ) -> Result<crate::ExecutionCtxFor<'_, Self>, Self::Error> {
76        self.inner().context_for_next_block(parent, attributes)
77    }
78}
79
80#[cfg(feature = "std")]
81impl<Inner, T> crate::ConfigureEngineEvm<T> for NoopEvmConfig<Inner>
82where
83    Inner: crate::ConfigureEngineEvm<T>,
84{
85    fn evm_env_for_payload(&self, payload: &T) -> Result<EvmEnvFor<Self>, Self::Error> {
86        self.inner().evm_env_for_payload(payload)
87    }
88
89    fn context_for_payload<'a>(
90        &self,
91        payload: &'a T,
92    ) -> Result<crate::ExecutionCtxFor<'a, Self>, Self::Error> {
93        self.inner().context_for_payload(payload)
94    }
95
96    fn tx_iterator_for_payload(
97        &self,
98        payload: &T,
99    ) -> Result<impl crate::ExecutableTxIterator<Self>, Self::Error> {
100        self.inner().tx_iterator_for_payload(payload)
101    }
102}