1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
pub use crate::stake_history::StakeHistory;
use crate::sysvar::Sysvar;
crate::declare_sysvar_id!("SysvarStakeHistory1111111111111111111111111", StakeHistory);
impl Sysvar for StakeHistory {
fn size_of() -> usize {
16392 }
}
#[cfg(test)]
mod tests {
use {super::*, crate::stake_history::*};
#[test]
fn test_size_of() {
let mut stake_history = StakeHistory::default();
for i in 0..MAX_ENTRIES as u64 {
stake_history.add(
i,
StakeHistoryEntry {
activating: i,
..StakeHistoryEntry::default()
},
);
}
assert_eq!(
bincode::serialized_size(&stake_history).unwrap() as usize,
StakeHistory::size_of()
);
}
#[test]
fn test_create_account() {
let mut stake_history = StakeHistory::default();
for i in 0..MAX_ENTRIES as u64 + 1 {
stake_history.add(
i,
StakeHistoryEntry {
activating: i,
..StakeHistoryEntry::default()
},
);
}
assert_eq!(stake_history.len(), MAX_ENTRIES);
assert_eq!(stake_history.iter().map(|entry| entry.0).min().unwrap(), 1);
assert_eq!(stake_history.get(0), None);
assert_eq!(
stake_history.get(1),
Some(&StakeHistoryEntry {
activating: 1,
..StakeHistoryEntry::default()
})
);
}
}