From 12fb3d35c63b8363c22f0ab45cc7ebee52bc08ad Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 24 Feb 2022 22:58:19 +0100 Subject: [PATCH] fix(abigen): dont generate empty shared_types module --- .../ethers-contract-abigen/src/multi.rs | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ethers-contract/ethers-contract-abigen/src/multi.rs b/ethers-contract/ethers-contract-abigen/src/multi.rs index a77b71a88..bb9a12f7d 100644 --- a/ethers-contract/ethers-contract-abigen/src/multi.rs +++ b/ethers-contract/ethers-contract-abigen/src/multi.rs @@ -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())); @@ -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();