Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Cargo test Failed in ethers-solc #1895

Open
aewc opened this issue Nov 27, 2022 · 2 comments
Open

Cargo test Failed in ethers-solc #1895

aewc opened this issue Nov 27, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@aewc
Copy link

aewc commented Nov 27, 2022

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

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

@aewc aewc added the bug Something isn't working label Nov 27, 2022
@mattsse
Copy link
Collaborator

mattsse commented Nov 27, 2022

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
Copy link
Author

aewc commented Nov 27, 2022

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");
        ...

gakonst pushed a commit that referenced this issue Jan 13, 2023
The test was failing for two reasons on macOS:

1. The build info directory was not created during the test.
2. Temporary directories are created with symbolic links on macOS and
the path canonicalization returns the given path if it doesn't exist.

This lead to a mismatch between the project root's canonical path (which
did exist and thus was a real path after canonicalization) and the build
info directory's canonical path (which did not exist and was a symbolic
link after canonicalization).

The fix is to create the build info directory to make sure its canonical
path matches the project root's canonical path.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants