During my Anchor tests, I need to simulate certain time change for my Solana program to react differently, such that the time_now below in my Solana program should change:
use solana_program::sysvar::clock::Clock;
let time_now = Clock::get().unwrap().unix_timestamp;
can I do that?
This may not pertain to Anchor, but on the Rust side, it's possible to advance time forward using the program-test
crate, creating your program test using start_with_context()
, and then using warp_to_slot()
.
Here's a simple example of advancing the clock on a program: https://github.com/solana-labs/solana/blob/c550b32a4489debb163cf6e6d170e934b0b4faaf/program-test/tests/warp.rs#L54