Produce_blocks doesn't affect transaction's timestamp

A piece of code like this maintains the same timestamp between the two contract calls. How can I change the timestamp for a contract call?

  let provider = wallet.get_provider().unwrap();
  assert_eq!(provider.latest_block_height().await.unwrap(), 0);

  let timestamp = get_timestamp(provider).await.unwrap();

  let time = TimeParameters {
    start_time: Utc.timestamp_opt(timestamp, 0).unwrap(),
    block_time_interval: Duration::seconds(5),
  };

  provider.produce_blocks(1, Some(time)).await.unwrap();

  // First contract call

  let time = TimeParameters {
    start_time: Utc.timestamp_opt(timestamp + 5, 0).unwrap(),
    block_time_interval: Duration::seconds(1),
  };

  provider.produce_blocks(1, Some(time)).await.unwrap();

  // Second contract call
2 Likes

What does get_timestamp(provider) do? I am trying to fetch current timestamp but failing.

Also what are your imports?

use fuels::{
  signers::fuel_crypto::SecretKey,
  prelude::*,
  types::{
    Identity,
    block::Block
  },
  client::{
    PaginationRequest,
    PageDirection
  },
};
use chrono::{Utc, Duration, TimeZone};

pub async fn get_timestamp(provider: &Provider) -> Result<i64, Error> {
  let req = PaginationRequest {
    cursor: None,
    results: 1,
    direction: PageDirection::Backward,
  };
  let blocks: Vec<Block> = provider.get_blocks(req).await?.results;

  Ok(blocks[0].header.time.unwrap().timestamp())
}

Also, to note, this post is somewhat similar to Allow to set message sender of a given call to a specified Identity - Rust SDK - Fuel Network & Sway Language

2 Likes