Skip to content

Commit

Permalink
fix(rpc-types): do not deny additional fields (#195)
Browse files Browse the repository at this point in the history
* fix(rpc-types): do not deny additional fields

* fmt
  • Loading branch information
Evalir authored Feb 9, 2024
1 parent 80206e7 commit 098ad56
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/rpc-types/src/eth/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde::{Deserialize, Serialize};

/// Represents _all_ transaction requests to/from RPC.
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct TransactionRequest {
/// The address of the transaction author.
Expand Down Expand Up @@ -259,6 +258,8 @@ pub struct TransactionInputError;

#[cfg(test)]
mod tests {
use alloy_primitives::b256;

use super::*;

#[test]
Expand All @@ -285,4 +286,14 @@ mod tests {
let req = serde_json::from_str::<TransactionRequest>(s).unwrap();
assert!(req.input.try_into_unique_input().is_err());
}

#[test]
fn serde_tx_request_additional_fields() {
let s = r#"{"accessList":[],"data":"0x0902f1ac","to":"0xa478c2975ab1ea89e8196811f51a7b7ade33eb11","type":"0x02","sourceHash":"0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a"}"#;
let req = serde_json::from_str::<TransactionRequest>(s).unwrap();
assert_eq!(
req.other.get_deserialized::<B256>("sourceHash").unwrap().unwrap(),
b256!("bf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
);
}
}

0 comments on commit 098ad56

Please sign in to comment.