Skip to content

Conversation

@ryanofsky
Copy link
Contributor

Add more comprehensive unit tests for CCoinsViewCache. Right now it is hard to refactor caching code or fix bugs in the caching logic because you have to try to mentally enumerate all the different states the cache might be in to make sure a change doesn't cause unintended consequences. The new tests explicitly enumerate relevant cache states, documenting and verifying the behavior in each state, so it will be safer and easier to make changes to the caching code in the future.

Add more comprehensive unit tests for CCoinsViewCache. Right now it is hard to
refactor caching code or fix bugs in the caching logic because you have to try
to mentally enumerate all the different states the cache might be in to make
sure a change doesn't cause unintended consequences. The new tests explicitly
enumerate relevant cache states, documenting and verifying the behavior in each
state, so it will be safer and easier to make changes to the caching code in
the future.
@laanwj
Copy link
Member

laanwj commented Dec 14, 2016

utACK 03ffa4c, thanks for adding tests for this important system

@maflcko
Copy link
Member

maflcko commented Dec 14, 2016

Concept ACK 03ffa4c


void CheckModifyNewCoins(CAmount cache_value, CAmount modify_value, CAmount expected_value, char cache_flags, char expected_flags, bool coinbase)
{
SingleEntryCacheTest test(ABSENT, cache_value, cache_flags);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe loop over possibilities for base values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

BOOST_CHECK_EQUAL(result_flags, expected_flags);
}

BOOST_AUTO_TEST_CASE(ccoins_write)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe try a loop of these tests with Child Flags not DIRTY as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@morcos
Copy link
Contributor

morcos commented Dec 19, 2016

ACK (left a couple of comments to slightly increase test coverage)

@laanwj laanwj merged commit 07df40b into bitcoin:master Dec 21, 2016
laanwj added a commit that referenced this pull request Dec 21, 2016
07df40b [test] Add CCoinsViewCache Access/Modify/Write tests (Russell Yanofsky)
@paveljanik
Copy link
Contributor

@ryanofsky What about this warning?

test/coins_tests.cpp:432:19: warning: unused variable 'DIRTY_FLAGS' [-Wunused-const-variable]

Do you plan to use it or can it be removed?

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 27, 2016
@ryanofsky
Copy link
Contributor Author

I do have some debug code using it, which I might make a PR from later, but its better to remove for now since it's causing this warning. Created to #9435 to remove.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 27, 2016
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jan 2, 2017
Remove unused variable in test, fixing warning.

Pointed out by Pavel Janík <[email protected]> in
bitcoin#9308.
codablock pushed a commit to codablock/dash that referenced this pull request Oct 23, 2017
07df40b [test] Add CCoinsViewCache Access/Modify/Write tests (Russell Yanofsky)
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 4, 2019
random-zebra pushed a commit to random-zebra/PIVX that referenced this pull request Aug 9, 2020
random-zebra pushed a commit to random-zebra/PIVX that referenced this pull request Aug 10, 2020
random-zebra pushed a commit to random-zebra/PIVX that referenced this pull request Aug 12, 2020
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Aug 18, 2020
cdbb1a6 Remove unused variable in test, fixing warning. (Russell Yanofsky)
03031a5 Check FRESH validity in CCoinsViewCache::BatchWrite (Russell Yanofsky)
3fb3e03 Fix dangerous condition in ModifyNewCoins. (random-zebra)
228d6bc [test] Add CCoinsViewCache Access/Modify/Write tests (random-zebra)

Pull request description:

  Going on with the coins view cache update work (started with #1774 and #1777).
  This backports the following upstream PRs (adapting them with the assumption that duplicate coinbase transactions are not possible):

  - bitcoin#9308 - [test] Add CCoinsViewCache Access/Modify/Write tests
  - bitcoin#9107 - Safer modify new coins
  - bitcoin#9310 - Assert FRESH validity in CCoinsViewCache::BatchWrite
  - bitcoin#9435 - Removed unused variable in test, fixing warning.

  Note: Will rebase #1773 on top of this one (to change `ApplyTxInUndo` return value in the unit test too).

ACKs for top commit:
  furszy:
    pretty nice one, ACK cdbb1a6
  Fuzzbawls:
    ACK cdbb1a6

Tree-SHA512: 69c534da1083c3c4a535923e98da7750474c6698bb45e042778b539a27fab0455d78aaf670bed9485522f9d2ee25e4ad57fa7d35632523fe7376fe5f5febb1e5
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants