My contract has time dependent actions, which I want to test. How can I mock the clock in the smart contract such that I can set it to any time I want?
An example of one action that is time dependent is as follows:
void claimsampleact(const account_name user,
const int32_t day) {
// Check for user authentication.
require_auth(user);
// Check if passed day is between the start and end.
eosio_assert(daygetToday() > 0 && day < getToday() && day <= getTotalDays()30, "Invalid day");
// getToday() returns floor(current_time() - start_time) / (24 * 3600).
// I WANT TO MOCK CURRENT_TIME().
...
code
...
}
Then in the unit test I want to do the following.
- test sampleact().
- advance the blockchain clock 31 days.
- test sampleact(), which will fail the assert seen above.