From 783646176325fc5c0792e5bdeeb4a1008e60bec2 Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Mon, 21 Jul 2025 12:15:27 +0300 Subject: [PATCH] Add test --- crates/format/src/input.rs | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index 6bbf771..9ae5d6e 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -434,6 +434,53 @@ mod tests { assert_eq!(decoded.0, 42); } + #[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_owned().into(), + method: Method::FunctionName("send(address)".to_owned()), + calldata: Some(Calldata::Compound(vec![ + "0x1000000000000000000000000000000000000001".to_string(), + ])), + ..Default::default() + }; + + let mut contracts = HashMap::new(); + contracts.insert( + ContractInstance::new_from("Contract"), + (Address::ZERO, parsed_abi), + ); + + let encoded = input.encoded_input(&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 test_encoded_input_address() { let raw_abi = r#"[