Error with Lottery testDontAllowPlayersToEnterWhileRaffleIsCalculating
test
#3234
-
I followed everything in the test and i still double check with the completed version of the code and i still can't figure out what exactly is wrong and why my test is failing after 24 hours. You will find the complete logs below but this is the section that is failing. [73976] RaffleTest::testDontAllowPlayersToEnterWhileRaffleIsCalculating()
├─ [0] VM::prank(player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C])
│ └─ ← [Return]
├─ [47827] Raffle::enterRaffle{value: 10000000000000000}()
│ ├─ emit RaffelEntered(player: player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C])
│ └─ ← [Stop]
├─ [0] VM::warp(32)
│ └─ ← [Return]
├─ [0] VM::roll(2)
│ └─ ← [Return]
├─ [3516] Raffle::performUpkeep(0x)
│ └─ ← [Revert] Raffle__UpkeepNotNeeded(10000000000000000 [1e16], 1, 0)
└─ ← [Revert] Raffle__UpkeepNotNeeded(10000000000000000 [1e16], 1, 0)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 18.81ms (294.43µs CPU time)
Ran 1 test suite in 1.33s (18.81ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/unit/RaffleTest.t.sol:RaffleTest
[FAIL: Raffle__UpkeepNotNeeded(10000000000000000 [1e16], 1, 0)] testDontAllowPlayersToEnterWhileRaffleIsCalculating() (gas: 73976)
Encountered a total of 1 failing tests, 0 tests succeeded Complete Logs /D/T/Cyfrin_Updraft/lottery | on master +5 !4 ?7 forge test --mt testDontAllowPlayersToEnterWhileRaffleIsCalculating -vvvv
[⠊] Compiling...
No files changed, compilation skipped
Ran 1 test for test/unit/RaffleTest.t.sol:RaffleTest
[FAIL: Raffle__UpkeepNotNeeded(10000000000000000 [1e16], 1, 0)] testDontAllowPlayersToEnterWhileRaffleIsCalculating() (gas: 73976)
Logs:
⚠️ You have deployed a mock conract!
Make sure this was intentional
Creating new subscription...
Creating subscription on chainId: 31337
Your subscription Id is: 7570848181127581986339189052072122886913734678723205985508750752041200654908
Please update the subscriptionId in HelperConfig.s.sol
Funding subscription: 7570848181127581986339189052072122886913734678723205985508750752041200654908
Using vrfCoordinator: 0x34A1D3fff3958843C43aD80F30b94c510645C316
On ChainID: 31337
Deploying Raffle contract...
Adding consumer to the subscription...
Adding consumer contract: 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
Using vrfCoordinator: 0x34A1D3fff3958843C43aD80F30b94c510645C316
On ChainID: 31337
Traces:
[61350138] RaffleTest::setUp()
├─ [28472824] → new DeployRaffle@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 141928 bytes of code
├─ [32554034] DeployRaffle::run()
│ ├─ [4937771] → new HelperConfig@0x104fBc016F4bb334D775a19E8A6510109AC63E00
│ │ └─ ← [Return] 22766 bytes of code
│ ├─ [6203583] → new AddConsumer@0x037eDa3aDB1198021A9b2e88C22B464fD38db3f3
│ │ └─ ← [Return] 30869 bytes of code
│ ├─ [3865383] HelperConfig::getConfig()
│ │ ├─ [0] console::log("⚠\u{fe0f} You have deployed a mock conract!") [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] console::log("Make sure this was intentional") [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] VM::startBroadcast()
│ │ │ └─ ← [Return]
│ │ ├─ [2863541] → new VRFCoordinatorV2_5Mock@0x34A1D3fff3958843C43aD80F30b94c510645C316
│ │ │ ├─ emit ConfigSet()
│ │ │ └─ ← [Return] 13951 bytes of code
│ │ ├─ [785080] → new LinkToken@0x90193C961A926261B756D1E5bb255e67ff9498A1
│ │ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38], amount: 1000000000000000000000000 [1e24])
│ │ │ └─ ← [Return] 3461 bytes of code
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ ├─ [0] VM::deal(DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38], 100000000000000000000 [1e20])
│ │ │ └─ ← [Return]
│ │ └─ ← [Return] NetworkConfig({ subscriptionId: 0, gasLane: 0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c, automationUpdateInterval: 30, raffleEntranceFee: 10000000000000000 [1e16], callbackGasLimit: 500000 [5e5], vrfCoordinatorV2_5: 0x34A1D3fff3958843C43aD80F30b94c510645C316, link: 0x90193C961A926261B756D1E5bb255e67ff9498A1, account: 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38 })
│ ├─ [0] console::log("Creating new subscription...") [staticcall]
│ │ └─ ← [Stop]
│ ├─ [5221534] → new CreateSubscription@0xDDc10602782af652bB913f7bdE1fD82981Db7dd9
│ │ └─ ← [Return] 25966 bytes of code
│ ├─ [124770] CreateSubscription::createSubscription(VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316], DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ ├─ [0] console::log("Creating subscription on chainId: ", 31337 [3.133e4]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] VM::startBroadcast(DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ │ └─ ← [Return]
│ │ ├─ [120948] VRFCoordinatorV2_5Mock::createSubscription()
│ │ │ ├─ emit SubscriptionCreated(subId: 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], owner: DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ │ └─ ← [Return] 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75]
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ ├─ [0] console::log("Your subscription Id is: ", 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] console::log("Please update the subscriptionId in HelperConfig.s.sol") [staticcall]
│ │ │ └─ ← [Stop]
│ │ └─ ← [Return] 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316]
│ ├─ [10856151] → new FundSubscription@0x7FdB3132Ff7D02d8B9e221c61cC895ce9a4bb773
│ │ └─ ← [Return] 53760 bytes of code
│ ├─ [49231] FundSubscription::fundSubscription(VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316], 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], LinkToken: [0x90193C961A926261B756D1E5bb255e67ff9498A1], DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ ├─ [0] console::log("Funding subscription: ", 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] console::log("Using vrfCoordinator: ", VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] console::log("On ChainID: ", 31337 [3.133e4]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] VM::startBroadcast(DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ │ └─ ← [Return]
│ │ ├─ [45313] VRFCoordinatorV2_5Mock::fundSubscription(7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], 1000000000000000000 [1e18])
│ │ │ ├─ emit SubscriptionFunded(subId: 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], oldBalance: 0, newBalance: 1000000000000000000 [1e18])
│ │ │ └─ ← [Stop]
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ └─ ← [Stop]
│ ├─ [154049] HelperConfig::setConfig(31337 [3.133e4], NetworkConfig({ subscriptionId: 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], gasLane: 0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c, automationUpdateInterval: 30, raffleEntranceFee: 10000000000000000 [1e16], callbackGasLimit: 500000 [5e5], vrfCoordinatorV2_5: 0x34A1D3fff3958843C43aD80F30b94c510645C316, link: 0x90193C961A926261B756D1E5bb255e67ff9498A1, account: 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38 }))
│ │ └─ ← [Stop]
│ ├─ [0] VM::startBroadcast(DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ └─ ← [Return]
│ ├─ [0] console::log("Deploying Raffle contract...") [staticcall]
│ │ └─ ← [Stop]
│ ├─ [870938] → new Raffle@0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
│ │ └─ ← [Return] 4004 bytes of code
│ ├─ [0] VM::stopBroadcast()
│ │ └─ ← [Return]
│ ├─ [0] console::log("Adding consumer to the subscription...") [staticcall]
│ │ └─ ← [Stop]
│ ├─ [71175] AddConsumer::addConsumer(Raffle: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316], 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ ├─ [0] console::log("Adding consumer contract: ", Raffle: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] console::log("Using vrfCoordinator: ", VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] console::log("On ChainID: ", 31337 [3.133e4]) [staticcall]
│ │ │ └─ ← [Stop]
│ │ ├─ [0] VM::startBroadcast(DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ │ │ └─ ← [Return]
│ │ ├─ [67270] VRFCoordinatorV2_5Mock::addConsumer(7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], Raffle: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76])
│ │ │ ├─ emit SubscriptionConsumerAdded(subId: 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], consumer: Raffle: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76])
│ │ │ └─ ← [Stop]
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ └─ ← [Stop]
│ └─ ← [Return] Raffle: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], HelperConfig: [0x104fBc016F4bb334D775a19E8A6510109AC63E00]
├─ [0] VM::deal(player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C], 10000000000000000000 [1e19])
│ └─ ← [Return]
├─ [2305] HelperConfig::getConfig()
│ └─ ← [Return] NetworkConfig({ subscriptionId: 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], gasLane: 0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c, automationUpdateInterval: 30, raffleEntranceFee: 10000000000000000 [1e16], callbackGasLimit: 500000 [5e5], vrfCoordinatorV2_5: 0x34A1D3fff3958843C43aD80F30b94c510645C316, link: 0x90193C961A926261B756D1E5bb255e67ff9498A1, account: 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38 })
├─ [0] VM::startPrank(DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38])
│ └─ ← [Return]
├─ [2796] LinkToken::mint(DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38], 100000000000000000000 [1e20])
│ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38], amount: 100000000000000000000 [1e20])
│ └─ ← [Stop]
├─ [3513] VRFCoordinatorV2_5Mock::fundSubscription(7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], 100000000000000000000 [1e20])
│ ├─ emit SubscriptionFunded(subId: 7570848181127581986339189052072122886913734678723205985508750752041200654908 [7.57e75], oldBalance: 1000000000000000000 [1e18], newBalance: 101000000000000000000 [1.01e20])
│ └─ ← [Stop]
├─ [24546] LinkToken::approve(VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316], 100000000000000000000 [1e20])
│ ├─ emit Approval(owner: DefaultSender: [0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38], spender: VRFCoordinatorV2_5Mock: [0x34A1D3fff3958843C43aD80F30b94c510645C316], amount: 100000000000000000000 [1e20])
│ └─ ← [Return] true
├─ [0] VM::stopPrank()
│ └─ ← [Return]
└─ ← [Stop]
[73976] RaffleTest::testDontAllowPlayersToEnterWhileRaffleIsCalculating()
├─ [0] VM::prank(player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C])
│ └─ ← [Return]
├─ [47827] Raffle::enterRaffle{value: 10000000000000000}()
│ ├─ emit RaffelEntered(player: player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C])
│ └─ ← [Stop]
├─ [0] VM::warp(32)
│ └─ ← [Return]
├─ [0] VM::roll(2)
│ └─ ← [Return]
├─ [3516] Raffle::performUpkeep(0x)
│ └─ ← [Revert] Raffle__UpkeepNotNeeded(10000000000000000 [1e16], 1, 0)
└─ ← [Revert] Raffle__UpkeepNotNeeded(10000000000000000 [1e16], 1, 0)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 18.81ms (294.43µs CPU time)
Ran 1 test suite in 1.33s (18.81ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/unit/RaffleTest.t.sol:RaffleTest
[FAIL: Raffle__UpkeepNotNeeded(10000000000000000 [1e16], 1, 0)] testDontAllowPlayersToEnterWhileRaffleIsCalculating() (gas: 73976)
Encountered a total of 1 failing tests, 0 tests succeeded |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you look at the last two lines of your error logs, you will see that it is reverting due to function performUpkeep(bytes calldata /* performData */ ) external override {
// If all conditions are met to perform upkeep, execute this function
(bool upkeepNeeded,) = checkUpkeep("");
if (!upkeepNeeded) {
revert Raffle__UpkeepNotNeeded(address(this).balance, s_listOfPlayers.length, s_raffleState);
}
s_raffleState = RaffleState.CALCULATING; // Can also be RaffleState(1), when picking out the winner This means /**
* This is the function that the Chainlink nodes will call to see when and
* if the lottery is ready to have a winner picked. The following should be
* true in order for `upkeepNeeded` to be true:
* 1. The time interval (lottery duration) has passed between raffle runs
* 2. The lottery is open (RaffleState is OPEN)
* 3. The contract has non-zero ETH (check if players have entered raffle)
* 4. There are players registered in the raffle
* 5. Implicitly, the VRF Subscription is funded - has non-zero LINK or ETH
* @param - //checkData - ignored
* @return upkeepNeeded (bool) - true if it's time to restart the lottery
* By returning `bool upkeepNeeded`, the return variable is already
* initialized to `false` and we can use it within the function.
* @return - //performData - ignored
*/
function checkUpkeep(bytes memory /* checkData */ )
public
view
override
returns (bool upkeepNeeded, bytes memory /* performData */ )
{
bool timeHasPassed = ((block.timestamp - s_lastRecordedTimestamp) >= i_lotteryDurationSeconds);
bool isOpen = s_raffleState == RaffleState.OPEN;
bool raffleHasBalance = (address(this).balance > 0);
console.log("raffleHasBalance truthiness:", raffleHasBalance); <--- Put logs like this
bool raffleHasPlayers = (s_listOfPlayers.length > 0);
upkeepNeeded = (timeHasPassed && isOpen && raffleHasBalance && raffleHasPlayers);
return (upkeepNeeded, "0x0");
} You need to check that the four conditions are satisfied, and that your VRF subscription is funded, in order for |
Beta Was this translation helpful? Give feedback.
-
@ismaildawoodjee God bless you |
Beta Was this translation helpful? Give feedback.
If you look at the last two lines of your error logs, you will see that it is reverting due to
Raffle__UpkeepNotNeeded
error, which is within theperformUpkeep
function:This means
checkUpkeep
function is returningfalse
because the fou…