Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix(abigen): dont generate empty shared_types module #965

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions ethers-contract/ethers-contract-abigen/src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ impl MultiExpansionResult {

let Self { contracts, shared_types, .. } = self;

tokens.extend(quote! {
pub mod #shared_types_module {
#( #shared_types )*
}
});
if !shared_types.is_empty() {
tokens.extend(quote! {
pub mod #shared_types_module {
#( #shared_types )*
}
});
}

tokens.extend(contracts.into_iter().map(|(exp, _)| exp.into_tokens()));

Expand Down Expand Up @@ -977,6 +979,22 @@ mod tests {
})
}

#[test]
fn does_not_generate_shared_types_if_empty() {
let gen = Abigen::new(
"Greeter",
r#"[
struct Inner {bool a;}
greet1() (uint256)
greet2(Inner inner) (string)
]"#,
)
.unwrap();

let tokens = MultiExpansion::new(vec![gen.expand().unwrap()]).expand_inplace().to_string();
assert!(!tokens.contains("mod __shared_types"));
}

#[test]
fn can_deduplicate_types() {
let tmp = TempProject::dapptools().unwrap();
Expand Down