-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TieredStorage] Put commonly used test functions into test_utils.rs #35065
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -657,26 +657,21 @@ impl HotStorageWriter { | |
pub mod tests { | ||
use { | ||
super::*, | ||
crate::{ | ||
account_storage::meta::StoredMeta, | ||
tiered_storage::{ | ||
byte_block::ByteBlockWriter, | ||
file::TieredStorageFile, | ||
footer::{AccountBlockFormat, AccountMetaFormat, TieredStorageFooter, FOOTER_SIZE}, | ||
hot::{HotAccountMeta, HotStorageReader}, | ||
index::{AccountIndexWriterEntry, IndexBlockFormat, IndexOffset}, | ||
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta}, | ||
owners::{OwnersBlockFormat, OwnersTable}, | ||
}, | ||
crate::tiered_storage::{ | ||
byte_block::ByteBlockWriter, | ||
file::TieredStorageFile, | ||
footer::{AccountBlockFormat, AccountMetaFormat, TieredStorageFooter, FOOTER_SIZE}, | ||
hot::{HotAccountMeta, HotStorageReader}, | ||
index::{AccountIndexWriterEntry, IndexBlockFormat, IndexOffset}, | ||
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta}, | ||
owners::{OwnersBlockFormat, OwnersTable}, | ||
test_utils::{create_test_account, verify_test_account}, | ||
}, | ||
assert_matches::assert_matches, | ||
memoffset::offset_of, | ||
rand::{seq::SliceRandom, Rng}, | ||
solana_sdk::{ | ||
account::{Account, AccountSharedData, ReadableAccount}, | ||
hash::Hash, | ||
pubkey::Pubkey, | ||
slot_history::Slot, | ||
account::ReadableAccount, hash::Hash, pubkey::Pubkey, slot_history::Slot, | ||
stake_history::Epoch, | ||
}, | ||
tempfile::TempDir, | ||
|
@@ -1288,67 +1283,6 @@ pub mod tests { | |
assert_matches!(HotStorageWriter::new(&path), Err(_)); | ||
} | ||
|
||
/// Create a test account based on the specified seed. | ||
/// The created test account might have default rent_epoch | ||
/// and write_version. | ||
/// | ||
/// When the seed is zero, then a zero-lamport test account will be | ||
/// created. | ||
fn create_test_account(seed: u64) -> (StoredMeta, AccountSharedData) { | ||
let data_byte = seed as u8; | ||
let owner_byte = u8::MAX - data_byte; | ||
let account = Account { | ||
lamports: seed, | ||
data: std::iter::repeat(data_byte).take(seed as usize).collect(), | ||
// this will allow some test account sharing the same owner. | ||
owner: [owner_byte; 32].into(), | ||
executable: seed % 2 > 0, | ||
rent_epoch: if seed % 3 > 0 { | ||
seed | ||
} else { | ||
RENT_EXEMPT_RENT_EPOCH | ||
}, | ||
}; | ||
|
||
let stored_meta = StoredMeta { | ||
write_version_obsolete: u64::MAX, | ||
pubkey: Pubkey::new_unique(), | ||
data_len: seed, | ||
}; | ||
(stored_meta, AccountSharedData::from(account)) | ||
} | ||
|
||
fn verify_account( | ||
stored_meta: &StoredAccountMeta<'_>, | ||
account: Option<&impl ReadableAccount>, | ||
address: &Pubkey, | ||
account_hash: &AccountHash, | ||
) { | ||
let (lamports, owner, data, executable, account_hash) = account | ||
.map(|acc| { | ||
( | ||
acc.lamports(), | ||
acc.owner(), | ||
acc.data(), | ||
acc.executable(), | ||
// only persist rent_epoch for those rent-paying accounts | ||
Some(*account_hash), | ||
) | ||
}) | ||
.unwrap_or((0, &OWNER_NO_OWNER, &[], false, None)); | ||
|
||
assert_eq!(stored_meta.lamports(), lamports); | ||
assert_eq!(stored_meta.data().len(), data.len()); | ||
assert_eq!(stored_meta.data(), data); | ||
assert_eq!(stored_meta.executable(), executable); | ||
assert_eq!(stored_meta.owner(), owner); | ||
assert_eq!(stored_meta.pubkey(), address); | ||
assert_eq!( | ||
*stored_meta.hash(), | ||
account_hash.unwrap_or(AccountHash(Hash::default())) | ||
); | ||
} | ||
|
||
Comment on lines
-1291
to
-1351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two functions have been moved to test_utils.rs |
||
#[test] | ||
fn test_write_account_and_index_blocks() { | ||
let account_data_sizes = &[ | ||
|
@@ -1401,7 +1335,7 @@ pub mod tests { | |
.unwrap(); | ||
|
||
let (account, address, account_hash, _write_version) = storable_accounts.get(i); | ||
verify_account(&stored_meta, account, address, account_hash); | ||
verify_test_account(&stored_meta, account, address, account_hash); | ||
|
||
assert_eq!(i + 1, next.0 as usize); | ||
} | ||
|
@@ -1420,7 +1354,7 @@ pub mod tests { | |
|
||
let (account, address, account_hash, _write_version) = | ||
storable_accounts.get(stored_info.offset); | ||
verify_account(&stored_meta, account, address, account_hash); | ||
verify_test_account(&stored_meta, account, address, account_hash); | ||
} | ||
|
||
// verify get_accounts | ||
|
@@ -1429,7 +1363,7 @@ pub mod tests { | |
// first, we verify everything | ||
for (i, stored_meta) in accounts.iter().enumerate() { | ||
let (account, address, account_hash, _write_version) = storable_accounts.get(i); | ||
verify_account(stored_meta, account, address, account_hash); | ||
verify_test_account(stored_meta, account, address, account_hash); | ||
} | ||
|
||
// second, we verify various initial position | ||
|
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,76 @@ | ||
#![cfg(test)] | ||
//! Helper functions for TieredStorage tests | ||
brooksprumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use { | ||
crate::{ | ||
account_storage::meta::{StoredAccountMeta, StoredMeta}, | ||
accounts_hash::AccountHash, | ||
tiered_storage::owners::OWNER_NO_OWNER, | ||
}, | ||
solana_sdk::{ | ||
account::{Account, AccountSharedData, ReadableAccount}, | ||
hash::Hash, | ||
pubkey::Pubkey, | ||
rent_collector::RENT_EXEMPT_RENT_EPOCH, | ||
}, | ||
}; | ||
|
||
/// Create a test account based on the specified seed. | ||
/// The created test account might have default rent_epoch | ||
/// and write_version. | ||
/// | ||
/// When the seed is zero, then a zero-lamport test account will be | ||
/// created. | ||
pub(super) fn create_test_account(seed: u64) -> (StoredMeta, AccountSharedData) { | ||
let data_byte = seed as u8; | ||
let owner_byte = u8::MAX - data_byte; | ||
let account = Account { | ||
lamports: seed, | ||
data: std::iter::repeat(data_byte).take(seed as usize).collect(), | ||
// this will allow some test account sharing the same owner. | ||
owner: [owner_byte; 32].into(), | ||
executable: seed % 2 > 0, | ||
rent_epoch: if seed % 3 > 0 { | ||
seed | ||
} else { | ||
RENT_EXEMPT_RENT_EPOCH | ||
}, | ||
}; | ||
|
||
let stored_meta = StoredMeta { | ||
write_version_obsolete: u64::MAX, | ||
pubkey: Pubkey::new_unique(), | ||
data_len: seed, | ||
}; | ||
(stored_meta, AccountSharedData::from(account)) | ||
} | ||
|
||
pub(super) fn verify_test_account( | ||
stored_meta: &StoredAccountMeta<'_>, | ||
account: Option<&impl ReadableAccount>, | ||
address: &Pubkey, | ||
account_hash: &AccountHash, | ||
) { | ||
let (lamports, owner, data, executable, account_hash) = account | ||
.map(|acc| { | ||
( | ||
acc.lamports(), | ||
acc.owner(), | ||
acc.data(), | ||
acc.executable(), | ||
// only persist rent_epoch for those rent-paying accounts | ||
Some(*account_hash), | ||
) | ||
}) | ||
.unwrap_or((0, &OWNER_NO_OWNER, &[], false, None)); | ||
|
||
assert_eq!(stored_meta.lamports(), lamports); | ||
assert_eq!(stored_meta.data().len(), data.len()); | ||
assert_eq!(stored_meta.data(), data); | ||
assert_eq!(stored_meta.executable(), executable); | ||
assert_eq!(stored_meta.owner(), owner); | ||
assert_eq!(stored_meta.pubkey(), address); | ||
assert_eq!( | ||
*stored_meta.hash(), | ||
account_hash.unwrap_or(AccountHash(Hash::default())) | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two functions have been moved to test_utils.rs