-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: correctly process chainId field #370
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,9 @@ pub struct Transaction { | |
#[serde(flatten, skip_serializing_if = "Option::is_none")] | ||
pub signature: Option<Signature>, | ||
/// The chain id of the transaction, if any. | ||
#[serde(default)] | ||
#[serde(with = "alloy_serde::u64_hex_opt")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub chain_id: Option<u64>, | ||
/// Contains the blob hashes for eip-4844 transactions. | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
|
@@ -315,4 +317,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"}"# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this fixture from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's just a fixture from the test above with all options set to None, the idea was to test that we can handle any of the optional fields missing I can change it to a valid legacy tx payload so we avoid unexpected test failures when modifying |
||
); | ||
let deserialized: Transaction = serde_json::from_str(&serialized).unwrap(); | ||
assert_eq!(transaction, deserialized); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we collapse them into a single serde attribute?
the skip is also fine because this field should be ignored