Skip to content

Commit

Permalink
fix: ensure camel case for untagged (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Feb 29, 2024
1 parent e7edba5 commit d19dfe8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crates/rpc-trace-types/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ use serde::{Deserialize, Serialize};

/// The result of a single transaction trace.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged, rename_all = "camelCase")]
#[serde(untagged)]
pub enum TraceResult<Ok, Err> {
/// Untagged success variant
Success {
/// Trace results produced by the tracer
result: Ok,
/// transaction hash
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none", rename = "txHash")]
tx_hash: Option<TxHash>,
},
/// Untagged error variant
Error {
/// Trace failure produced by the tracer
error: Err,
/// transaction hash
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none", rename = "txHash")]
tx_hash: Option<TxHash>,
},
}
Expand Down
16 changes: 14 additions & 2 deletions crates/rpc-trace-types/src/geth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,20 @@ mod tests {
"input": "0xa9059cbb000000000000000000000000e3f85a274c1edbea2f2498cf5978f41961cf8b5b0000000000000000000000000000000000000000000000000000000068c8f380",
"value": "0x0",
"type": "CALL"
}
},
"txHash": "0x7cc741c553d4098f319c894d9db208999ca49ee1b5c53f6a9992e687cbffb69e"
}"#;
let _result: TraceResult = serde_json::from_str(s).unwrap();
let result: TraceResult = serde_json::from_str(s).unwrap();
let hash = result.tx_hash().unwrap();
assert_eq!(
hash,
"0x7cc741c553d4098f319c894d9db208999ca49ee1b5c53f6a9992e687cbffb69e"
.parse::<B256>()
.unwrap()
);

let de = serde_json::to_value(&result).unwrap();
let val = serde_json::from_str::<serde_json::Value>(s).unwrap();
similar_asserts::assert_eq!(val, de);
}
}

0 comments on commit d19dfe8

Please sign in to comment.