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

(Feature request) Provide missing stack trace depth #343

Open
webthethird opened this issue Apr 24, 2024 · 2 comments
Open

(Feature request) Provide missing stack trace depth #343

webthethird opened this issue Apr 24, 2024 · 2 comments
Labels

Comments

@webthethird
Copy link

Component

Forge

Describe the feature you would like

I have noticed that the stack traces provided for failing tests only include top-level calls from my test contract, and are missing any external calls that occur while executing the top-level call, which normally are included when using vanilla foundry. For example, I have the following contracts and test:

contract A {
    function revertIfEven(uint256 number) public pure returns (uint256) {
        if (number % 2 == 0) {
            revert("Number is even");
        }
        return number;
    }
}

contract B {
    A public a;

    constructor(A _a) {
        a = _a;
    }

    function callRevertIfEven(uint256 number) public view returns (uint256) {
        return a.revertIfEven(number);
    }
}

contract C {
    B public b;

    constructor(B _b) {
        b = _b;
    }

    function isEven(uint256 number) public view returns (bool) {
        try b.callRevertIfEven(number) {
            return false;
        } catch Error(string memory) {
            return true;
        }
    }
}

contract ABCTest is Test {
    A public a;
    B public b;
    C public c;

    function setUp() public {
        a = new A();
        b = new B(a);
        c = new C(b);
    }

    function test_StackTraceDepth() public {
        // Call C.isEven, which calls B.callRevertIfEven, which calls A.revertIfEven
        c.isEven(2);
        // Force test to fail so we can see the stack trace
        assertTrue(false);
    }
}

When this test fails, we can observe the following stack trace (after replacing addresses with contract names):

Ran 1 test for test/ABC.t.sol:ABCTest
[FAIL. Reason: assertion failed] test_StackTraceDepth() (gas: 8097)
Traces:
  [8097] ABCTest::test_StackTraceDepth()
    ├─ [0] C::isEven(2) [staticcall]
    │   └─ ← true
    ├─ [0] VM::assertTrue(false) [staticcall]
    │   └─ ← assertion failed
    └─ ← assertion failed

But I would expect the stack trace to look like this:

Ran 1 test for test/ABC.t.sol:ABCTest
[FAIL. Reason: assertion failed] test_StackTraceDepth() (gas: 8097)
Traces:
  [8097] ABCTest::test_StackTraceDepth()
    ├─ [0] C::isEven(2) [staticcall]
    |   ├─ [0] B::callRevertIfEven(2) [staticcall]
    |   |   ├─ [0] A::revertIfEven(2) [staticcall]
    |   |   |   └─ ← revert
    |   |   └─ ← revert
    │   └─ ← true
    ├─ [0] VM::assertTrue(false) [staticcall]
    │   └─ ← assertion failed
    └─ ← assertion failed

Additional context

Minimal reproducible example:
https://github.com/webthethird/min-reproducible-missing-stack-trace-depth

@webthethird webthethird changed the title Provide missing stack trace depth (Feature request) Provide missing stack trace depth Apr 24, 2024
@dutterbutter
Copy link
Collaborator

Thank you very much for the feature request and even bigger thanks for the minimal reproducible example! We will definitely look into this!

@webthethird
Copy link
Author

@dutterbutter any idea when this might be implemented? It would really help me with debugging an odd issue I'm encountering in my tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants