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

Test behaves unexpected when using via-ir=true (the Yul pipeline) #5238

Closed
2 tasks done
malteish opened this issue Jun 28, 2023 · 1 comment
Closed
2 tasks done

Test behaves unexpected when using via-ir=true (the Yul pipeline) #5238

malteish opened this issue Jun 28, 2023 · 1 comment
Labels
T-bug Type: bug

Comments

@malteish
Copy link

malteish commented Jun 28, 2023

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (e918c81 2023-06-27T00:04:31.801932823Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

Problem

    /**
     * Demonstrate that tests don't work as expected with Yul
     * This test should fail, and does fail when run with via-ir=false.
     * But it succeeds when compiled with via-ir=true.
     */
    function testYul() public {
        uint256 time = block.timestamp;
        assertTrue(time == 1, "time is not 1 at the beginning");
        console.log("stored time before: ", time);
        // Problem 1: this warp changes the contents of the "time" variable, even though it shouldn't
        vm.warp(2 hours);
        console.log("stored time after: ", time);

        // Problem 2: none of these assertions fail, even though at least one should
        assertTrue(time == 1, "time is not 1 after warp");
        assertTrue(time == 2 hours, "time is not 1 after warp");

        console.log("This line is executed even though it shouldn't be reachable");
    }
  1. time should always stay 1 in this test.
  2. The test should fail because of the conflicting assertions.

Both expectations hold when compiling with via-ir=false, but neither of them holds when compiling with via-ir=true.

How to reproduce

Find the demo repository and follow the README.

Additional info

I found this problem when compiling my existing tests with via-ir=true for the first time. Now I am unsure how to proceed. In my opinion, this minimal example suggests some bug in foundry. Please advise on how to proceed.
I have not found any related issues.

Praise

Foundry rocks!

@mds1
Copy link
Collaborator

mds1 commented Jun 28, 2023

Closing as a duplicate, more info and workarounds are found in this linked issue and the other issues that comment links to: #4934 (comment)

@mds1 mds1 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
No open projects
Archived in project
Development

No branches or pull requests

2 participants