5

I need to change the block_timestamp to test timed voting.

Using VMContext, block_timestamp is changed using:

context.block_timestamp = get_timestamp();
testing_env!(context.clone());

How to do that in near_sdk_sim?

let (root, contract) = deploy_contract();
// Change the block_timestamp

Runtime has block_timestamp(), not sure how to use it.

Amiya Behera
  • 2,210
  • 19
  • 32

1 Answers1

0
// You should start with the master_account returned by init_simulator
// You can change the genesis config by giving 
//   near_sdk_sim::runtime::GenesisConfig to init_simulator instead of None
// FYI, the default value of block timestamp was 0 with None
let master_account = init_simulator(None);

// If you don't wrap this code block below in brackets
//   or don't call it as a function from outside,
//   you will encounter the error 'already borrowed: BorrowMutError'.
{
  let mut runtime = master_account.borrow_runtime_mut();
  // In near_sdk_sim, 1 block takes 1 second !
  // So it changes the block timestamp 0 to 10000000000
  runtime.produce_blocks(10u64);
}