Why we need to mine a block when we do this unit test? #5685
Replies: 2 comments
-
@software-dev2010 When you increase the time, you are only changing the time of the current block. However, the smart contract will not be aware of this change until the next block is mined. This is because the smart contract only sees the state of the blockchain at the time of the most recently mined block. By mining a block after increasing the time, you are ensuring that the smart contract will see the new time when it is next executed. This is necessary for the unit test to pass, because the unit test is expecting the smart contract to reject the entry when the raffle state is calculating. |
Beta Was this translation helpful? Give feedback.
-
@software-dev2010 It is the general real approach like the way blockchain works with the increase in time new blockchains get mined. But here for hardhat testing just increasing the time will be enough for testing purposes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm at the lesson 9 at the unit tests and there is this unit test:
I understand why we need to increase the time, because in the function
checkUpkeep
fromRaffle.sol
we need to have the valuetrue
for the fieldtimepassed
. But after that we mine a block. Can someone explain me why we do that? If I comment this line of code, the unit test also passes. Thank you!Beta Was this translation helpful? Give feedback.
All reactions