2

Hey so instead of resorting to warp_to_slot function of the program test crate ,utilizing the set_account function i quickly cooked something along the lines of this Problem am facing is although when i retrieve the timestamp via by getting the clock and reading the updated value, problem is inside my programs i access the time via the sysvar cluster that is Clock::get()? which does not seem to get affected even after changing the time directly as shown, what am i doing wrong here ?

async fn set_exact_time (context : &mut ProgramTestContext, add_time : i64) {
    let mut clock_account = get_clock(&mut context.banks_client).await;
    let time_before = clock_account.unix_timestamp;
   
    clock_account.unix_timestamp += add_time;
    let new_data = bincode::serialize(&clock_account).unwrap();
    let mut acc_info = context.banks_client.get_account(solana_program::sysvar::clock::id()).await.unwrap().unwrap();
    acc_info.data = new_data;
    let acc_shared_data = AccountSharedData::from(acc_info);
    context.set_account(&solana_sdk::sysvar::clock::id(), &acc_shared_data);
    let  clock_account = get_clock(&mut context.banks_client).await.unix_timestamp;
    println!("time now isss {clock_account},time before was {time_before}");
    
    // let acc_shared_clock = AccountSharedData::from(clock_account);


}

1 Answer 1

2

I was using the wrong function for this, the correct function to update sysvar data is , set_sysvar not set_account.

1
  • haha will do , ty for the reminder. Commented Aug 3, 2022 at 0:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.