Skip to content

Commit

Permalink
[TieredStorage] Unit-tests for checking invalid HotAccountOffset (#34376
Browse files Browse the repository at this point in the history
)

#### Problem
HotAccountOffset::new() might return Err for invalid offset, and this
part needs some test coverage.

#### Summary of Changes
Add unit-tests for checking invalid HotAccountOffset.
  • Loading branch information
yhchiang-sol authored Dec 12, 2023
1 parent 549c3e7 commit 383aa04
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ pub mod tests {
index::{AccountIndexWriterEntry, IndexBlockFormat, IndexOffset},
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta},
},
assert_matches::assert_matches,
memoffset::offset_of,
rand::Rng,
solana_sdk::{hash::Hash, pubkey::Pubkey, stake_history::Epoch},
Expand Down Expand Up @@ -370,6 +371,28 @@ pub mod tests {
assert_eq!(meta.owner_offset(), MAX_HOT_OWNER_OFFSET);
}

#[test]
fn test_max_hot_account_offset() {
assert_matches!(HotAccountOffset::new(0), Ok(_));
assert_matches!(HotAccountOffset::new(MAX_HOT_ACCOUNT_OFFSET), Ok(_));
}

#[test]
fn test_max_hot_account_offset_out_of_bounds() {
assert_matches!(
HotAccountOffset::new(MAX_HOT_ACCOUNT_OFFSET + HOT_ACCOUNT_OFFSET_ALIGNMENT),
Err(TieredStorageError::OffsetOutOfBounds(_, _))
);
}

#[test]
fn test_max_hot_account_offset_alignment_error() {
assert_matches!(
HotAccountOffset::new(HOT_ACCOUNT_OFFSET_ALIGNMENT - 1),
Err(TieredStorageError::OffsetAlignmentError(_, _))
);
}

#[test]
#[should_panic(expected = "padding exceeds MAX_HOT_PADDING")]
fn test_hot_meta_padding_exceeds_limit() {
Expand Down

0 comments on commit 383aa04

Please sign in to comment.