Skip to content

Commit

Permalink
fix(json-abi): correct to-sol for UDVT arrays in structs (#745)
Browse files Browse the repository at this point in the history
* fix(json-abi): correct to-sol for UDVT arrays in structs

* chore: clippy
  • Loading branch information
DaniPopes authored Sep 24, 2024
1 parent 4b823f7 commit 9183606
Show file tree
Hide file tree
Showing 7 changed files with 1,915 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/json-abi/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Param {
/// instantiate directly. Use Param::new instead.
#[doc(hidden)]
pub name: String,
/// If the paramaeter is a compound type (a struct or tuple), a list of the
/// If the parameter is a compound type (a struct or tuple), a list of the
/// parameter's components, in order. Empty otherwise
pub components: Vec<Param>,
/// The internal type of the parameter. This type represents the type that
Expand Down Expand Up @@ -325,7 +325,7 @@ pub struct EventParam {
/// Whether the parameter is indexed. Indexed parameters have their
/// value, or the hash of their value, stored in the log topics.
pub indexed: bool,
/// If the paramaeter is a compound type (a struct or tuple), a list of the
/// If the parameter is a compound type (a struct or tuple), a list of the
/// parameter's components, in order. Empty otherwise. Because the
/// components are not top-level event params, they will not have an
/// `indexed` field.
Expand Down
10 changes: 6 additions & 4 deletions crates/json-abi/src/to_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a> InternalTypes<'a> {
&mut self,
internal_type: Option<&'a InternalType>,
components: &'a Vec<Param>,
real_ty: &'a String,
real_ty: &'a str,
) {
match internal_type {
None | Some(InternalType::AddressPayable(_) | InternalType::Contract(_)) => {}
Expand All @@ -229,9 +229,11 @@ impl<'a> InternalTypes<'a> {
}
}
Some(it @ InternalType::Other { contract, ty }) => {
// `Other` is a UDVT if it's not a basic Solidity type and not an array
// `Other` is a UDVT if it's not a basic Solidity type.
if let Some(it) = it.other_specifier() {
if it.try_basic_solidity().is_err() && !it.is_array() {
if it.try_basic_solidity().is_err() {
let ty = ty.split('[').next().unwrap();
let real_ty = real_ty.split('[').next().unwrap();
self.extend_one(contract, It::new(ty, ItKind::Udvt(real_ty)));
}
}
Expand Down Expand Up @@ -264,7 +266,7 @@ struct It<'a> {
#[derive(PartialEq, Eq)]
enum ItKind<'a> {
Enum,
Udvt(&'a String),
Udvt(&'a str),
Struct(&'a Vec<Param>),
}

Expand Down
2 changes: 2 additions & 0 deletions crates/json-abi/tests/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ fn to_sol_test(path: &str, abi: &JsonAbi, run_solc: bool) {
|"ZeroXExchange"| "GaugeController" | "DoubleExponentInterestSetter" | "NamelessParams"
// UniswapV1Exchange has return values with the same name.
| "UniswapV1Exchange"
// https://github.com/alloy-rs/core/issues/744
| "DelegationManager"
) {
return;
}
Expand Down
Loading

0 comments on commit 9183606

Please sign in to comment.