Replies: 2 comments
-
|
Update, I was trying to use |
Beta Was this translation helpful? Give feedback.
-
|
The issue is that The core problem: The trick is to mock function testClockModeRevert() public {
// Mock clock() to return a value that differs from block.timestamp
// This causes the check inside CLOCK_MODE() to fail
vm.mockCall(
address(asset),
abi.encodeWithSignature("clock()"),
abi.encode(uint48(block.timestamp + 1))
);
vm.expectRevert(Votes.ERC6372InconsistentClock.selector);
asset.CLOCK_MODE();
}This works because:
Important note: // In your test file
contract BrokenClockHarness is YourToken {
bool public breakClock;
function setBreakClock(bool _break) external {
breakClock = _break;
}
function clock() public view override returns (uint48) {
if (breakClock) return uint48(block.timestamp + 1);
return super.clock();
}
}
// In your test
function testClockModeRevertWithHarness() public {
BrokenClockHarness harness = new BrokenClockHarness();
// ... initialize harness same as asset ...
harness.setBreakClock(true);
vm.expectRevert(Votes.ERC6372InconsistentClock.selector);
harness.CLOCK_MODE();
}The harness approach is the most reliable because it guarantees the actual revert path executes inside the real |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Guys,
Does anyone have an idea how can I test revert from this function:
The problem is that mocking revert doesnt count as proper test and I still have missing branch in my coverage report...
Would much appreciate any tips/ideas how can I properly test this revert I believe that foundry somehow allows that but I just have no idea how... Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions