accounts db/refactor accounts db test - add macro for accounts-db panic test (#786)
* add macro for accounts-db panic test convert double remove test for both account file provider * refactor to share accounts_db_test and accounts_db_panic_test macro * rebase --------- Co-authored-by: HaoranYi <haoran.yi@solana.com>
This commit is contained in:
parent
8edc6ccb5c
commit
283f433a3b
|
@ -9632,18 +9632,36 @@ pub mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
/// Helper macro to define accounts_db_test for both `AppendVec` and `HotStorage`.
|
||||
/// This macro supports creating both regular tests and tests that should panic.
|
||||
/// Usage:
|
||||
/// For regular test, use the following syntax.
|
||||
/// define_accounts_db_test!(TEST_NAME, |accounts_db| { TEST_BODY }); // regular test
|
||||
/// For test that should panic, use the following syntax.
|
||||
/// define_accounts_db_test!(TEST_NAME, panic = "PANIC_MSG", |accounts_db| { TEST_BODY });
|
||||
macro_rules! define_accounts_db_test {
|
||||
(@testfn $name:ident, $accounts_file_provider: ident, |$accounts_db:ident| $inner: tt) => {
|
||||
fn run_test($accounts_db: AccountsDb) {
|
||||
$inner
|
||||
}
|
||||
let accounts_db =
|
||||
AccountsDb::new_single_for_tests_with_provider($accounts_file_provider);
|
||||
run_test(accounts_db);
|
||||
|
||||
};
|
||||
($name:ident, |$accounts_db:ident| $inner: tt) => {
|
||||
#[test_case(AccountsFileProvider::AppendVec; "append_vec")]
|
||||
#[test_case(AccountsFileProvider::HotStorage; "hot_storage")]
|
||||
fn $name(accounts_file_provider: AccountsFileProvider) {
|
||||
fn run_test($accounts_db: AccountsDb) {
|
||||
$inner
|
||||
define_accounts_db_test!(@testfn $name, accounts_file_provider, |$accounts_db| $inner);
|
||||
}
|
||||
|
||||
let accounts_db =
|
||||
AccountsDb::new_single_for_tests_with_provider(accounts_file_provider);
|
||||
run_test(accounts_db);
|
||||
};
|
||||
($name:ident, panic = $panic_message:literal, |$accounts_db:ident| $inner: tt) => {
|
||||
#[test_case(AccountsFileProvider::AppendVec; "append_vec")]
|
||||
#[test_case(AccountsFileProvider::HotStorage; "hot_storage")]
|
||||
#[should_panic(expected = $panic_message)]
|
||||
fn $name(accounts_file_provider: AccountsFileProvider) {
|
||||
define_accounts_db_test!(@testfn $name, accounts_file_provider, |$accounts_db| $inner);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -12610,10 +12628,10 @@ pub mod tests {
|
|||
assert_eq!(1, db.get_snapshot_storages(slot..=slot + 1).0.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "double remove of account in slot: 0/store: 0!!")]
|
||||
fn test_storage_remove_account_double_remove() {
|
||||
let accounts = AccountsDb::new_single_for_tests();
|
||||
define_accounts_db_test!(
|
||||
test_storage_remove_account_double_remove,
|
||||
panic = "double remove of account in slot: 0/store: 0!!",
|
||||
|accounts| {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
|
||||
accounts.store_for_tests(0, &[(&pubkey, &account)]);
|
||||
|
@ -12622,6 +12640,7 @@ pub mod tests {
|
|||
storage_entry.remove_accounts(0, true, 1);
|
||||
storage_entry.remove_accounts(0, true, 1);
|
||||
}
|
||||
);
|
||||
|
||||
fn do_full_clean_refcount(store1_first: bool, store_size: u64) {
|
||||
let pubkey1 = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
|
||||
|
|
Loading…
Reference in New Issue