Skip to content

Commit

Permalink
Adds verify_accounts_hash_and_lamports_for_tests() (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored May 6, 2024
1 parent 87b8d33 commit f46e3ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 16 additions & 7 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9446,6 +9446,15 @@ impl AccountsDb {
0
}
}

pub fn verify_accounts_hash_and_lamports_for_tests(
&self,
slot: Slot,
total_lamports: u64,
config: VerifyAccountsHashAndLamportsConfig,
) -> Result<(), AccountsHashVerificationError> {
self.verify_accounts_hash_and_lamports(slot, total_lamports, None, config)
}
}

// These functions/fields are only usable from a dev context (i.e. tests and benches)
Expand Down Expand Up @@ -12349,14 +12358,14 @@ pub mod tests {
);

assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 1, None, config.clone()),
db.verify_accounts_hash_and_lamports_for_tests(some_slot, 1, config.clone()),
Ok(_)
);

db.accounts_hashes.lock().unwrap().remove(&some_slot);

assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 1, None, config.clone()),
db.verify_accounts_hash_and_lamports_for_tests(some_slot, 1, config.clone()),
Err(AccountsHashVerificationError::MissingAccountsHash)
);

Expand All @@ -12366,7 +12375,7 @@ pub mod tests {
);

assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 1, None, config),
db.verify_accounts_hash_and_lamports_for_tests(some_slot, 1, config),
Err(AccountsHashVerificationError::MismatchedAccountsHash)
);
}
Expand Down Expand Up @@ -12414,12 +12423,12 @@ pub mod tests {
db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true);

assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 2, None, config.clone()),
db.verify_accounts_hash_and_lamports_for_tests(some_slot, 2, config.clone()),
Ok(_)
);

assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 10, None, config),
db.verify_accounts_hash_and_lamports_for_tests(some_slot, 10, config),
Err(AccountsHashVerificationError::MismatchedTotalLamports(expected, actual)) if expected == 2 && actual == 10
);
}
Expand All @@ -12445,7 +12454,7 @@ pub mod tests {
);

assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 0, None, config),
db.verify_accounts_hash_and_lamports_for_tests(some_slot, 0, config),
Ok(_)
);
}
Expand Down Expand Up @@ -12483,7 +12492,7 @@ pub mod tests {
);

assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 1, None, config),
db.verify_accounts_hash_and_lamports_for_tests(some_slot, 1, config),
Err(AccountsHashVerificationError::MismatchedAccountsHash)
);
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ mod serde_snapshot_tests {
);

accounts
.verify_accounts_hash_and_lamports(4, 1222, None, config)
.verify_accounts_hash_and_lamports_for_tests(4, 1222, config)
.unwrap();
}

Expand Down Expand Up @@ -834,12 +834,12 @@ mod serde_snapshot_tests {

accounts.update_accounts_hash_for_tests(current_slot, &no_ancestors, false, false);
accounts
.verify_accounts_hash_and_lamports(current_slot, 22300, None, config.clone())
.verify_accounts_hash_and_lamports_for_tests(current_slot, 22300, config.clone())
.unwrap();

let accounts = reconstruct_accounts_db_via_serialization(&accounts, current_slot);
accounts
.verify_accounts_hash_and_lamports(current_slot, 22300, None, config)
.verify_accounts_hash_and_lamports_for_tests(current_slot, 22300, config)
.unwrap();

// repeating should be no-op
Expand Down

0 comments on commit f46e3ca

Please sign in to comment.