Skip to content

Commit

Permalink
tests for new epoch credits methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Dec 3, 2024
1 parent 6e1630d commit efd0bcd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/tests/validator_history/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ mod test_initialize;
mod test_mev_commission;
mod test_stake;
mod test_vote_account;

mod test_state;
74 changes: 74 additions & 0 deletions tests/tests/validator_history/test_state.rs
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

View workflow job for this annotation

GitHub Actions / lint

expected one of `!` or `::`, found `validator_history`

Check failure on line 2 in tests/tests/validator_history/test_state.rs

View workflow job for this annotation

GitHub Actions / udeps

expected one of `!` or `::`, found `validator_history`
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)
]
);
}

0 comments on commit efd0bcd

Please sign in to comment.