foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Forge test hangs forever

Open jdbertron opened this issue 1 year ago • 8 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (388c3c0 2023-04-12T03:09:53.984763822Z)

What command(s) is the bug in?

forge test --ffi

Operating System

Linux

Describe the bug

I have a diamond contract that has multiple facets. The high level description is that one facet lets a user publish a series of puzzles, keyed by hashes and tracked by owner. One facet lets anyone query the puzzles. I can retrieve all but the first puzzle. Attempting to retrieve any other hangs the test. I have a separate issue in which the EVM runs out of gas calling a separate method (see bottom of https://github.com/foundry-rs/foundry/issues/3971) . I have looked at expanding the gas and memory limits, but none seem to have an impact. The code works fine on Goerli.

You can check out the test here https://github.com/BqETH/solidity/commit/4ecf04021a11736d6f956c51cc18bea99d0cd3e4 and run forge test --ffi -vvvv -m "testCanRegisterPuzzle"

to make it hang. If I try the debugger, it also hangs and never gives me the debugger screen. I'm not sure what else I can do.

jdbertron avatar Apr 12 '23 18:04 jdbertron

Strangely if you run this command with RUST_LOG=forge it fails Screen Shot 2023-04-12 at 5 38 26 PM

brockelmore avatar Apr 13 '23 00:04 brockelmore

Interesting. So that's equivalent to -vvvvv and I get the same error. Thanks for pointing that out. I'll research why that might be. Presumably a revert during setup should prevent the tests from attempting to run, that should be a fail-fast regarding of the logging level.

jdbertron avatar Apr 13 '23 18:04 jdbertron

I have two open issues where forge test hangs, and I'm also using a Diamond: #4656 and #4735.

In case you want to have a look.

trojanMcAfee avatar Apr 13 '23 19:04 trojanMcAfee

Lol. Ok, that's not really the source of the bug. The RUST_LOG=forge environment gets passed on to the "forge inspect facet methods" invocation within the HelperContract that tries to extract method selectors for adding them to the diamond. So instead of getting a nice list of method:selector it gets a blob from the contract artifact and all the parsing gets out of whack, causing that error.

jdbertron avatar Apr 13 '23 21:04 jdbertron

Ok, the problem you found was just caused by the RUST_LOG setting. I fixed that problem in the Diamond deployment code. See this: https://github.com/FydeTreasury/Diamond-Foundry/pull/6/commits/755144352b20f9ad9c84e22feb8fe3d6646e9f39 You can check out the lasted commit https://github.com/BqETH/solidity or just change the HelperContract:generateSelectors method to this: `
// return array of function selectors for given facet name function generateSelectors(string memory _facetName) internal returns (bytes4[] memory selectors) { //get string of contract methods string[] memory cmd = new string; cmd[0] = "forge"; cmd[1] = "inspect"; cmd[2] = _facetName; cmd[3] = "methods"; bytes memory res = vm.ffi(cmd); string memory st = string(res);

    // extract function signatures and take first 4 bytes of keccak
    strings.slice memory s = st.toSlice();

    // Skip TRACE lines if any
    strings.slice memory nl = '\n'.toSlice();
    strings.slice memory trace = 'TRACE'.toSlice();
    while (s.contains(trace) ) {
        s.split(nl);
    }

    strings.slice memory colon = ":".toSlice();
    strings.slice memory comma = ",".toSlice();
    strings.slice memory dbquote = '"'.toSlice();
    selectors = new bytes4[]((s.count(colon)));

    for(uint i = 0; i < selectors.length; i++) {
        s.split(dbquote);   // advance to next doublequote
        // split at colon, extract string up to next doublequote for methodname
        strings.slice memory method = s.split(colon).until(dbquote);
        selectors[i] = bytes4(method.keccak());
        strings.slice memory selectr = s.split(comma).until(dbquote);     // advance s to the next comma
    }
    return selectors;
}

`

The results have not changed. The hanging bug still hangs and the OutOfGas error still happens too.
The RUST_LOG=forge added nothing useful in the TRACE.

jdbertron avatar Apr 13 '23 23:04 jdbertron

Can someone look at this please ? My pull request to the Diamond Foundry project has been merged. https://github.com/FydeTreasury/Diamond-Foundry/pull/6 The problem still persists.

jdbertron avatar Apr 28 '23 15:04 jdbertron

Could this be because the gas_limit number too large to fit in target type, since max value that can be used is 9_223_372_036_854_775_807 ?

sambacha avatar Mar 22 '24 23:03 sambacha

I cannot reproduce this with latest commit and running forge test --ffi @mattsse I think this one can be closed @jdbertron pls reopen if still an issue

grandizzy avatar Apr 25 '24 11:04 grandizzy