-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ mod test_initialize; | |
mod test_mev_commission; | ||
mod test_stake; | ||
mod test_vote_account; | ||
|
||
mod test_state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
se validator_history::constants::TVC_MULTIPLIER; | ||
Check failure on line 2 in tests/tests/validator_history/test_state.rs GitHub Actions / lint
|
||
use validator_history::state::CircBuf; | ||
use validator_history::ValidatorHistoryEntry; | ||
|
||
const MAX_ITEMS: usize = 512; | ||
#[test] | ||
fn test_normalized_epoch_credits_latest() { | ||
let mut circ_buf = CircBuf { | ||
idx: 4, | ||
is_empty: 0, | ||
padding: [0; 7], | ||
arr: [ValidatorHistoryEntry::default(); MAX_ITEMS], | ||
}; | ||
|
||
for i in 0..5 { | ||
circ_buf.arr[i] = ValidatorHistoryEntry { | ||
epoch_credits: 1000, | ||
epoch: i as u16, | ||
..ValidatorHistoryEntry::default() | ||
}; | ||
} | ||
|
||
// Test normalizing an epoch before tvc activation | ||
assert_eq!( | ||
circ_buf.epoch_credits_latest_normalized(3, 4), | ||
Some(1000 * TVC_MULTIPLIER) | ||
); | ||
|
||
// Test normalizing an epoch after tvc activation | ||
assert_eq!(circ_buf.epoch_credits_latest_normalized(3, 3), Some(1000)); | ||
} | ||
|
||
#[test] | ||
fn test_epoch_credits_range_normalized() { | ||
let mut circ_buf = CircBuf { | ||
idx: 4, | ||
is_empty: 0, | ||
padding: [0; 7], | ||
arr: [ValidatorHistoryEntry::default(); MAX_ITEMS], | ||
}; | ||
|
||
for i in 0..5 { | ||
circ_buf.arr[i] = ValidatorHistoryEntry { | ||
epoch_credits: 1000, | ||
epoch: i as u16, | ||
..ValidatorHistoryEntry::default() | ||
}; | ||
} | ||
|
||
// Test normalizing epochs before tvc activation | ||
assert_eq!( | ||
circ_buf.epoch_credits_range_normalized(0, 4, 5), | ||
vec![ | ||
Some(1000 * TVC_MULTIPLIER), | ||
Some(1000 * TVC_MULTIPLIER), | ||
Some(1000 * TVC_MULTIPLIER), | ||
Some(1000 * TVC_MULTIPLIER), | ||
Some(1000 * TVC_MULTIPLIER) | ||
] | ||
); | ||
|
||
// Test normalizing epochs with tvc activation in middle of range | ||
assert_eq!( | ||
circ_buf.epoch_credits_range_normalized(0, 4, 2), | ||
vec![ | ||
Some(1000 * TVC_MULTIPLIER), | ||
Some(1000 * TVC_MULTIPLIER), | ||
Some(1000), | ||
Some(1000), | ||
Some(1000) | ||
] | ||
); | ||
} |