I have a program as follows:
- Some state is initialized with a
start_time
- Another instruction can be executed on that state, but only if the clock sysvar has passed the given
start_time
In my tests (using solana_program_test
and the banks_client
) I've tried the following:
This solution loops forever:
loop {
let clock: Clock = banks_client.get_sysvar().await.unwrap();
if clock.unix_timestamp > data.start_time {
break;
}
std::thread::sleep(std::time::Duration::from_secs(1));
}
If I manually sleep for the required time, I get an error in the program that makes it seem as though the clock sysvar hasn't moved forward i.e:
std::thread::sleep(std::time::Duration::from_secs((data.start_time - clock.unix_timestamp) as u64));
Produces this:
[2022-07-18T14:17:20.530662358Z DEBUG solana_runtime::message_processor::stable_log] Program log: 5 seconds until vend starts...
[2022-07-18T14:17:20.531179736Z DEBUG solana_runtime::message_processor::stable_log] Program log: Vend hasn't started yet
This is where start time was initially set to clock.unix_timestamp + 5
.
My question is:
- Does the banks client move the clock forward? If so, when/how?
- Is it possible to write to the clock sysvar and change the time?
Thanks!