Skip to content

Commit

Permalink
avoid handling of blocks, different from Foundry implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Jun 18, 2024
1 parent 767cd22 commit 0502553
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions crates/rpc-types-anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ pub struct ForkedNetwork {

/// Additional `evm_mine` options
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum MineOptions {
/// The options for mining
Expand All @@ -152,7 +151,6 @@ pub enum MineOptions {
timestamp: Option<u64>,
/// If `blocks` is given, it will mine exactly blocks number of blocks, regardless of any
/// other blocks mined or reverted during it's operation
#[serde(with = "alloy_serde::num::u64_opt_via_ruint")]
blocks: Option<u64>,
},
/// The timestamp the block should be mined with
Expand Down Expand Up @@ -313,4 +311,28 @@ mod tests {
serde_json::from_value(json_data).expect("Failed to deserialize large index");
assert_eq!(index, Index(u64::MAX as usize));
}

#[test]
fn test_deserialize_options_with_values() {
let data = r#"{"timestamp":"1620000000","blocks":"10"}"#;
let deserialized: MineOptions = serde_json::from_str(data).expect("Deserialization failed");
assert_eq!(
deserialized,
MineOptions::Options { timestamp: Some(1620000000), blocks: Some(10) }
);
}

#[test]
fn test_deserialize_timestamp() {
let data = r#""1620000000""#;
let deserialized: MineOptions = serde_json::from_str(data).expect("Deserialization failed");
assert_eq!(deserialized, MineOptions::Timestamp(Some(1620000000)));
}

#[test]
fn test_deserialize_timestamp_hex() {
let data = r#""0x608f3d00""#;
let deserialized: MineOptions = serde_json::from_str(data).expect("Deserialization failed");
assert_eq!(deserialized, MineOptions::Timestamp(Some(1620000000)));
}
}

0 comments on commit 0502553

Please sign in to comment.