Compare commits

...

3 Commits

Author SHA1 Message Date
Omar Abdulla 7836461763 Add test 2025-07-21 12:15:27 +03:00
Omar Abdulla 0e473e1633 Merge remote-tracking branch 'origin/main' into bugfix/function-signature 2025-07-21 12:13:24 +03:00
Omar Abdulla c8cef4834f Allow for the use of function signatures 2025-07-18 16:37:15 +03:00
+48 -1
View File
@@ -150,7 +150,7 @@ impl Input {
// https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190 // https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190
let function = abi let function = abi
.functions() .functions()
.find(|function| function.name.starts_with(function_name)) .find(|function| function.signature().starts_with(function_name))
.ok_or_else(|| { .ok_or_else(|| {
anyhow::anyhow!( anyhow::anyhow!(
"Function with name {:?} not found in ABI for the instance {:?}", "Function with name {:?} not found in ABI for the instance {:?}",
@@ -434,6 +434,53 @@ mod tests {
assert_eq!(decoded.0, 42); 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] #[test]
fn test_encoded_input_address() { fn test_encoded_input_address() {
let raw_abi = r#"[ let raw_abi = r#"[