Closed
Description
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 forks
The code that we currently use looks like this (below) but it marks the skipped tests as passed [PASS]
uint256 BSC_MAINNET = 56;
uint256 ETH_KOVAN = 42;
uint256 ETH_RINKEBY = 4;
uint256 EVMOS_TESTNET = 9000;
/// custom modifier for running tests conditionally
modifier shouldRun(bool run) {
if (run) {
_;
}
}
// filter function for a specific chain
function forChains(uint256 id0) public view returns (bool) {
return block.chainid == id0;
}
// filter function for multiple chains
function forChains(uint256 id0, uint256 id1) public view returns (bool) {
return block.chainid == id0 || block.chainid == id1;
}
// TEST CASES
function testSomething() public {
// this test will be run on all chains
}
function testSomethingElse() public shouldRun(forChains(BSC, ETH_KOVAN)) {
// this test will be skipped on EVMOS_TESTNET and ETH_RINKEBY
}
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 way
modifier shouldRun(bool run) {
if (run) {
_;
}
else {
assembly {
some_op_code_to_mark_test_as_skipped()
}
}
}
Additional context
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done