2023-04-16 04:31:54 +00:00
|
|
|
use std::time::{Duration, SystemTime};
|
|
|
|
|
|
|
|
use tokio::time::sleep;
|
|
|
|
|
|
|
|
use serai_client::Serai;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
serai_test!(
|
2023-10-23 04:33:38 +00:00
|
|
|
time: (|serai: Serai| async move {
|
2023-10-14 06:47:58 +00:00
|
|
|
let mut number = serai.latest_block().await.unwrap().number();
|
2023-04-16 04:31:54 +00:00
|
|
|
let mut done = 0;
|
|
|
|
while done < 3 {
|
|
|
|
// Wait for the next block
|
2023-10-14 06:47:58 +00:00
|
|
|
let block = serai.latest_block().await.unwrap();
|
2023-04-16 04:31:54 +00:00
|
|
|
if block.number() == number {
|
|
|
|
sleep(Duration::from_secs(1)).await;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
number = block.number();
|
|
|
|
|
|
|
|
// Make sure the time we extract from the block is within 5 seconds of now
|
|
|
|
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
|
|
|
|
assert!(now.saturating_sub(block.time().unwrap()) < 5);
|
|
|
|
done += 1;
|
|
|
|
}
|
2023-10-23 04:33:38 +00:00
|
|
|
})
|
2023-04-16 04:31:54 +00:00
|
|
|
);
|