gakonst / ethers-rs

Complete Ethereum & Celo library and wallet implementation in Rust. https://docs.rs/ethers
Apache License 2.0
2.48k stars 796 forks source link

Cargo test Failed in ethers-solc #1895

Open aewc opened 1 year ago

aewc commented 1 year ago

Version I pull the ethers-rs, and using the Commit b0ef1343dd71c28bdce74212aa136e827b9c54a8.

Platform

Darwin C27C.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103 arm64

Description

$ cd ethers-rs
$ ETHERSCAN_API_KEY=xxxxx GOERLI_PRIVATE_KEY=xxxxx cargo test
...
failures:

---- config::tests::can_autodetect_dirs stdout ----
thread 'config::tests::can_autodetect_dirs' panicked at 'assertion failed: `(left == right)`
  left: `"/private/var/folders/2y/70kmz0xn3j95ncb5fw0j737w0000gn/T/rootPom69r/artifacts/build-info"`,
 right: `"/var/folders/2y/70kmz0xn3j95ncb5fw0j737w0000gn/T/rootPom69r/artifacts/build-info"`', ethers-solc/src/config.rs:934:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    config::tests::can_autodetect_dirs

test result: FAILED. 73 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.74s

error: test failed, to rerun pass `-p ethers-solc --lib`

The path difference in tests::can_autodetect_dirs is only /private

mattsse commented 1 year ago

ah this is a mac symlink issue

path paths point to the same file, but the way std::fs::canonicalize works on mac is that /private/var/ is resolved to /var, or the other way around, can't remember.

this could be fixed by used std::fs::canonicalize on the other variant in the assertEq I think.

Could you please try that?

aewc commented 1 year ago

Yes, macOS have this weird linked dir: std::fs::canonicalize would add /private in /var

However, it has not been resolved. The root cause is that the build-info folder has not been created, resulting in

pub fn canonicalized(path: impl Into<PathBuf>) -> PathBuf {
     let path = path.into();
     canonicalize(&path).unwrap_or(path)
}

unwrap_or directly returns path.

I printed some information, as follows:

Ok("/private/var/folders/2y/70kmz0xn3j95ncb5fw0j737w0000gn/T/root9n6PoM")
Ok("/private/var/folders/2y/70kmz0xn3j95ncb5fw0j737w0000gn/T/root9n6PoM/contracts")
Ok("/private/var/folders/2y/70kmz0xn3j95ncb5fw0j737w0000gn/T/root9n6PoM/src")
Ok("/private/var/folders/2y/70kmz0xn3j95ncb5fw0j737w0000gn/T/root9n6PoM/artifacts")
Err(SolcIoError { io: Os { code: 20, kind: NotADirectory, message: "Not a directory" }, path: "/var/folders/2y/70kmz0xn3j95ncb5fw0j737w0000gn/T/root9n6PoM/artifacts/build-info" })

The build_infos is newed by artifacts.join("build-info"), while others are newed by root.path().join(), this may cause build-info not creating:

    fn can_autodetect_dirs() {
        let root = utils::tempdir("root").unwrap();
        let out = root.path().join("out");
        let artifacts = root.path().join("artifacts");
        let build_infos = artifacts.join("build-info");
        let contracts = root.path().join("contracts");
        let src = root.path().join("src");
        let lib = root.path().join("lib");
        let node_modules = root.path().join("node_modules");
        ...