Cyfrin / foundry-smart-contract-lottery-cu

48 stars 42 forks source link

test fails on testnet if wallet balance is not zero #46

Closed 0xpantera closed 6 months ago

0xpantera commented 7 months ago

The test testPerformUpkeepRevertsIfCheckUpkeepIsFalse which does not have the skipFork modifier will fail if the wallet balance on Sepolia is not zero.

function testPerformUpkeepRevertsIfCheckUpkeepIsFalse() public {
        uint256 currentBalance = 0;
        uint256 numPlayers = 0;
        uint256 raffleState = 0;

        vm.expectRevert(
            abi.encodeWithSelector(
                Raffle.Raffle__UpkeepNotNeeded.selector,
                currentBalance,
                numPlayers,
                raffleState
            )
        );

        raffle.performUpkeep("");
    }

If wallet balance on Sepolia is not zero test will fail because it will throw a different error than the expected one by vm.expectRevert():

Expected error:

Actual error:

Test fail reason:

PatrickAlphaC commented 7 months ago

Ah! So we should add this modifier. Good shout, any chance you'd be interested in making the PR?

0xpantera commented 7 months ago

Sorry, just saw this. I'd be happy to make the PR if it hasn't already been made.

PatrickAlphaC commented 6 months ago

Ah, I think this test is still correct.

revert Raffle__UpkeepNotNeeded(
                address(this).balance,
                s_players.length,
                uint256(s_raffleState)
            );

address(this).balance is referring to the balance of the contract, not the wallet.