| 
1 | 1 | //! Configuration types for EVM environment.  | 
2 | 2 | 
  | 
 | 3 | +use alloy_primitives::U256;  | 
3 | 4 | use revm::{  | 
4 | 5 |     context::{BlockEnv, CfgEnv},  | 
5 | 6 |     primitives::hardfork::SpecId,  | 
@@ -44,6 +45,81 @@ impl<Spec> EvmEnv<Spec> {  | 
44 | 45 |     pub const fn spec_id(&self) -> &Spec {  | 
45 | 46 |         &self.cfg_env.spec  | 
46 | 47 |     }  | 
 | 48 | + | 
 | 49 | +    /// Overrides the configured block number  | 
 | 50 | +    pub fn with_block_number(mut self, number: U256) -> Self {  | 
 | 51 | +        self.block_env.number = number;  | 
 | 52 | +        self  | 
 | 53 | +    }  | 
 | 54 | + | 
 | 55 | +    /// Convenience function that overrides the configured block number with the given  | 
 | 56 | +    /// `Some(number)`.  | 
 | 57 | +    ///  | 
 | 58 | +    /// This is intended for block overrides.  | 
 | 59 | +    pub fn with_block_number_opt(mut self, number: Option<U256>) -> Self {  | 
 | 60 | +        if let Some(number) = number {  | 
 | 61 | +            self.block_env.number = number;  | 
 | 62 | +        }  | 
 | 63 | +        self  | 
 | 64 | +    }  | 
 | 65 | + | 
 | 66 | +    /// Sets the block number if provided.  | 
 | 67 | +    pub fn set_block_number_opt(&mut self, number: Option<U256>) -> &mut Self {  | 
 | 68 | +        if let Some(number) = number {  | 
 | 69 | +            self.block_env.number = number;  | 
 | 70 | +        }  | 
 | 71 | +        self  | 
 | 72 | +    }  | 
 | 73 | + | 
 | 74 | +    /// Overrides the configured block timestamp.  | 
 | 75 | +    pub fn with_timestamp(mut self, timestamp: U256) -> Self {  | 
 | 76 | +        self.block_env.timestamp = timestamp;  | 
 | 77 | +        self  | 
 | 78 | +    }  | 
 | 79 | + | 
 | 80 | +    /// Convenience function that overrides the configured block timestamp with the given  | 
 | 81 | +    /// `Some(timestamp)`.  | 
 | 82 | +    ///  | 
 | 83 | +    /// This is intended for block overrides.  | 
 | 84 | +    pub fn with_timestamp_opt(mut self, timestamp: Option<U256>) -> Self {  | 
 | 85 | +        if let Some(timestamp) = timestamp {  | 
 | 86 | +            self.block_env.timestamp = timestamp;  | 
 | 87 | +        }  | 
 | 88 | +        self  | 
 | 89 | +    }  | 
 | 90 | + | 
 | 91 | +    /// Sets the block timestamp if provided.  | 
 | 92 | +    pub fn set_timestamp_opt(&mut self, timestamp: Option<U256>) -> &mut Self {  | 
 | 93 | +        if let Some(timestamp) = timestamp {  | 
 | 94 | +            self.block_env.timestamp = timestamp;  | 
 | 95 | +        }  | 
 | 96 | +        self  | 
 | 97 | +    }  | 
 | 98 | + | 
 | 99 | +    /// Overrides the configured block base fee.  | 
 | 100 | +    pub fn with_base_fee(mut self, base_fee: u64) -> Self {  | 
 | 101 | +        self.block_env.basefee = base_fee;  | 
 | 102 | +        self  | 
 | 103 | +    }  | 
 | 104 | + | 
 | 105 | +    /// Convenience function that overrides the configured block base fee with the given  | 
 | 106 | +    /// `Some(base_fee)`.  | 
 | 107 | +    ///  | 
 | 108 | +    /// This is intended for block overrides.  | 
 | 109 | +    pub fn with_base_fee_opt(mut self, base_fee: Option<u64>) -> Self {  | 
 | 110 | +        if let Some(base_fee) = base_fee {  | 
 | 111 | +            self.block_env.basefee = base_fee;  | 
 | 112 | +        }  | 
 | 113 | +        self  | 
 | 114 | +    }  | 
 | 115 | + | 
 | 116 | +    /// Sets the block base fee if provided.  | 
 | 117 | +    pub fn set_base_fee_opt(&mut self, base_fee: Option<u64>) -> &mut Self {  | 
 | 118 | +        if let Some(base_fee) = base_fee {  | 
 | 119 | +            self.block_env.basefee = base_fee;  | 
 | 120 | +        }  | 
 | 121 | +        self  | 
 | 122 | +    }  | 
47 | 123 | }  | 
48 | 124 | 
 
  | 
49 | 125 | impl<Spec> From<(CfgEnv<Spec>, BlockEnv)> for EvmEnv<Spec> {  | 
 | 
0 commit comments