Skip to content
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

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Copy link
Member

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

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 @@ -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"}"#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this fixture from

Copy link
Member Author

Choose a reason for hiding this comment

The 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 Transaction in the future

);
let deserialized: Transaction = serde_json::from_str(&serialized).unwrap();
assert_eq!(transaction, deserialized);
}
}
Loading