test_verify_bank_capitalization works with write cache (#29107)

This commit is contained in:
Jeff Washington (jwash) 2022-12-06 12:24:43 -06:00 committed by GitHub
parent 7ed22f7b18
commit 7180345ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 48 deletions

View File

@ -12948,58 +12948,64 @@ pub mod tests {
#[test]
fn test_verify_bank_capitalization() {
use BankHashVerificationError::*;
solana_logger::setup();
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
for pass in 0..2 {
use BankHashVerificationError::*;
solana_logger::setup();
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = solana_sdk::pubkey::new_rand();
let some_data_len = 0;
let some_slot: Slot = 0;
let account = AccountSharedData::new(1, some_data_len, &key);
let ancestors = vec![(some_slot, 0)].into_iter().collect();
let key = solana_sdk::pubkey::new_rand();
let some_data_len = 0;
let some_slot: Slot = 0;
let account = AccountSharedData::new(1, some_data_len, &key);
let ancestors = vec![(some_slot, 0)].into_iter().collect();
db.store_for_tests(some_slot, &[(&key, &account)]);
db.add_root(some_slot);
db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true);
assert_matches!(
db.verify_bank_hash_and_lamports(
db.store_for_tests(some_slot, &[(&key, &account)]);
if pass == 0 {
db.add_root_and_flush_write_cache(some_slot);
db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true);
assert_matches!(
db.verify_bank_hash_and_lamports(
some_slot,
&ancestors,
1,
true,
&EpochSchedule::default(),
&RentCollector::default(),
false,
),
Ok(_)
);
continue;
}
let native_account_pubkey = solana_sdk::pubkey::new_rand();
db.store_for_tests(
some_slot,
&ancestors,
1,
true,
&EpochSchedule::default(),
&RentCollector::default(),
false,
),
Ok(_)
);
&[(
&native_account_pubkey,
&solana_sdk::native_loader::create_loadable_account_for_test("foo"),
)],
);
db.add_root_and_flush_write_cache(some_slot);
db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true);
assert_matches!(
db.verify_bank_hash_and_lamports(
some_slot,
&ancestors,
2,
true,
&EpochSchedule::default(),
&RentCollector::default(),
false,
),
Ok(_)
);
let native_account_pubkey = solana_sdk::pubkey::new_rand();
db.store_for_tests(
some_slot,
&[(
&native_account_pubkey,
&solana_sdk::native_loader::create_loadable_account_for_test("foo"),
)],
);
db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true);
assert_matches!(
db.verify_bank_hash_and_lamports(
some_slot,
&ancestors,
2,
true,
&EpochSchedule::default(),
&RentCollector::default(),
false,
),
Ok(_)
);
assert_matches!(
db.verify_bank_hash_and_lamports(some_slot, &ancestors, 10, true, &EpochSchedule::default(), &RentCollector::default(), false,),
Err(MismatchedTotalLamports(expected, actual)) if expected == 2 && actual == 10
);
assert_matches!(
db.verify_bank_hash_and_lamports(some_slot, &ancestors, 10, true, &EpochSchedule::default(), &RentCollector::default(), false,),
Err(MismatchedTotalLamports(expected, actual)) if expected == 2 && actual == 10
);
}
}
#[test]