mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-10 15:05:24 -05:00
storage: add unit tests for StorageRevertsIter (#11999)
This commit is contained in:
@@ -76,3 +76,105 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_storage_reverts_iter_empty() {
|
||||
// Create empty sample data for reverts and wiped entries.
|
||||
let reverts: Vec<(B256, RevertToSlot)> = vec![];
|
||||
let wiped: Vec<(B256, U256)> = vec![];
|
||||
|
||||
// Create the iterator with the empty data.
|
||||
let iter = StorageRevertsIter::new(reverts, wiped);
|
||||
|
||||
// Iterate and collect results into a vector for verification.
|
||||
let results: Vec<_> = iter.collect();
|
||||
|
||||
// Verify that the results are empty.
|
||||
assert_eq!(results, vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_storage_reverts_iter_reverts_only() {
|
||||
// Create sample data for only reverts.
|
||||
let reverts = vec![
|
||||
(B256::from_slice(&[4; 32]), RevertToSlot::Destroyed),
|
||||
(B256::from_slice(&[5; 32]), RevertToSlot::Some(U256::from(40))),
|
||||
];
|
||||
|
||||
// Create the iterator with only reverts and no wiped entries.
|
||||
let iter = StorageRevertsIter::new(reverts, vec![]);
|
||||
|
||||
// Iterate and collect results into a vector for verification.
|
||||
let results: Vec<_> = iter.collect();
|
||||
|
||||
// Verify the output order and values.
|
||||
assert_eq!(
|
||||
results,
|
||||
vec![
|
||||
(B256::from_slice(&[4; 32]), U256::ZERO), // Revert slot previous value
|
||||
(B256::from_slice(&[5; 32]), U256::from(40)), // Only revert present.
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_storage_reverts_iter_wiped_only() {
|
||||
// Create sample data for only wiped entries.
|
||||
let wiped = vec![
|
||||
(B256::from_slice(&[6; 32]), U256::from(50)),
|
||||
(B256::from_slice(&[7; 32]), U256::from(60)),
|
||||
];
|
||||
|
||||
// Create the iterator with only wiped entries and no reverts.
|
||||
let iter = StorageRevertsIter::new(vec![], wiped);
|
||||
|
||||
// Iterate and collect results into a vector for verification.
|
||||
let results: Vec<_> = iter.collect();
|
||||
|
||||
// Verify the output order and values.
|
||||
assert_eq!(
|
||||
results,
|
||||
vec![
|
||||
(B256::from_slice(&[6; 32]), U256::from(50)), // Only wiped present.
|
||||
(B256::from_slice(&[7; 32]), U256::from(60)), // Only wiped present.
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_storage_reverts_iter_interleaved() {
|
||||
// Create sample data for interleaved reverts and wiped entries.
|
||||
let reverts = vec![
|
||||
(B256::from_slice(&[8; 32]), RevertToSlot::Some(U256::from(70))),
|
||||
(B256::from_slice(&[9; 32]), RevertToSlot::Some(U256::from(80))),
|
||||
// Some higher key than wiped
|
||||
(B256::from_slice(&[15; 32]), RevertToSlot::Some(U256::from(90))),
|
||||
];
|
||||
|
||||
let wiped = vec![
|
||||
(B256::from_slice(&[8; 32]), U256::from(75)), // Same key as revert
|
||||
(B256::from_slice(&[10; 32]), U256::from(85)), // Wiped with new key
|
||||
];
|
||||
|
||||
// Create the iterator with the sample data.
|
||||
let iter = StorageRevertsIter::new(reverts, wiped);
|
||||
|
||||
// Iterate and collect results into a vector for verification.
|
||||
let results: Vec<_> = iter.collect();
|
||||
|
||||
// Verify the output order and values.
|
||||
assert_eq!(
|
||||
results,
|
||||
vec![
|
||||
(B256::from_slice(&[8; 32]), U256::from(70)), // Revert takes priority.
|
||||
(B256::from_slice(&[9; 32]), U256::from(80)), // Only revert present.
|
||||
(B256::from_slice(&[10; 32]), U256::from(85)), // Wiped entry.
|
||||
(B256::from_slice(&[15; 32]), U256::from(90)), // WGreater revert entry
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user