fix(abigen): dont generate empty shared_types module (#965)
This commit is contained in:
parent
f5ef8149e5
commit
b6c22e9bcc
|
@ -113,11 +113,13 @@ impl MultiExpansionResult {
|
||||||
|
|
||||||
let Self { contracts, shared_types, .. } = self;
|
let Self { contracts, shared_types, .. } = self;
|
||||||
|
|
||||||
|
if !shared_types.is_empty() {
|
||||||
tokens.extend(quote! {
|
tokens.extend(quote! {
|
||||||
pub mod #shared_types_module {
|
pub mod #shared_types_module {
|
||||||
#( #shared_types )*
|
#( #shared_types )*
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
tokens.extend(contracts.into_iter().map(|(exp, _)| exp.into_tokens()));
|
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]
|
#[test]
|
||||||
fn can_deduplicate_types() {
|
fn can_deduplicate_types() {
|
||||||
let tmp = TempProject::dapptools().unwrap();
|
let tmp = TempProject::dapptools().unwrap();
|
||||||
|
|
Loading…
Reference in New Issue