test: CanonChainTracker implementation for BlockchainProvider2 (#10378)

This commit is contained in:
greged93
2024-08-22 05:18:00 -07:00
committed by GitHub
parent 82f10164db
commit a4c30ead7e

View File

@ -1487,7 +1487,7 @@ where
#[cfg(test)]
mod tests {
use std::{ops::Range, sync::Arc};
use std::{ops::Range, sync::Arc, time::Instant};
use itertools::Itertools;
use rand::Rng;
@ -2356,4 +2356,29 @@ mod tests {
Ok(())
}
#[test]
fn test_canon_state_tracker() -> eyre::Result<()> {
let mut rng = generators::rng();
let (provider, _, _, _) =
provider_with_random_blocks(&mut rng, TEST_BLOCKS_COUNT, TEST_BLOCKS_COUNT, None)?;
let before = Instant::now();
provider.on_forkchoice_update_received(&Default::default());
let last_update_ts = provider.last_received_update_timestamp().unwrap();
let after = Instant::now();
// Ensure the timestamp is updated and between the before and after timestamps
assert!(before < last_update_ts && last_update_ts < after);
let before = Instant::now();
provider.on_transition_configuration_exchanged();
let last_update_ts = provider.last_exchanged_transition_configuration_timestamp().unwrap();
let after = Instant::now();
// Ensure the timestamp is updated and between the before and after timestamps
assert!(before < last_update_ts && last_update_ts < after);
Ok(())
}
}