Skip to content

Commit

Permalink
feat: support input as alias in eth_call and eth_sendTransaction (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann authored May 13, 2024
1 parent a4d5b62 commit c5da529
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-adults-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": patch
---

Fixed eth_call and eth_sendTransaction to allow passing input data with both `input` and `data` fields
42 changes: 42 additions & 0 deletions crates/edr_eth/src/remote/eth/call_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct CallRequest {
/// transaction value
pub value: Option<U256>,
/// transaction data
#[cfg_attr(feature = "serde", serde(alias = "input"))]
pub data: Option<Bytes>,
/// warm storage access pre-payment
pub access_list: Option<Vec<AccessListItem>>,
Expand All @@ -32,3 +33,44 @@ pub struct CallRequest {
/// Blob versioned hashes (EIP-4844)
pub blob_hashes: Option<Vec<B256>>,
}

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

#[test]
fn data_alias() -> anyhow::Result<()> {
const JSON_WITH_DATA: &str = r#"{
"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"to":"0x5fbdb2315678afecb367f032d93f642f64180aa3",
"data":"0x8b1329e0"
}"#;

const JSON_WITH_INPUT: &str = r#"{
"from":"0x0000000000000000000000000000000000000000",
"input":"0x8b1329e0",
"to":"0x5fbdb2315678afecb367f032d93f642f64180aa3"
}"#;

const JSON_WITH_BOTH: &str = r#"{
"from":"0x0000000000000000000000000000000000000000",
"data":"0x8b1329e0",
"input":"0x8b1329e0",
"to":"0x5fbdb2315678afecb367f032d93f642f64180aa3"
}"#;

let with_data: CallRequest = serde_json::from_str(JSON_WITH_DATA)?;
let with_input: CallRequest = serde_json::from_str(JSON_WITH_INPUT)?;
assert_eq!(with_data.data, with_input.data);

let error: serde_json::Error = serde_json::from_str::<CallRequest>(JSON_WITH_BOTH)
.expect_err("Should fail due to duplicate fields");

assert_eq!(
error.to_string(),
"duplicate field `data` at line 4 column 19"
);

Ok(())
}
}
1 change: 1 addition & 0 deletions crates/edr_eth/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct EthTransactionRequest {
/// value of th tx in wei
pub value: Option<U256>,
/// Any additional data sent
#[cfg_attr(feature = "serde", serde(alias = "input"))]
pub data: Option<Bytes>,
/// Transaction nonce
#[cfg_attr(feature = "serde", serde(default, with = "crate::serde::optional_u64"))]
Expand Down

0 comments on commit c5da529

Please sign in to comment.