Skip to content

Commit

Permalink
fix: FeeHistory deserialization (alloy-rs#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored May 10, 2024
1 parent 890acea commit 6c58a0a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion crates/rpc-types/src/eth/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct FeeHistory {
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
// with = "alloy_serde::num::u128_vec_via_ruint"
with = "alloy_serde::num::u128_vec_via_ruint"
)]
pub base_fee_per_blob_gas: Vec<u128>,
/// An array of block blob gas used ratios. These are calculated as the ratio of gasUsed and
Expand Down Expand Up @@ -116,3 +116,27 @@ impl FeeHistory {
.copied()
}
}

#[cfg(test)]
mod tests {
use similar_asserts::assert_eq;

use crate::FeeHistory;

#[test]
fn test_fee_history_serde() {
let sample = r#"{"baseFeePerGas":["0x342770c0","0x2da282a8"],"gasUsedRatio":[0.0],"baseFeePerBlobGas":["0x0","0x0"],"blobGasUsedRatio":[0.0],"oldestBlock":"0x1"}"#;
let fee_history: FeeHistory = serde_json::from_str(sample).unwrap();
let expected = FeeHistory {
base_fee_per_blob_gas: vec![0, 0],
base_fee_per_gas: vec![875000000, 765625000],
blob_gas_used_ratio: vec![0.0],
gas_used_ratio: vec![0.0],
oldest_block: 1,
reward: None,
};

assert_eq!(fee_history, expected);
assert_eq!(serde_json::to_string(&fee_history).unwrap(), sample);
}
}

0 comments on commit 6c58a0a

Please sign in to comment.