Skip to content

Commit

Permalink
some test tweaks (solana-labs#882)
Browse files Browse the repository at this point in the history
* some test tweaks

* get rid of some redundancy
  • Loading branch information
jeffwashington authored Apr 18, 2024
1 parent fcabbd8 commit 994ab25
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
6 changes: 3 additions & 3 deletions accounts-db/src/account_storage/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ impl<'storage> StoredAccountMeta<'storage> {
}
}

pub fn data_len(&self) -> u64 {
pub fn data_len(&self) -> usize {
match self {
Self::AppendVec(av) => av.data_len(),
Self::Hot(hot) => hot.data().len() as u64,
Self::AppendVec(av) => av.data_len() as usize,
Self::Hot(hot) => hot.data().len(),
}
}

Expand Down
31 changes: 21 additions & 10 deletions accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ pub mod tests {
bytes: accounts
.stored_accounts
.iter()
.map(|account| aligned_stored_size(account.data().len()))
.map(|account| aligned_stored_size(account.data_len()))
.sum(),
slot,
})
Expand Down Expand Up @@ -1317,7 +1317,7 @@ pub mod tests {
bytes: accounts
.stored_accounts
.iter()
.map(|account| aligned_stored_size(account.data().len()))
.map(|account| aligned_stored_size(account.data_len()))
.sum(),
slot,
})
Expand Down Expand Up @@ -1364,7 +1364,7 @@ pub mod tests {
.iter()
.map(|(_slot, accounts)| accounts
.iter()
.map(|account| aligned_stored_size(account.data().len()) as u64)
.map(|account| aligned_stored_size(account.data_len()) as u64)
.sum::<u64>())
.sum::<u64>()
);
Expand Down Expand Up @@ -1665,8 +1665,9 @@ pub mod tests {
.stored_accounts
.first()
.unwrap();
let account_shared_data_with_2_refs = account_with_2_refs.to_account_shared_data();
let pk_with_2_refs = account_with_2_refs.pubkey();
let mut account_with_1_ref = account_with_2_refs.to_account_shared_data();
let mut account_with_1_ref = account_shared_data_with_2_refs.clone();
account_with_1_ref.checked_add_lamports(1).unwrap();
append_single_account_with_default_hash(
&storage,
Expand All @@ -1683,7 +1684,7 @@ pub mod tests {
append_single_account_with_default_hash(
&ignored_storage,
pk_with_2_refs,
&account_with_2_refs.to_account_shared_data(),
&account_shared_data_with_2_refs,
true,
Some(&db.accounts_index),
);
Expand Down Expand Up @@ -1731,6 +1732,11 @@ pub mod tests {
.alive_accounts
.one_ref
.accounts;
let one_ref_accounts_account_shared_data = one_ref_accounts
.iter()
.map(|account| account.to_account_shared_data())
.collect::<Vec<_>>();

assert_eq!(
one_ref_accounts
.iter()
Expand All @@ -1739,7 +1745,7 @@ pub mod tests {
vec![&pk_with_1_ref]
);
assert_eq!(
one_ref_accounts
one_ref_accounts_account_shared_data
.iter()
.map(|meta| meta.to_account_shared_data())
.collect::<Vec<_>>(),
Expand Down Expand Up @@ -1815,7 +1821,7 @@ pub mod tests {
.first()
.unwrap()
.to_account_shared_data(),
account_with_2_refs.to_account_shared_data()
account_shared_data_with_2_refs
);
}
}
Expand Down Expand Up @@ -1843,8 +1849,9 @@ pub mod tests {
.stored_accounts
.first()
.unwrap();
let account_shared_data_with_2_refs = account_with_2_refs.to_account_shared_data();
let pk_with_2_refs = account_with_2_refs.pubkey();
let mut account_with_1_ref = account_with_2_refs.to_account_shared_data();
let mut account_with_1_ref = account_shared_data_with_2_refs.clone();
_ = account_with_1_ref.checked_add_lamports(1);
append_single_account_with_default_hash(
&storage,
Expand Down Expand Up @@ -1906,6 +1913,10 @@ pub mod tests {
.alive_accounts
.one_ref
.accounts;
let one_ref_accounts_account_shared_data = one_ref_accounts
.iter()
.map(|account| account.to_account_shared_data())
.collect::<Vec<_>>();
assert_eq!(
one_ref_accounts
.iter()
Expand All @@ -1914,7 +1925,7 @@ pub mod tests {
vec![&pk_with_1_ref]
);
assert_eq!(
one_ref_accounts
one_ref_accounts_account_shared_data
.iter()
.map(|meta| meta.to_account_shared_data())
.collect::<Vec<_>>(),
Expand Down Expand Up @@ -1958,7 +1969,7 @@ pub mod tests {
.first()
.unwrap()
.to_account_shared_data(),
account_with_2_refs.to_account_shared_data()
account_shared_data_with_2_refs
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ pub mod tests {
// Reload accounts and observe crafted_data_len
let accounts = av.accounts(0);
let account = accounts.first().unwrap();
assert_eq!(account.data_len(), crafted_data_len);
assert_eq!(account.data_len() as u64, crafted_data_len);

av.flush().unwrap();
av.len()
Expand Down
3 changes: 0 additions & 3 deletions accounts-db/src/storable_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,6 @@ pub mod tests {

#[test]
fn test_storable_accounts_by_slot() {
solana_logger::setup();
// slots 0..4
// each one containing a subset of the overall # of entries (0..4)
for entries in 0..6 {
let data = Vec::default();
let hashes = (0..entries)
Expand Down

0 comments on commit 994ab25

Please sign in to comment.