You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Probably a noob question but I'm trying to understand and learn.
Following Cyfrin's course on Foundry I'm left with only one branch to test in Raffle.sol
Uncovered for src/Raffle.sol:
- Branch (branch: 3, path: 0) (location: source ID 44, line 124, chars 5107-5163, hits: 0)
- Line (location: source ID 44, line 125, chars 5121-5152, hits: 0)
- Statement (location: source ID 44, line 125, chars 5121-5152, hits: 0)
which leads me to this conditional:
(boolsuccess,) = recentWinner.call{value: address(this).balance}("");
if (!success) {
revertRaffle__TransferFailed();
}
Is there a way to check if Raffle__TransferFailed is indeed the error triggered?
this is what I tried so far
contractRevertOnReceive {
receive() externalpayable {
revert("Forced failure");
}
}
function testFulfillRandomWordsTransferFailureBranch() public skipFork {
// Arrange
RevertOnReceive player =newRevertOnReceive();
hoax(address(player), 1 ether);
raffle.enterRaffle{value: 1ether}();
vm.warp(block.timestamp+ interval +1);
vm.roll(block.number+1);
// Perform upkeep to emit a requestId
vm.recordLogs();
raffle.performUpkeep("");
Vm.Log[] memory entries = vm.getRecordedLogs();
bytes32 requestId = entries[1].topics[1];
vm.expectRevert(Raffle__TransferFailed.selector);
// ActVRFCoordinatorV2_5Mock(vrfCoordinator).fulfillRandomWords(uint256(requestId), address(raffle));
// Assert: The player's balance should remain unchangedassertEq(address(player).balance, 0 ether);
}
To me it looks strange that after the Raffle__TransferFailed() reverts, RandomWordsFullfilled gets emitted. Is this happening because
fullfillRandomWords is actually called by the VRFCoordinator so when reverting the execution is given back to it hence not reverting as expected? Is there a way to test that branch?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Probably a noob question but I'm trying to understand and learn.
Following Cyfrin's course on Foundry I'm left with only one branch to test in Raffle.sol
which leads me to this conditional:
Is there a way to check if Raffle__TransferFailed is indeed the error triggered?
this is what I tried so far
this fails:
If I don't expectRevert it obviously pass and shows that indeed the error reverts and that the player balance did not change.
To me it looks strange that after the Raffle__TransferFailed() reverts, RandomWordsFullfilled gets emitted. Is this happening because
fullfillRandomWords is actually called by the VRFCoordinator so when reverting the execution is given back to it hence not reverting as expected? Is there a way to test that branch?
Beta Was this translation helpful? Give feedback.
All reactions