use blvm_node::utils::time::{current_timestamp, current_timestamp_duration};
#[test]
fn test_current_timestamp() {
let timestamp1 = current_timestamp();
let timestamp2 = current_timestamp();
assert!(timestamp1 > 0);
assert!(timestamp2 > 0);
assert!(timestamp2 >= timestamp1);
}
#[test]
fn test_current_timestamp_duration() {
let duration1 = current_timestamp_duration();
let duration2 = current_timestamp_duration();
assert!(duration1.as_secs() > 0);
assert!(duration2.as_secs() > 0);
assert!(duration2 >= duration1);
}
#[test]
fn test_current_timestamp_consistency() {
let timestamp = current_timestamp();
let duration = current_timestamp_duration();
let diff = (timestamp as i64) - (duration.as_secs() as i64);
assert!(diff.abs() <= 1);
}
#[test]
fn test_current_timestamp_monotonic() {
let timestamps: Vec<u64> = (0..10).map(|_| current_timestamp()).collect();
for i in 1..timestamps.len() {
if timestamps[i] < timestamps[i - 1] {
assert!(
timestamps[i - 1] - timestamps[i] < 10,
"Large timestamp decrease detected"
);
}
}
}
#[test]
fn test_current_timestamp_reasonable() {
let timestamp = current_timestamp();
let min_timestamp = 946_684_800; let max_timestamp = 4_102_444_800;
assert!(timestamp >= min_timestamp, "Timestamp too old: {timestamp}");
assert!(
timestamp <= max_timestamp,
"Timestamp too far in future: {timestamp}"
);
}