From c8cef4834f490fdec38c55027f9aa1132459925f Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Fri, 18 Jul 2025 16:37:15 +0300 Subject: [PATCH] Allow for the use of function signatures --- crates/format/src/input.rs | 49 +++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index 1cdefe4..2ffe14b 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -110,7 +110,7 @@ impl Input { // https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190 let function = abi .functions() - .find(|function| function.name.starts_with(function_name)) + .find(|function| function.signature().starts_with(function_name)) .ok_or_else(|| { anyhow::anyhow!( "Function with name {:?} not found in ABI for the instance {:?}", @@ -424,6 +424,53 @@ mod tests { ); } + #[test] + fn test_encoded_input_address_with_signature() { + let raw_abi = r#"[ + { + "inputs": [{"name": "recipient", "type": "address"}], + "name": "send", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ]"#; + + let parsed_abi: JsonAbi = serde_json::from_str(raw_abi).unwrap(); + let selector = parsed_abi + .function("send") + .unwrap() + .first() + .unwrap() + .selector() + .0; + + let input: Input = Input { + instance: "Contract".to_string(), + method: Method::FunctionName("send(address)".to_owned()), + calldata: Some(Calldata::Compound(vec![ + "0x1000000000000000000000000000000000000001".to_string(), + ])), + ..Default::default() + }; + + let mut abis = HashMap::new(); + abis.insert("Contract".to_string(), parsed_abi); + let contracts = HashMap::new(); + + let encoded = input + .encoded_input(&abis, &contracts, &DummyEthereumNode) + .unwrap(); + assert!(encoded.0.starts_with(&selector)); + + type T = (alloy_primitives::Address,); + let decoded: T = T::abi_decode(&encoded.0[4..]).unwrap(); + assert_eq!( + decoded.0, + address!("0x1000000000000000000000000000000000000001") + ); + } + #[test] fn resolver_can_resolve_chain_id_variable() { // Arrange