Skip to content

Test reverts with Assertion failed. when reverting to a fork snapshot, without any assertion #3792

New issue

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

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

Already on GitHub? # to your account

Closed
2 tasks done
Rubilmax opened this issue Nov 29, 2022 · 5 comments · Fixed by #5404
Closed
2 tasks done
Assignees
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test P-high Priority: high T-bug Type: bug

Comments

@Rubilmax
Copy link
Contributor

Rubilmax commented Nov 29, 2022

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 (15204ec 2022-11-29T00:07:45.954046141Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

Report

  • The following test case testWtf reverts with reason Assertion failed., whereas no assertion is explicitly performed within it
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity ^0.8.0;

import "@forge-std/Test.sol";

contract Config {
    address public test = 0xcBa28b38103307Ec8dA98377ffF9816C164f9AFa;
}

contract TestSetup is Config, Test {
    function testWtf() public {
        uint256 snapshotId = vm.snapshot();

        vm.prank(test);

        vm.revertTo(snapshotId);
    }
}
  • forge-std is at the latest commit: ea1c1f4022f6a7924887106caa64499317295493

Findings

It seems to be a very specific case, because the test passes as soon as:

  • the order of inheritance is swapped
  • the test address is moved to the TestSetup contract
  • the test address is address(1), address(2), ...
  • any of the line of the body of testWtf is commented out

The test fails even if a call is performed on behalf of the pranked address test, right after vm.prank

@Rubilmax Rubilmax added the T-bug Type: bug label Nov 29, 2022
@MerlinEgalite
Copy link

Nice bug ser

@mds1
Copy link
Collaborator

mds1 commented Nov 29, 2022

@mattsse, potentially related to #3055 (comment) and foundry-rs/forge-std#241?

@mattsse mattsse self-assigned this Dec 1, 2022
@mattsse
Copy link
Member

mattsse commented Dec 1, 2022

thanks, will fix next.

@rkrasiuk rkrasiuk added Cmd-forge-test Command: forge test C-forge Command: forge A-cheatcodes Area: cheatcodes labels Dec 5, 2022
@mds1 mds1 added the P-high Priority: high label Mar 10, 2023
@mds1
Copy link
Collaborator

mds1 commented Mar 10, 2023

@mattsse This still appears to be an issue—seems something is broken with the snapshot/revert functionality. Giving this high priority since it causes in erroneous test results which is bad 😅

@ZeroEkkusu
Copy link
Contributor

ZeroEkkusu commented Jun 29, 2023

Hi, @Evalir.

I've seen that you've been trying to solve this issue, so I wanted to clarify a few things, in case it helps you.

I haven't checked the codebase, but it seems that before reverting the state, the thirty first byte of the zeroth slot of the testing contract is checked for a non-zero value.

If that is really the case, I suggest you check the slot at the Keccak-256 hash of the word "failed" at the VM address first, to see if the value is one (and it will be).

That is because placing a contract with a state variable before DSTest in the inheritance chain causes the storage order to shift, meaning the _failed flag won't be the second state variable anymore, that is, its value won't be the byte being checked.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test P-high Priority: high T-bug Type: bug
Projects
None yet
6 participants