From ef22e05a9a587a75c062aab14093ff6785b7937c Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 11 Oct 2022 19:48:30 +0200 Subject: [PATCH] fix(abigen): remove trailing test,script markers (#1776) --- .../ethers-contract-abigen/src/lib.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ethers-contract/ethers-contract-abigen/src/lib.rs b/ethers-contract/ethers-contract-abigen/src/lib.rs index 3b69d575..6e06533f 100644 --- a/ethers-contract/ethers-contract-abigen/src/lib.rs +++ b/ethers-contract/ethers-contract-abigen/src/lib.rs @@ -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")); + } }