Cyfrin / foundry-smart-contract-lottery-cu

47 stars 42 forks source link

Test testFulfillRandomWordsPicksAWinnerResetsAndSendsMoney (BIG ONE) keeps failing #44

Closed acaignar closed 9 months ago

acaignar commented 9 months ago

Hi!

When I run the 'BIG ONE' test I get the following failing reason:

FAIL. Reason: cannot overwrite a prank until it is applied at least once

I double checked the code and it appears similar to Patrick's. Any idea what I am missing here?

My code below:

function testFulfillRandomWordsPicksAWinnerResetsAndSendsMoney()
        public
        raffleEnteredAndTimePassed
    {
        // Arrange
        uint256 additionalEntrants = 5;
        uint256 startingIndex = 1;
        for (
            uint256 i = startingIndex;
            i < startingIndex + additionalEntrants;
            i++
        ) {
            address playerX = address(uint160(i));
            hoax(playerX, STARTING_USER_BALANCE); // hoax = creates a player (prank) and give him money
            raffle.enterRaffle{value: entranceFee};
        }

        uint256 prize = entranceFee * (additionalEntrants + 1);

        vm.recordLogs();
        raffle.performUpkeep(""); // emit requestId
        Vm.Log[] memory entries = vm.getRecordedLogs();
        bytes32 requestId = entries[1].topics[1];

        uint256 previousTimeStamp = raffle.getLastTimeStamp();

        // pretend to te chainlink vrf to get random number & pick the winner
        VRFCoordinatorV2Mock(vrfCoordinator).fulfillRandomWords(
            uint256(requestId),
            address(raffle)
        );

        // Asserts
        //assert(uint256(raffle.getRaffleState()) == 0);
        //assert(raffle.getRecentWinner() != address(0));
        //assert(raffle.getLengthOfPlayers() == 0);
        //assert(previousTimeStamp < raffle.getLastTimeStamp());
        console.log(raffle.getRecentWinner().balance);
        console.log(prize);
        assert(
            raffle.getRecentWinner().balance ==
                STARTING_USER_BALANCE + prize - entranceFee
        );
PatrickAlphaC commented 9 months ago

Hmmm... It's working for me. Could you try to git clone the repo and run the test? LIkely you're missing something.

acaignar commented 9 months ago

Thanks Patrick! The rest of the tests are working well so I'll keep moving forward even with this one failing anyway. Thanks so much for all the great contents you are sharing here!! :)