Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ pub struct Config {
/// the initial balance of each deployed test contract
pub initial_balance: U256,
/// the block.number value during EVM execution
pub block_number: u64,
#[serde(deserialize_with = "crate::deser_u64_to_u256")]
pub block_number: U256,
/// pins the block number for the state fork
pub fork_block_number: Option<u64>,
/// The chain name or EIP-155 chain ID.
Expand All @@ -365,7 +366,8 @@ pub struct Config {
/// The `block.coinbase` value during EVM execution.
pub block_coinbase: Address,
/// The `block.timestamp` value during EVM execution.
pub block_timestamp: u64,
#[serde(deserialize_with = "crate::deser_u64_to_u256")]
pub block_timestamp: U256,
/// The `block.difficulty` value during EVM execution.
pub block_difficulty: u64,
/// Before merge the `block.max_hash`, after merge it is `block.prevrandao`.
Expand Down Expand Up @@ -1660,8 +1662,8 @@ impl Config {
pub fn dapptools() -> Self {
Self {
chain: Some(Chain::from_id(99)),
block_timestamp: 0,
block_number: 0,
block_timestamp: U256::ZERO,
block_number: U256::ZERO,
..Self::default()
}
}
Expand Down Expand Up @@ -2352,15 +2354,15 @@ impl Default for Config {
sender: Self::DEFAULT_SENDER,
tx_origin: Self::DEFAULT_SENDER,
initial_balance: U256::from((1u128 << 96) - 1),
block_number: 1,
block_number: U256::from(1),
fork_block_number: None,
chain: None,
gas_limit: (1u64 << 30).into(), // ~1B
code_size_limit: None,
gas_price: None,
block_base_fee_per_gas: 0,
block_coinbase: Address::ZERO,
block_timestamp: 1,
block_timestamp: U256::from(1),
block_difficulty: 0,
block_prevrandao: Default::default(),
block_gas_limit: None,
Expand Down
18 changes: 18 additions & 0 deletions crates/config/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ where
deserialize_u64_or_max(deserializer)?.try_into().map_err(D::Error::custom)
}

/// Deserialize into `U256` from either a `u64` or a `U256` hex string.
pub fn deser_u64_to_u256<'de, D>(deserializer: D) -> Result<U256, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum NumericValue {
U256(U256),
U64(u64),
}

match NumericValue::deserialize(deserializer)? {
NumericValue::U64(n) => Ok(U256::from(n)),
NumericValue::U256(n) => Ok(n),
}
}

/// Helper type to parse both `u64` and `U256`
#[derive(Clone, Copy, Deserialize)]
#[serde(untagged)]
Expand Down
2 changes: 2 additions & 0 deletions crates/evm/core/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ pub struct Env {
pub block_coinbase: Address,

/// the block.timestamp value during EVM execution
#[serde(deserialize_with = "foundry_config::deser_u64_to_u256")]
pub block_timestamp: U256,

/// the block.number value during EVM execution"
#[serde(deserialize_with = "foundry_config::deser_u64_to_u256")]
pub block_number: U256,

/// the block.difficulty value during EVM execution
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ forgetest!(can_extract_config_values, |prj, cmd| {
sender: "00a329c0648769A73afAc7F9381D08FB43dBEA72".parse().unwrap(),
tx_origin: "00a329c0648769A73afAc7F9F81E08FB43dBEA72".parse().unwrap(),
initial_balance: U256::from(0xffffffffffffffffffffffffu128),
block_number: 10,
block_number: U256::from(10),
fork_block_number: Some(200),
chain: Some(9999.into()),
gas_limit: 99_000_000u64.into(),
code_size_limit: Some(100000),
gas_price: Some(999),
block_base_fee_per_gas: 10,
block_coinbase: Address::random(),
block_timestamp: 10,
block_timestamp: U256::from(10),
block_difficulty: 10,
block_prevrandao: B256::random(),
block_gas_limit: Some(100u64.into()),
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/tests/it/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ impl ForgeTestProfile {
config.gas_limit = u64::MAX.into();
config.chain = None;
config.tx_origin = CALLER;
config.block_number = 1;
config.block_timestamp = 1;
config.block_number = U256::from(1);
config.block_timestamp = U256::from(1);

config.sender = CALLER;
config.initial_balance = U256::MAX;
Expand Down
Loading