test(hardano): discover snapshots by inspecting test_data dir (#428)

This commit is contained in:
Santiago Carmuega 2024-04-02 09:18:53 -03:00 committed by GitHub
parent c31e773ce2
commit b6f537abba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 47 deletions

View file

@ -528,18 +528,8 @@ mod tests {
); );
} }
#[test] fn read_full_snapshot(path: &Path) {
#[ignore] let reader = super::read_blocks(&path).unwrap();
fn can_read_whole_mithril_snapshot() {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::DEBUG)
.finish(),
)
.unwrap();
let path = option_env!("PALLAS_MITHRIL_SNAPSHOT_PATH").unwrap();
let reader = super::read_blocks(Path::new(path)).unwrap();
let mut count = 0; let mut count = 0;
let mut last_slot = None; let mut last_slot = None;
@ -576,9 +566,12 @@ mod tests {
assert!(count > 0); assert!(count > 0);
} }
// This test will inspect the /test_data/full_snapshots dir in the repo hoping
// to find full mithril snapshots to process. Full snapshots are ignored in git
// for obvious reasons. Is up to the developer to download and extract snapshots
// into that folder. If no snapshots are available, this test will pass.
#[test] #[test]
#[ignore] fn read_available_full_snapshots() {
fn can_read_whole_mithril_snapshot_2() {
tracing::subscriber::set_global_default( tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder() tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::DEBUG) .with_max_level(tracing::Level::DEBUG)
@ -586,41 +579,15 @@ mod tests {
) )
.unwrap(); .unwrap();
let path = option_env!("PALLAS_MITHRIL_SNAPSHOT_PATH").unwrap(); let path = Path::new("../test_data/full_snapshots");
let reader = super::read_blocks_from_point(Path::new(path), Point::Origin).unwrap();
let mut count = 0; let dir = std::fs::read_dir(path).expect("can't access full_snapshots dir");
let mut last_slot = None; for snapshot in dir {
let mut last_height = None; let snapshot = snapshot.unwrap();
let mut last_hash = None; let immutable = snapshot.path().join("immutable");
if immutable.is_dir() {
for block in reader.take_while(Result::is_ok) { read_full_snapshot(&immutable);
let block = block.unwrap();
let block = MultiEraBlock::decode(&block).unwrap();
trace!("slot: {}, hash: {}", block.slot(), block.hash());
if let Some(last_slot) = last_slot {
assert!(last_slot < block.slot());
} }
if let Some(last_height) = last_height {
assert_eq!(last_height + 1, block.number());
}
if let Some(last_hash) = last_hash {
if let Some(expected) = block.header().previous_hash() {
assert_eq!(last_hash, expected)
}
}
last_slot = Some(block.slot());
last_height = Some(block.number());
last_hash = Some(block.hash());
count += 1;
} }
assert!(count > 0);
} }
} }

1
test_data/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
full_snapshots