smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
11.94k stars 2.89k forks source link

Leeson 9 - Timeout Error for doing Unit test(Raffle.test.js) #6149

Open kds93419 opened 9 months ago

kds93419 commented 9 months ago

Discussed in https://github.com/smartcontractkit/full-blockchain-solidity-course-js/discussions/6148

Originally posted by **kds93419** September 21, 2023 Plz help me... i'cant find my mistake. i'm willing to test it(it("picks a winner, resets the lottery, and sends money")) but make a error(timeout)... I've been struggling for several days. ![image](https://github.com/smartcontractkit/full-blockchain-solidity-course-js/assets/73619981/c908eee5-0455-4c34-95d2-65721e9fbc40) https://github.com/kds93419/FCC-Lottery.git here is my repo..thx
MariossoKN commented 9 months ago

So after adding a try catch to your test file I found that the problem is that the "performUpkeep" function returns a "Raffle_UpkeepNotNeeded(30000000000000000, 3, 0)" error.

error_upkeepNeeded

The error is caused by the: bool timePassed = ((block.timestamp - s_lastTimeStamp) > i_interval); check inside of the checkUpkeep function - the i_interval set inside of the cunstructor is greater then the actual timestamp - the timestamps set in constructor.

The only way I found to make this code work was to decrease the "keepersUpdateInterval" inside of the helper-hardhat file from 30 seconds to like 2-3 seconds. But I am not sure how is it possible that the code from Patrick works with 30 seconds without increasing the time with evm_increaseTime.