fix: Preserve gas price chart across empty buckets#44
Conversation
📝 WalkthroughWalkthroughThe backend now returns Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/crates/atlas-server/src/api/handlers/stats.rs (1)
231-266: Consider adding a unit test for nullable serialization.The existing tests cover
Windowenum methods but don't validate the new nullableavg_gas_pricebehavior. A simple serialization test would help ensureOption<f64>serializes correctly to JSONnull.📝 Example test to add
+ #[test] + fn gas_price_point_serializes_null() { + let point = GasPricePoint { + bucket: "2024-01-01T00:00:00Z".to_string(), + avg_gas_price: None, + }; + let json = serde_json::to_string(&point).unwrap(); + assert!(json.contains(r#""avg_gas_price":null"#)); + }As per coding guidelines: "Add unit tests for new logic in a
#[cfg(test)] mod testsblock in the same file".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/crates/atlas-server/src/api/handlers/stats.rs` around lines 231 - 266, Add a unit test in the existing #[cfg(test)] mod tests that verifies nullable avg_gas_price serializes to JSON null and Some(f64) serializes to a numeric value: create a small #[derive(Serialize, Deserialize, PartialEq, Debug)] temp struct with an avg_gas_price: Option<f64> field inside the tests module, use serde_json::to_string (and optionally from_str) to assert that None -> "null" for that field in the JSON and Some(1.23) -> numeric 1.23, and place the test alongside the existing Window tests so it runs with cargo test; reference avg_gas_price, serde_json::to_string, and the tests module when locating where to add it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/crates/atlas-server/src/api/handlers/stats.rs`:
- Around line 231-266: Add a unit test in the existing #[cfg(test)] mod tests
that verifies nullable avg_gas_price serializes to JSON null and Some(f64)
serializes to a numeric value: create a small #[derive(Serialize, Deserialize,
PartialEq, Debug)] temp struct with an avg_gas_price: Option<f64> field inside
the tests module, use serde_json::to_string (and optionally from_str) to assert
that None -> "null" for that field in the JSON and Some(1.23) -> numeric 1.23,
and place the test alongside the existing Window tests so it runs with cargo
test; reference avg_gas_price, serde_json::to_string, and the tests module when
locating where to add it.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b221d7f7-91af-4127-820a-abd7cf2f17e0
📒 Files selected for processing (4)
backend/crates/atlas-server/src/api/handlers/stats.rsfrontend/src/api/chartData.tsfrontend/src/hooks/useChartData.tsfrontend/src/pages/StatusPage.tsx
Avoid plotting a zero gas price when a bucket has no transactions.
Carry the last observed gas price forward in the status chart instead.
Summary by CodeRabbit