Skip to content

Commit

Permalink
fix: camel case with chain id rename
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jan 3, 2025
1 parent 9249381 commit 2593278
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crates/protocol/src/messages/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl From<Log> for MessagePayload {
/// CrossL2Inbox contract.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct MessageIdentifier {
/// The account that sent the message.
pub origin: Address,
Expand All @@ -65,6 +66,7 @@ pub struct MessageIdentifier {
/// The timestamp of the message.
pub timestamp: u64,
/// The chain ID of the chain that the message was sent on.
#[cfg_attr(feature = "serde", serde(rename = "chainID"))]
pub chain_id: u64,
}

Expand Down Expand Up @@ -104,3 +106,30 @@ impl From<executeMessageCall> for ExecutingMessage {
Self { id: call._id, msgHash: keccak256(call._message.as_ref()) }
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_message_identifier_serde() {
let raw_id = r#"
{
"origin": "0x6887246668a3b87F54DeB3b94Ba47a6f63F32985",
"blockNumber": 123456,
"logIndex": 789,
"timestamp": 1618932000,
"chainID": 420
}
"#;
let id: MessageIdentifier = serde_json::from_str(raw_id).unwrap();
let expected = MessageIdentifier {
origin: "0x6887246668a3b87F54DeB3b94Ba47a6f63F32985".parse().unwrap(),
block_number: 123456,
log_index: 789,
timestamp: 1618932000,
chain_id: 420,
};
assert_eq!(id, expected);
}
}

0 comments on commit 2593278

Please sign in to comment.