This is potentially related to Mocking the Clock sysvar in solana_program_test, but I didn't find a sufficient answer/discussion there.

I have a program instruction that contains logic such that instruction_b cannot be executed while the clock's current timestamp is less than the timestamp at instruction_a + some time.

How can I mock or fast-forward the clock's current timestamp such that I can test instruction_b?

e.g. I would like to write the following unit test:

1. execute instruction_a
2. fast-forward (1 day)
3. execute instruction_b
  • 1
    Does this answer your question? Control time anchor test
    – Kise
    Feb 20 at 1:03
  • @kise Not what I'm looking for. My example requires that the time be fast forwarded 1 day. It's not feasible to have a test run on a loop sleeping for a second until a day has passed. Feb 20 at 23:51
  • 1
    Looks like it's not possible for tests written in JS/TS, but you can do something in Rust:solana.stackexchange.com/a/3748/7356
    – Kise
    Feb 21 at 1:20
  • Thank you @Kise. It's unfortunate that the tooling is so immature, but good to know it can be done using Rust tests. Feb 21 at 5:34


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.