Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Add tests for store_account_and_update_capitalization#14008

Merged
ryoqun merged 1 commit intosolana-labs:masterfrom
ryoqun:store-and-update-caps-tests
Dec 8, 2020
Merged

Add tests for store_account_and_update_capitalization#14008
ryoqun merged 1 commit intosolana-labs:masterfrom
ryoqun:store-and-update-caps-tests

Conversation

@ryoqun
Copy link
Copy Markdown
Contributor

@ryoqun ryoqun commented Dec 8, 2020

Problem

#13884 is too big. Let's split it.

Summary of Changes

Extracted pretty simple test additions and minor implementation modifications.

@ryoqun ryoqun added the v1.4 label Dec 8, 2020
Comment thread runtime/src/bank.rs

#[cfg(test)]
fn add_account_and_update_capitalization(&self, pubkey: &Pubkey, new_account: &Account) {
fn store_account_and_update_capitalization(&self, pubkey: &Pubkey, new_account: &Account) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I renamed this to sound like a cousin to store_account. Introducing different verb add_ was a bad idea...

Comment thread runtime/src/bank.rs
}

#[test]
fn test_store_account_and_update_capitalization_missing() {
Copy link
Copy Markdown
Contributor Author

@ryoqun ryoqun Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classical textbookish non-overlapping exhaustive shortly-chucked set of unit tests for store_account_and_update_capitalization, which will be newly promoted from cfg(test) at #13884 .

Comment thread runtime/src/bank.rs
assert_capitalization_diff(
&bank,
|| bank.store_account_and_update_capitalization(&pubkey, &account),
|old, new| assert_eq!(old + 100, new),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivia: Q: why do I this manual math hard code like this instead of old + (new_lamports - old_lamports) sometimes? Isn't a bad practice?

A: Well this is partly art of coding but these well nuanced hard coded math can catch really silly test failure. Say, I assigned same value to both old_lamports and new_lamports in a huste of refactoring by accident, then, old + (new_lamports - old_lamports) wouldn't detect that this test got broken meaning actually noting (including intended branch coverage in store_account_and_update_capitalization) is tested.

Also, note that these silly things could happen in the refactoring of cfg(not(test)) code.

@ryoqun ryoqun requested a review from CriesofCarrots December 8, 2020 07:39
@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Dec 8, 2020

@CriesofCarrots Could you review this at your convenient time?

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 8, 2020

Codecov Report

Merging #14008 (93b37a9) into master (1dc71fb) will decrease coverage by 0.0%.
The diff coverage is 95.6%.

@@            Coverage Diff            @@
##           master   #14008     +/-   ##
=========================================
- Coverage    82.1%    82.1%   -0.1%     
=========================================
  Files         381      381             
  Lines       93727    93793     +66     
=========================================
+ Hits        76975    77024     +49     
- Misses      16752    16769     +17     

@ryoqun ryoqun merged commit 28b014c into solana-labs:master Dec 8, 2020
mergify Bot pushed a commit that referenced this pull request Dec 8, 2020
mergify Bot added a commit that referenced this pull request Dec 8, 2020
(cherry picked from commit 28b014c)

Co-authored-by: Ryo Onodera <ryoqun@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants