fix(abigen): remove trailing test,script markers (#1776)

This commit is contained in:
Matthias Seitz 2022-10-11 19:48:30 +02:00 committed by GitHub
parent 12548b5abf
commit ef22e05a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -104,6 +104,10 @@ impl Abigen {
.to_str()
.ok_or_else(|| eyre::format_err!("Unable to convert file stem to string"))?;
// test,script files usually end with `.t.sol` or `.s.sol`, we simply cut off everything
// after the first `.`
let name = name.split('.').next().expect("name not empty.");
Self::new(name, std::fs::read_to_string(path.as_ref())?)
}
@ -311,4 +315,39 @@ contract Greeter {
assert!(out.contains("pub struct Stuff"));
assert!(out.contains("pub struct Inner"));
}
#[test]
fn can_compile_and_generate_with_punctuation() {
let tmp = TempProject::dapptools().unwrap();
tmp.add_source(
"Greeter.t.sol",
r#"
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
contract Greeter {
struct Inner {
bool a;
}
struct Stuff {
Inner inner;
}
function greet(Stuff calldata stuff) public view returns (Stuff memory) {
return stuff;
}
}
"#,
)
.unwrap();
let _ = tmp.compile().unwrap();
let abigen =
Abigen::from_file(tmp.artifacts_path().join("Greeter.t.sol/Greeter.json")).unwrap();
let gen = abigen.generate().unwrap();
let out = gen.tokens.to_string();
assert!(out.contains("pub struct Stuff"));
assert!(out.contains("pub struct Inner"));
}
}