From f17f900d01b938833c44ab1231160715347833c1 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 27 Jun 2022 20:52:06 +0200 Subject: [PATCH] fix(abigen): remove redundant index adjustment for many overloads (#1419) --- .../src/contract/methods.rs | 18 +++---------- ethers-contract/tests/abigen.rs | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs index efe628fa..dee0da35 100644 --- a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs +++ b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs @@ -414,20 +414,10 @@ impl Context { let mut functions = functions.iter().enumerate().collect::>(); functions.sort_by(|(_, f1), (_, f2)| f1.inputs.len().cmp(&f2.inputs.len())); - // the `functions` are now mapped with their index according as defined in the ABI, but - // we always want the zero arg function (`log()`) to be `log0`, even if it defined after - // an overloaded function like `log(address)` - if num_functions > NAME_ALIASING_OVERLOADED_FUNCTIONS_CAP { - // lots of overloads, so we set `log()` to index 0, and shift all fun - for (idx, _) in &mut functions[1..] { - *idx += 1; - } - functions[0].0 = 0; - } else { - // for few overloads we stick entirely to the input len order - for (idx, (f_idx, _)) in functions.iter_mut().enumerate() { - *f_idx = idx; - } + // the `functions` are now mapped with their index as defined in the ABI, but + // we always want the zero arg function (`log()`) to be `log0` + for (idx, (f_idx, _)) in functions.iter_mut().enumerate() { + *f_idx = idx; } // the first function will be the function with the least amount of inputs, like log() diff --git a/ethers-contract/tests/abigen.rs b/ethers-contract/tests/abigen.rs index 8b79ec7f..b5d6ded5 100644 --- a/ethers-contract/tests/abigen.rs +++ b/ethers-contract/tests/abigen.rs @@ -1,4 +1,5 @@ #![cfg(feature = "abigen")] +#![allow(unused)] //! Test cases to validate the `abigen!` macro use ethers_contract::{abigen, EthCall, EthEvent}; use ethers_core::{ @@ -601,3 +602,27 @@ fn can_gen_seaport() { ); assert_eq!(hex::encode(FulfillAdvancedOrderCall::selector()), "e7acab24"); } + +#[test] +fn can_generate_to_string_overload() { + abigen!( + ToString, + r#"[ + toString(bytes) + toString(address) + toString(uint256) + toString(int256) + toString(bytes32) + toString(bool) + ]"# + ); + + match ToStringCalls::ToString0(ToString0Call(Default::default())) { + ToStringCalls::ToString0(_) => {} + ToStringCalls::ToString1(_) => {} + ToStringCalls::ToString2(_) => {} + ToStringCalls::ToString3(_) => {} + ToStringCalls::ToString4(_) => {} + ToStringCalls::ToString5(_) => {} + }; +}