diff --git a/light-client/src/supervisor.rs b/light-client/src/supervisor.rs index 14a1358c1..0084464f0 100644 --- a/light-client/src/supervisor.rs +++ b/light-client/src/supervisor.rs @@ -585,7 +585,10 @@ mod tests { let peer_id = provider.unwrap_or("0BEFEEDC0C0ADEADBEBADFADADEFC0FFEEFACADE"); - let header = Header::new(&vals).height(1).chain_id(chain).time(1); + let header = Header::new(&vals) + .height(1) + .chain_id(chain) + .time(Time::from_unix_timestamp(1, 0).unwrap()); let commit = Commit::new(header.clone(), 1); let mut lb = TestgenLightBlock::new(header, commit).provider(peer_id); @@ -722,8 +725,7 @@ mod tests { .collect::>(); let mut header = chain.light_blocks[4].header.clone().unwrap(); - let mut time = header.time.unwrap(); - time += 3; + let time = (header.time.unwrap() + Duration::from_secs(3)).unwrap(); header.time = Some(time); chain.light_blocks[4].header = Some(header.clone()); chain.light_blocks[4].commit = Some(Commit::new(header, 1)); diff --git a/light-client/tests/backward.rs b/light-client/tests/backward.rs index e7b3bd324..c372ff4d7 100644 --- a/light-client/tests/backward.rs +++ b/light-client/tests/backward.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, time::Duration}; -use tendermint::{hash::Algorithm, Hash}; +use tendermint::{hash::Algorithm, Hash, Time}; use tendermint_light_client::{ components::{ @@ -156,7 +156,7 @@ fn corrupt_hash(mut tc: TestCase, mut rng: TestRng) -> TestCase { let block = tc.chain.block_mut(height).unwrap(); if let Some(header) = block.header.as_mut() { - header.time = Some(1610105021); + header.time = Some(Time::from_unix_timestamp(1610105021, 0).unwrap()); } tc diff --git a/testgen/Cargo.toml b/testgen/Cargo.toml index 5504b031b..64795152f 100644 --- a/testgen/Cargo.toml +++ b/testgen/Cargo.toml @@ -16,7 +16,7 @@ description = """ """ [dependencies] -tendermint = { version = "0.23.0", path = "../tendermint" } +tendermint = { version = "0.23.0", path = "../tendermint", features = ["clock"] } serde = { version = "1", default-features = false, features = ["derive"] } serde_json = { version = "1", default-features = false, features = ["std"] } ed25519-consensus = { version = "1.2", default-features = false } diff --git a/testgen/src/commit.rs b/testgen/src/commit.rs index a0cd86a50..ba1f428f3 100644 --- a/testgen/src/commit.rs +++ b/testgen/src/commit.rs @@ -169,6 +169,7 @@ impl Generator for Commit { #[cfg(test)] mod tests { use super::*; + use tendermint::Time; #[test] fn test_commit() { @@ -186,7 +187,7 @@ mod tests { let header = Header::new(&valset1) .next_validators(&valset2) .height(10) - .time(11); + .time(Time::from_unix_timestamp(11, 0).unwrap()); let commit = Commit::new(header.clone(), 3); diff --git a/testgen/src/header.rs b/testgen/src/header.rs index 0891fea58..2233b86b3 100644 --- a/testgen/src/header.rs +++ b/testgen/src/header.rs @@ -1,6 +1,8 @@ use crate::{helpers::*, validator::generate_validators, Generator, Validator}; +use core::time::Duration; use gumdrop::Options; use serde::{Deserialize, Serialize}; +use serde::{Deserializer, Serializer}; use simple_error::*; use std::convert::{TryFrom, TryInto}; use std::str::FromStr; @@ -24,13 +26,41 @@ pub struct Header { #[options(help = "block height (default: 1)")] pub height: Option, #[options(help = "time (default: now)")] - pub time: Option, + #[serde(deserialize_with = "deserialize_time")] + #[serde(serialize_with = "serialize_time")] + pub time: Option