fix(abigen): remove redundant index adjustment for many overloads (#1419)
This commit is contained in:
parent
6c89311b33
commit
f17f900d01
|
@ -414,21 +414,11 @@ impl Context {
|
|||
let mut functions = functions.iter().enumerate().collect::<Vec<_>>();
|
||||
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
|
||||
// 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()
|
||||
// and is the baseline for the diff
|
||||
|
|
|
@ -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(_) => {}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue