Issue with testPerformUpkeepRevertsIfCheckUpkeepIsFalse()
dannweeeee opened this issue · comments
Dann Wee commented
Patrick Collins commented
Can you:
- Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
- Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be
Euisin Gee commented
@dannweeeee @PatrickAlphaC
The raffle contract gets deployed to address '0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496'.
and there is 0.04 ETH (40000000000000000 wei) on that address. See this etherscan
That's why that test function fails.
So you'll need to add below to the constructor function.
uint256 balance = address(this).balance;
if (balance > 0) {
payable(msg.sender).transfer(balance);
}
You can fix the test function without fixing the constructor function, as shown below, but it's not recommended.
function testPerformUpkeepRevertsIfCheckUpkeepIsFalse() public {
// Arrange
uint256 currentBalance = address(raffle).balance;
uint256 numPlayers = 0;
uint256 raffleState = 0;
// Act / Assert
vm.expectRevert(
abi.encodeWithSelector(
Raffle.Raffle__UpkeepNotNeeded.selector,
currentBalance,
numPlayers,
raffleState
)
);
raffle.performUpkeep("");
}