nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gakonst/ethers-rs
Pull request #1583 (2022-08-09 20:11:08)

fix(solc): strip .sol suffix
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.

Contributors guide: https://github.com/gakonst/ethers-rs/blob/master/CONTRIBUTING.md

The contributors guide includes instructions for running rustfmt and building the
documentation.
-->

## Motivation
fixes failing test introduced in https://github.com/gakonst/ethers-rs/pull/1580 by correctly stripping `.sol` suffix from contract name /file anme
<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of as being the motivation for your change.
-->

## Solution

<!--
Summarize the solution and provide any necessary context needed to understand
the code change.
-->

## PR Checklist

- [ ] Added Tests
- [ ] Added Documentation
- [ ] Updated the changelog



Patch:
diff --git a/ethers-solc/src/project_util/mod.rs b/ethers-solc/src/project_util/mod.rs
index 5b2b95d8..7d0c8b22 100644
--- a/ethers-solc/src/project_util/mod.rs
+++ b/ethers-solc/src/project_util/mod.rs
@@ -185,6 +185,7 @@ impl<T: ArtifactOutput> TempProject<T> {
         version: impl AsRef<str>,
     ) -> Result<PathBuf> {
         let name = name.as_ref();
+        let name = name.strip_suffix(".sol").unwrap_or(name);
         self.add_lib(
             name,
             format!(
@@ -213,6 +214,7 @@ contract {} {{}}
         version: impl AsRef<str>,
     ) -> Result<PathBuf> {
         let name = name.as_ref();
+        let name = name.strip_suffix(".sol").unwrap_or(name);
         self.add_source(
             name,
             format!(


Test patch:
diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs
index cb3cbdfd..0a0a023b 100644
--- a/ethers-solc/tests/project.rs
+++ b/ethers-solc/tests/project.rs
@@ -2150,14 +2150,15 @@ fn can_add_basic_contract_and_library() {
 
     let src = project.add_basic_source("Foo.sol", "^0.8.0").unwrap();
 
-    let lib = project.add_basic_source("Bar.sol", "^0.8.0").unwrap();
+    let lib = project.add_basic_source("Bar", "^0.8.0").unwrap();
 
     let graph = Graph::resolve(project.paths()).unwrap();
     assert_eq!(graph.files().len(), 2);
-    assert_eq!(graph.files().clone(), HashMap::from([(src, 0), (lib, 1),]));
+    assert!(graph.files().contains_key(&src));
+    assert!(graph.files().contains_key(&lib));
 
     let compiled = project.compile().unwrap();
+    assert!(!compiled.has_compiler_errors());
     assert!(compiled.find_first("Foo").is_some());
     assert!(compiled.find_first("Bar").is_some());
-    assert!(!compiled.has_compiler_errors());
 }