Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 22d4c6a

Browse files
authored
Adds test for SortedStorages::new_with_slots() (#31471)
1 parent ed4cc52 commit 22d4c6a

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

runtime/src/sorted_storages.rs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'a> SortedStoragesIter<'a> {
191191
}
192192

193193
#[cfg(test)]
194-
pub mod tests {
194+
mod tests {
195195
use {
196196
super::*,
197197
crate::{
@@ -201,6 +201,7 @@ pub mod tests {
201201
},
202202
std::sync::Arc,
203203
};
204+
204205
impl<'a> SortedStorages<'a> {
205206
pub fn new_debug(
206207
source: &[(&'a Arc<AccountStorageEntry>, Slot)],
@@ -327,6 +328,81 @@ pub mod tests {
327328
);
328329
}
329330

331+
#[test]
332+
fn test_sorted_storages_new_with_slots() {
333+
let store = create_sample_store(1);
334+
let start = 33;
335+
let end = 44;
336+
337+
// ┌───────────────────────────────────────┐
338+
// │ ■ storages ■ │
339+
// └──────┃──────────────────────────┃─────┘
340+
// min┣ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┃max
341+
// ■ ■
342+
{
343+
let min = start + 1;
344+
let max = end - 1;
345+
let storages = SortedStorages::new_with_slots(
346+
[(&store, end), (&store, start)].iter().cloned(),
347+
Some(min),
348+
Some(max),
349+
);
350+
assert_eq!(storages.storages.len(), 2);
351+
assert_eq!(storages.range, start..end + 1);
352+
}
353+
354+
// ┌───────────────────────────────────────┐
355+
// │ storages ■ │ ■
356+
// └──────────────────────────────┃────────┘ ┃
357+
// min┣ ─ ─ ─ ─ ─ ─ ┫max
358+
// ■ ■
359+
{
360+
let min = start + 1;
361+
let max = end + 1;
362+
let storages = SortedStorages::new_with_slots(
363+
[(&store, end), (&store, start)].iter().cloned(),
364+
Some(min),
365+
Some(max),
366+
);
367+
assert_eq!(storages.storages.len(), 2);
368+
assert_eq!(storages.range, start..max + 1);
369+
}
370+
371+
// ┌───────────────────────────────────────┐
372+
// ■ │ ■ storages │
373+
// ┃ └─────┃─────────────────────────────────┘
374+
// min┣ ─ ─ ─ ─ ┫max
375+
// ■ ■
376+
{
377+
let min = start - 1;
378+
let max = end - 1;
379+
let storages = SortedStorages::new_with_slots(
380+
[(&store, end), (&store, start)].iter().cloned(),
381+
Some(min),
382+
Some(max),
383+
);
384+
assert_eq!(storages.storages.len(), 2);
385+
assert_eq!(storages.range, min..end + 1);
386+
}
387+
388+
// ┌───────────────────────────────────────┐
389+
// ■ │ storages │ ■
390+
// ┃ └───────────────────────────────────────┘ ┃
391+
// min┣ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┫max
392+
// ■ ■
393+
{
394+
let min = start - 1;
395+
let max = end + 1;
396+
let storages = SortedStorages::new_with_slots(
397+
[(&store, end), (&store, start)].iter().cloned(),
398+
Some(min),
399+
Some(max),
400+
);
401+
assert_eq!(storages.storages.len(), 2);
402+
assert_eq!(storages.range, min..max + 1);
403+
}
404+
}
405+
330406
#[test]
331407
#[should_panic(expected = "slots are not unique")]
332408
fn test_sorted_storages_duplicate_slots() {

0 commit comments

Comments
 (0)