-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Function Modifier or an Opcode to mark a test as skipped conditionally #1123
Comments
Note on implementation: This could be a cheatcode ( Others could then implement their custom modifiers, and modifier shouldRun(bool pred) {
vm.skip(!pred);
_;
}
// Or
modifier shouldRunForChains(uint256 id0, uint256 id1) public view returns (bool) {
vm.skip(block.chainid != id0 && block.chainid != id1);
_;
} The bulk of the work is not the cheatcode itself, but adjusting all of the test-related code to move away from Marked it as low priority since it can already be solved using custom solutions, even if the outcome is not 100% desireable |
|
I wonder if this is needed anymore since we now have fork-related cheatcodes to choose what fork to use on a per-test level? Wdyt @vminkov? I can't really think of a use case beyond that. |
I still think this feature is useful in some cases. For example with hardhat, I'd sometimes scaffold out a bunch of unimplemented tests and mark them as skipped to signal that they're not implemented. Having them pass/fail didn't feel correct since it might be a while until all tests are implemented. Instead of a cheatcode, another idea is a special test name prefix, like I don't feel too strongly about this feature and am ok marking this closed, pending @vminkov's thoughts |
For our use case the fork-related cheatcodes are good enough alternative. It is still useful to mark a test case as skipped when the reasons for its failure are not related to the code that is tested, but to the fork RPC URL being invalid, for example. |
I think this would be the best fix here, since we identify tests via naming convention, simply adding |
I thought the OP wanted to skip tests on certain conditions like the chain id, which the |
Probably should have left this comment in this issue instead, so linking to it here #2606 (comment)
|
I've got another use case for this feature, which I originally described in #3845, and that now I'm moving here. When coding a test harness for live contracts, it is not possible to know in advance the state the the smart contracts will be in. Therefore, some tests will make sense, and others will not. For example, we might have a set of tests that make sense on a given uninitialized contract, but once the contract is initialized it would make more sense to skip those tests and move on to the next ones in the same file. The workaround described above still works, but the PASS in the output might still lead to confusion as to what is the current state of my contracts. I would very much prefer if the test would show as SKIP, and maybe even in the summary at the end ("67 passed, 32 skipped, 0 failed", for example). Additional context |
Component
Forge
Describe the feature you would like
It would be nice to have a Forge provided modifier that lets one mark a test as skipped
[SKIP]
depending on some custom condition. The specific use case we need it for is to mark which tests are run on different mainnet forksThe code that we currently use looks like this (below) but it marks the skipped tests as passed
[PASS]
I would imagine that we're provided by the forge env either a modifier like
shouldRun(forChains(...))
or some assembly opcode to return from the test marking it as skipped[SKIP]
and then we can craft the modifier in the same wayAdditional context
The text was updated successfully, but these errors were encountered: