Repository: gakonst/ethers-rs
Pull request #1191 (2022-04-28 13:22:37)

test(solc): add another link with remapping 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
Adds another test that mimics the compiler input generated in forge
<!--
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/compile/mod.rs b/ethers-solc/src/compile/mod.rs
index 0b5c5bed..5a096829 100644
--- a/ethers-solc/src/compile/mod.rs
+++ b/ethers-solc/src/compile/mod.rs
@@ -704,6 +704,18 @@ mod tests {
         assert!(!bytecode.is_unlinked());
     }
 
+    #[test]
+    fn can_compile_with_remapped_links_temp_dir() {
+        let input: CompilerInput =
+            serde_json::from_str(include_str!("../../test-data/library-remapping-in-2.json"))
+                .unwrap();
+        let out = solc().compile(&input).unwrap();
+        let (_, mut contracts) = out.split();
+        let contract = contracts.remove("LinkTest").unwrap();
+        let bytecode = &contract.get_bytecode().unwrap().object;
+        assert!(!bytecode.is_unlinked());
+    }
+
     #[cfg(feature = "async")]
     #[tokio::test]
     async fn async_solc_compile_works() {


Test patch:
diff --git a/ethers-solc/test-data/library-remapping-in-2.json b/ethers-solc/test-data/library-remapping-in-2.json
new file mode 100644
index 00000000..39a83e2c
--- /dev/null
+++ b/ethers-solc/test-data/library-remapping-in-2.json
@@ -0,0 +1,43 @@
+{
+  "language": "Solidity",
+  "sources": {
+    "/private/var/folders/l5/lprhf87s6xv8djgd017f0b2h0000gn/T/can_create_on_goerli-0vd5EOs/lib/remapping/MyLib.sol": {
+      "content": "\n// SPDX-License-Identifier: MIT\nlibrary MyLib {\n    function foobar(uint256 a) public view returns (uint256) {\n    \treturn a * 100;\n    }\n}\n"
+    },
+    "/private/var/folders/l5/lprhf87s6xv8djgd017f0b2h0000gn/T/can_create_on_goerli-0vd5EOs/src/LinkTest.sol": {
+      "content": "\n// SPDX-License-Identifier: MIT\nimport \"remapping/MyLib.sol\";\ncontract LinkTest {\n    function foo() public returns (uint256) {\n        return MyLib.foobar(1);\n    }\n}\n"
+    }
+  },
+  "settings": {
+    "remappings": [
+      "remapping/=/private/var/folders/l5/lprhf87s6xv8djgd017f0b2h0000gn/T/can_create_on_goerli-0vd5EOs/lib/remapping/",
+      "src/=/private/var/folders/l5/lprhf87s6xv8djgd017f0b2h0000gn/T/can_create_on_goerli-0vd5EOs/src/"
+    ],
+    "optimizer": {
+      "enabled": true,
+      "runs": 200
+    },
+    "metadata": {
+      "bytecodeHash": "ipfs"
+    },
+    "outputSelection": {
+      "*": {
+        "": [
+          "ast"
+        ],
+        "*": [
+          "abi",
+          "evm.bytecode",
+          "evm.deployedBytecode",
+          "evm.methodIdentifiers"
+        ]
+      }
+    },
+    "evmVersion": "london",
+    "libraries": {
+      "/private/var/folders/l5/lprhf87s6xv8djgd017f0b2h0000gn/T/can_create_on_goerli-0vd5EOs/lib/remapping/MyLib.sol": {
+        "MyLib": "0x0000000000000000000000000000000000000000"
+      }
+    }
+  }
+}
\ No newline at end of file