Skip to content

Commit

Permalink
fix: correctly process chainId field (#370)
Browse files Browse the repository at this point in the history
* fix: correctly process chainId field

* skip if none

* fix
  • Loading branch information
klkvr authored Mar 22, 2024
1 parent 3224c25 commit 825ec7f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion crates/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct Transaction {
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub signature: Option<Signature>,
/// The chain id of the transaction, if any.
#[serde(with = "alloy_serde::u64_hex_opt")]
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::u64_hex_opt")]
pub chain_id: Option<u64>,
/// Contains the blob hashes for eip-4844 transactions.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand Down Expand Up @@ -314,4 +314,24 @@ mod tests {
let deserialized: Transaction = serde_json::from_str(&serialized).unwrap();
assert_eq!(transaction, deserialized);
}

#[test]
fn serde_minimal_transaction() {
let transaction = Transaction {
hash: B256::with_last_byte(1),
nonce: 2,
from: Address::with_last_byte(6),
value: U256::from(8),
gas: U256::from(10),
input: Bytes::from(vec![11, 12, 13]),
..Default::default()
};
let serialized = serde_json::to_string(&transaction).unwrap();
assert_eq!(
serialized,
r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000001","nonce":"0x2","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000006","to":null,"value":"0x8","gas":"0xa","input":"0x0b0c0d"}"#
);
let deserialized: Transaction = serde_json::from_str(&serialized).unwrap();
assert_eq!(transaction, deserialized);
}
}

0 comments on commit 825ec7f

Please sign in to comment.