Repository: gakonst/ethers-rs
Pull request #929 (2022-02-18 16:17:57)

test: add curly bracket import test
<!--
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
Ensure we can parse curly bracket imports via solang and via regex
<!--
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

- [x] Added Tests
- [ ] Added Documentation
- [ ] Updated the changelog



Patch:
diff --git a/ethers-solc/src/compile/mod.rs b/ethers-solc/src/compile/mod.rs
index 11fd3ad0..9841fcc6 100644
--- a/ethers-solc/src/compile/mod.rs
+++ b/ethers-solc/src/compile/mod.rs
@@ -79,7 +79,8 @@ pub static RELEASES: once_cell::sync::Lazy<(svm::Releases, Vec<Version>, bool)>
 
 /// A `Solc` version is either installed (available locally) or can be downloaded, from the remote
 /// endpoint
-#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
+#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
+#[serde(untagged)]
 pub enum SolcVersion {
     Installed(Version),
     Remote(Version),
diff --git a/ethers-solc/src/resolver.rs b/ethers-solc/src/resolver.rs
index 1d9a515a..16bfbc34 100644
--- a/ethers-solc/src/resolver.rs
+++ b/ethers-solc/src/resolver.rs
@@ -476,7 +476,7 @@ impl Graph {
             }
 
             let mut result = sets.pop().cloned().expect("not empty; qed.").clone();
-            if sets.len() > 1 {
+            if !sets.is_empty() {
                 result.retain(|item| sets.iter().all(|set| set.contains(item)));
             }
 
diff --git a/ethers-solc/src/utils.rs b/ethers-solc/src/utils.rs
index a5e5978c..c15a2697 100644
--- a/ethers-solc/src/utils.rs
+++ b/ethers-solc/src/utils.rs
@@ -341,6 +341,7 @@ pub fn create_parent_dir_all(file: impl AsRef<Path>) -> Result<(), SolcError> {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use solang_parser::pt::SourceUnitPart;
     use std::{
         collections::HashSet,
         fs::{create_dir_all, File},
@@ -383,6 +384,22 @@ mod tests {
         assert_eq!(files, expected);
     }
 
+    #[test]
+    fn can_parse_curly_bracket_imports() {
+        let s =
+            r#"import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";"#;
+
+        let (unit, _) = solang_parser::parse(s, 0).unwrap();
+        assert_eq!(unit.0.len(), 1);
+        match unit.0[0] {
+            SourceUnitPart::ImportDirective(_, _) => {}
+            _ => unreachable!("failed to parse import"),
+        }
+        let imports: Vec<_> = find_import_paths(s).map(|m| m.as_str()).collect();
+
+        assert_eq!(imports, vec!["@openzeppelin/contracts/utils/ReentrancyGuard.sol"])
+    }
+
     #[test]
     fn can_find_single_quote_imports() {
         let content = r#"


Test patch:
diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs
index ac8c01f7..c1afeb4f 100644
--- a/ethers-solc/tests/project.rs
+++ b/ethers-solc/tests/project.rs
@@ -24,7 +24,6 @@ fn init_tracing() {
 }
 
 #[test]
-#[ignore]
 fn can_get_versioned_linkrefs() {
     let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test-data/test-versioned-linkrefs");
     let paths = ProjectPathsConfig::builder()
@@ -37,8 +36,6 @@ fn can_get_versioned_linkrefs() {
 
     let compiled = project.compile().unwrap();
     assert!(!compiled.has_compiler_errors());
-
-    // TODO:
 }
 
 #[test]