-
Notifications
You must be signed in to change notification settings - Fork 341
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
Use native assertions #503
Conversation
I haven't gotten to look at this closely yet, but regardless would like to get thoughts from @vdrg @gnkz @PaulRBerg since you maintain alternative assertion libs. In general what are your thoughts on these changes? Would it be a breaking change for you that's hard to support? |
I'm OK with these changes. It looks like it will continue to be possible to use Also, if this gets implemented, I will consider stopping the development on PRBTest. |
This PR looks great! No objections from me, answers to the your questions below:
The reason for these duplicates is so users can avoid unnecessary casts when a type is ambiguous. For example I searched on sourcegraph and found repos using these overloads. So we could add native cheats for these overloads to maintain backwards compatibility to mitigate this one (even though their names aren't the greatest)
Do we still respect the
I would keep them for now for backwards compatibility reasons, and then in forge v1:
We should also upstream
AFAIK these should not be needed, and we have the |
|
Hey! This looks great! Our |
for now we can be assertEqCall, so this isn't a blocker but ideally we figure out how to replace this as well |
When I drop this version of forge-std in the optimism monorepo, two tests fail, even though they pass on the latest master. To reproduce:
Both failing are failing on the |
@mds1 Interesting, it is probably happening because assertion cheatcodes previously operated only on stack (in cases of success) and now any assertion is performing a |
quick question: does the cheatcode set the storage of the vm contract? People may rely on this mechanism. |
@brockelmore we don't set the bool vm storage on assertion failure, if I got your question right. The new behavior for assertions is that they immediately revert on failure and I don't think that it makes sense to set that bool as any checks of it in Solidity code would be unreacheable However, we are still checking it on test execution level and third-party testing frameworks can still set it and force tests to fail |
So, the minimal repro for this safeMemory bug looks like this uint64 initPtr;
assembly {
initPtr := mload(0x40)
}
vm.expectSafeMemory(initPtr, initPtr + 0x20);
assertEq(true, true); This passes on current version of forge-std and fails on this PR version. I am not sure what is a best thing to do here. This can be mitigated by moving logic which needs to be checked for memory safety into some inner function and using |
Was just in the process of suggesting this, front-ran :) It is important that we preserve We know where the allocation begins definitively since we can introspect the current free memory pointer, whereas if it were in a separate context, we'd maybe assume that we started allocating at 0x80, but couldn't know for sure w/o manual inspection. To allow for more flexibility in memory safety tests, a function test_whatever() public {
// ... other logic ...
vm.expectSafeMemory(0x420, 0x42069);
// logic that's being checked.
vm.stopExpectSafeMemory();
// post-condition checks, etc. Before `stopExpectSafeMemory`, any memory allocations here are liable to throw.
} The implementation of this cheatcode should also be very straightforwards, just clear the |
@klkvr Two open questions before we can merge this:
I lean towards (iii) because I'd like to avoid (i), and my concern with (ii) is we might have other breaking changes soon as part of foundry-rs/foundry#3782 |
I am not sure if we should really treat I don't really want to go with (ii) as there is much more to do in terms of upstreaming stuff to native cheats, so IMO we should do either (i) or (iii)
I've just tried doing it with several repos I've had on my machine already, it seems to break https://github.com/a16z/erc4626-tests as they rely on explicit calls to I think if we decide to go with option (i) it makes sense to keep |
So a search of
So I do think you're right that there should be no other unexpected breaking changes and a v1.8.0 is ok. If we can go with (i) that is the easiest from a maintenance perspective, so we probably should add |
Yep, will return them and do some more testing to ensure that we don't break anything else |
@mds1 so I've tested it on all repos from foundry integration tests that are using forge-std and on several external repos and haven't noticed any regression. The only thing that a little bit concerns me is the result of experiment I did:
After that I got a warning from git: I am not sure exactly what causes this, probably some strange behavior related to submodules getting removed, I will look into this |
I've seen that before too, I think it's unrelated to this change and just wonky submodule / Since this worked on all repos, I think we should be good to merge and release as v1.8.0? Would like to get #505 in too for that if we can, pending comments from brock |
It's kind of a known issue https://git-scm.com/book/en/v2/Git-Tools-Submodules#Issues-with-Submodules, but yeah, I am still not sure what which gitmodule-related flag of git does exactly and considering that we already use several of them when dealing with submodules, we probably shoudln't try fixing it rn |
yep, I think it's ready to be merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
This reverts commit 21577a0.
Ref foundry-rs/foundry#6803 (comment)
Changes
DSTest
dependency and moves allassert*
functions toStdAssertions
assert*
functions inStdAssertions
with calls tovm.assert*
cheatcodesStdAssertions
Breaking changes
This PR is marked as a draft because in current version it introduces some breaking changes which I am not sure we want. I think it makes sense to discuss them here first and decide if we are ready to merge them.
DSTest
includes some additionalassert*
functions which duplicate logic of their alternatives. For exampleassertEq0(bytes, bytes)
equivalent toassertEq(bytes, bytes)
orassertEq32(bytes32,bytes32)
equivalent toassertEq(bytes32, bytes32)
. Do we want to keep those considering that we don't have native cheatcodes with such selectors or it makes sense to drop them now?DSTest
includes logic withfailed()
andfail()
methods. Currently I haven't included this logic toStdAssertions
because we are migrating to new assertions behavior when they revert immidiately. Removal of those should also not affect custom testing frameworks as they usually implementfailed()
method themselves on baseTest
contract. However, this will affect users or frameworks relying on explicit calls tofail()
method onforge-std
baseTest
contract. I am not sure if it is a common usecase and if it makes sense to keep it.log_*
events toStdAssertions
except forlog
andlog_named_bytes
which are needed forassertEqCall
assertions. Are we expecting those to be commonly used or all users should be usingconsole.log
calls at this point?DSTest
are not migrated too, not sure if they are used at all:hasHEVMContext
,logs_gas
,mayRevert
,testopts
,HEVM_ADDRESS
All changes are basically just something not being migrated from
DSTest
toStdAssertions
and fixing it is as simple as copy-pasting it. However, I am not sure if we really want to keep compatibility with some of legacy methods above.