Adds test for SortedStorages::new_with_slots() (#31471)
This commit is contained in:
parent
ed4cc52250
commit
22d4c6abf2
|
@ -191,7 +191,7 @@ impl<'a> SortedStoragesIter<'a> {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
mod tests {
|
||||
use {
|
||||
super::*,
|
||||
crate::{
|
||||
|
@ -201,6 +201,7 @@ pub mod tests {
|
|||
},
|
||||
std::sync::Arc,
|
||||
};
|
||||
|
||||
impl<'a> SortedStorages<'a> {
|
||||
pub fn new_debug(
|
||||
source: &[(&'a Arc<AccountStorageEntry>, Slot)],
|
||||
|
@ -327,6 +328,81 @@ pub mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sorted_storages_new_with_slots() {
|
||||
let store = create_sample_store(1);
|
||||
let start = 33;
|
||||
let end = 44;
|
||||
|
||||
// ┌───────────────────────────────────────┐
|
||||
// │ ■ storages ■ │
|
||||
// └──────┃──────────────────────────┃─────┘
|
||||
// min┣ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┃max
|
||||
// ■ ■
|
||||
{
|
||||
let min = start + 1;
|
||||
let max = end - 1;
|
||||
let storages = SortedStorages::new_with_slots(
|
||||
[(&store, end), (&store, start)].iter().cloned(),
|
||||
Some(min),
|
||||
Some(max),
|
||||
);
|
||||
assert_eq!(storages.storages.len(), 2);
|
||||
assert_eq!(storages.range, start..end + 1);
|
||||
}
|
||||
|
||||
// ┌───────────────────────────────────────┐
|
||||
// │ storages ■ │ ■
|
||||
// └──────────────────────────────┃────────┘ ┃
|
||||
// min┣ ─ ─ ─ ─ ─ ─ ┫max
|
||||
// ■ ■
|
||||
{
|
||||
let min = start + 1;
|
||||
let max = end + 1;
|
||||
let storages = SortedStorages::new_with_slots(
|
||||
[(&store, end), (&store, start)].iter().cloned(),
|
||||
Some(min),
|
||||
Some(max),
|
||||
);
|
||||
assert_eq!(storages.storages.len(), 2);
|
||||
assert_eq!(storages.range, start..max + 1);
|
||||
}
|
||||
|
||||
// ┌───────────────────────────────────────┐
|
||||
// ■ │ ■ storages │
|
||||
// ┃ └─────┃─────────────────────────────────┘
|
||||
// min┣ ─ ─ ─ ─ ┫max
|
||||
// ■ ■
|
||||
{
|
||||
let min = start - 1;
|
||||
let max = end - 1;
|
||||
let storages = SortedStorages::new_with_slots(
|
||||
[(&store, end), (&store, start)].iter().cloned(),
|
||||
Some(min),
|
||||
Some(max),
|
||||
);
|
||||
assert_eq!(storages.storages.len(), 2);
|
||||
assert_eq!(storages.range, min..end + 1);
|
||||
}
|
||||
|
||||
// ┌───────────────────────────────────────┐
|
||||
// ■ │ storages │ ■
|
||||
// ┃ └───────────────────────────────────────┘ ┃
|
||||
// min┣ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┫max
|
||||
// ■ ■
|
||||
{
|
||||
let min = start - 1;
|
||||
let max = end + 1;
|
||||
let storages = SortedStorages::new_with_slots(
|
||||
[(&store, end), (&store, start)].iter().cloned(),
|
||||
Some(min),
|
||||
Some(max),
|
||||
);
|
||||
assert_eq!(storages.storages.len(), 2);
|
||||
assert_eq!(storages.range, min..max + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "slots are not unique")]
|
||||
fn test_sorted_storages_duplicate_slots() {
|
||||
|
|
Loading…
Reference in New Issue