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

Commit

Permalink
Use assert_matches! for verifying TieredStorageResult.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhchiang-sol committed Dec 11, 2023
1 parent 001f8ff commit 041baf1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,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 @@ -362,20 +363,24 @@ pub mod tests {

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

#[test]
#[should_panic(expected = "OffsetOutOfBounds(34359738368, 34359738360)")]
fn test_max_hot_account_offset_out_of_bounds() {
HotAccountOffset::new(MAX_HOT_ACCOUNT_OFFSET + HOT_ACCOUNT_OFFSET_ALIGNMENT).unwrap();
assert_matches!(
HotAccountOffset::new(MAX_HOT_ACCOUNT_OFFSET + HOT_ACCOUNT_OFFSET_ALIGNMENT),
Err(TieredStorageError::OffsetOutOfBounds(_, _))
);
}

#[test]
#[should_panic(expected = "OffsetAlignmentError(7, 8)")]
fn test_max_hot_account_offset_alignment_error() {
HotAccountOffset::new(HOT_ACCOUNT_OFFSET_ALIGNMENT - 1).unwrap();
assert_matches!(
HotAccountOffset::new(HOT_ACCOUNT_OFFSET_ALIGNMENT - 1),
Err(TieredStorageError::OffsetAlignmentError(_, _))
);
}

#[test]
Expand Down

0 comments on commit 041baf1

Please sign in to comment.