Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when testing or deploying a contract containing a library function call. #6

Closed
kalloc opened this issue Mar 15, 2023 · 5 comments

Comments

@kalloc
Copy link
Contributor

kalloc commented Mar 15, 2023

Hi.

Thank you very much for your work.
But, I found a mistake while using it.
If the contract under test contains a library function call, the testing fails.
I made a repo with an error https://github.com/8gen/0xPhaze-upgrade-script-bug, so you may repeat.

How I call function:

..
import {Lib} from "./library/Lib.sol";
..
number = newNumber + Lib.x();
..
$ forge test

[⠆] Compiling...
No files changed, compilation skipped
2023-03-15T12:59:19.471056Z ERROR forge::runner: setUp failed reason="failed to read from \"../out/Counter/Counter.json\": No such file or directory (os error 2)" contract=0x7fa9385be102ac3eac297483dd6233d62b3e1496

Running 1 test for test/Counter.t.sol:CounterTest
[FAIL. Reason: Setup failed: failed to read from "../out/Counter/Counter.json": No such file or directory (os error 2)] setUp() (gas: 0)
Test result: FAILED. 0 passed; 1 failed; finished in 965.23µs

Failing tests:
Encountered 1 failing test in test/Counter.t.sol:CounterTest
[FAIL. Reason: Setup failed: failed to read from "../out/Counter/Counter.json": No such file or directory (os error 2)] setUp() (gas: 0)

Encountered a total of 1 failing tests, 0 tests succeeded
@kalloc
Copy link
Contributor Author

kalloc commented Mar 15, 2023

Maybe the problem in foundry (foundry-rs/book#1361)

@0xPhaze
Copy link
Owner

0xPhaze commented Mar 15, 2023

The issue is that the artifact folder now has multiple files with the included lib and you should specify the contract location via "Counter.sol:Counter".

However, I added an extra search for "{Contract}.sol:{Contract}" and 9112da4 should fix this. Also should have better error logging now. Let me know if it works.

@0xPhaze
Copy link
Owner

0xPhaze commented Mar 15, 2023

@kalloc actually there seems to be another issue related to this. I think foundry doesn't handle public library linking well. You might want to change

function x() public pure returns (uint256) {
    return X;
}

to

function x() internal pure returns (uint256) {
    return X;
}

@kalloc
Copy link
Contributor Author

kalloc commented Mar 15, 2023 via email

@0xPhaze
Copy link
Owner

0xPhaze commented Mar 20, 2023

Closing this here then for now

@0xPhaze 0xPhaze closed this as completed Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants