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

Restore fail with a message #583

Open
CodeSandwich opened this issue Jul 19, 2024 · 4 comments
Open

Restore fail with a message #583

CodeSandwich opened this issue Jul 19, 2024 · 4 comments

Comments

@CodeSandwich
Copy link

Back in forge-std v1.7 there was function fail in StdAssertions that accepted the error message. As of v1.9.1 it's gone, which breaks existing tests and requires rewriting using much less convenient assertTrue(false, "Reason to fail").

@mds1
Copy link
Collaborator

mds1 commented Jul 24, 2024

I believe fail() was removed as part of the move to native cheatcode assertions from the solidity assertions. You should also be able to fail a test with revert("Reason to fail") which should be similarly convenient. cc @klkvr for more info

There also is vm.skip(bool) to conditionally skip tests if that helps

@CodeSandwich
Copy link
Author

CodeSandwich commented Jul 24, 2024

I believe that you're referring to this change: 1432518#diff-d79529fa796b868bdba7d0be181244b6d3ee5d3ff0aecb1b5db2d47b78dfb05dL15-L17 and specifically this part of StdAssertion.sol:

-    function fail(string memory err) internal virtual {
-        emit log_named_string("Error", err);
-        fail();
-    }
+     function fail() internal virtual {
+        vm.store(address(vm), bytes32("failed"), bytes32(uint256(1)));
+        _failed = true;
+    }

fail() wasn't removed, it was moved from DSTest to StdAssertion and switched to the native cheatcodes. In the process the fail(err) variant was lost and IMO it could be restored to keep this useful tool around and improve backward compatibility. Previously it was logging err and calling DSTest's fail(), now it could log err and call StdAssertion's fail().

@mds1
Copy link
Collaborator

mds1 commented Aug 9, 2024

I see, that seems reasonable to me. What do you think @klkvr @mattsse?

@klkvr
Copy link
Member

klkvr commented Aug 10, 2024

I see, that seems reasonable to me. What do you think @klkvr @mattsse?

I think we can add vm.fail(string) cheatcode for consistency, I'd prefer to not add methods which are manually logging stuff through log_named_string and keep all formatting/outputting logic in cheatcode implementations

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

3 participants