Testing smart contract with time manipulation

I have a contract logic that executes only after a specific time (defined during contract deployment). The contract logic relies on checking the current time via witness (using Date javascript method).

Testing the contract, how do I manipulate the time logic so the current time given by the witness is fast forward to successfully test the logic?

3 Likes

You can use the following vitest utility Mocking | Guide | Vitest to test your logic, but you should never rely on checking the current time via witness (using Date javascript method) in a production smart contract. It can easily get hacked.

2 Likes