Cyfrin / foundry-smart-contract-lottery-cu

47 stars 38 forks source link

Challenge: Test > unit > RaffleTest.t.sol > CheckUpKeep Functions #47

Closed Bharath-Anbazhagan closed 5 months ago

Bharath-Anbazhagan commented 5 months ago

Hey Patrick & Cyfrin TEAM!

First Of All - Thank You All, For The Courses & Support 💖 ( Especially For Equious, Who Helped Me To Do My First PR! )

Yes, This is my First Pull Request 🥳

About The Pull Request ⬇️

I have completed the 2 Challenges in the CheckUpKeep Test Functions in the Raffle Project.

// Challenge 1. testCheckUpkeepReturnsFalseIfEnoughTimeHasntPassed

    function testCheckUpkeepReturnsFalseIfEnoughTimeHasntPassed() public {
        // Arrange
        vm.prank(PLAYER);
        raffle.enterRaffle{value: raffleEntranceFee}();

        // Act
        (bool upkeepNeeded, ) = raffle.checkUpkeep("");

        // Assert
        assert(!upkeepNeeded);
    }

// Challenge 2. testCheckUpkeepReturnsTrueWhenParametersGood

    function testCheckUpkeepReturnsTrueWhenParametersGood() public {
        // Arrange
        vm.prank(PLAYER);
        raffle.enterRaffle{value: raffleEntranceFee}();
        vm.warp(block.timestamp + automationUpdateInterval + 1);
        vm.roll(block.number + 1);

        // Act
        (bool upkeepNeeded, ) = raffle.checkUpkeep("");

        // Assert
        assert(upkeepNeeded);
    }

Conclusion

I know that this PR will be closed as others can also try to do this! 💪