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

Commit

Permalink
fix(abigen): remove trailing test,script markers (#1776)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 11, 2022
1 parent 12548b5 commit ef22e05
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ethers-contract/ethers-contract-abigen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?)
}

Expand Down Expand Up @@ -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"));
}
}

0 comments on commit ef22e05

Please sign in to comment.