-
Notifications
You must be signed in to change notification settings - Fork 38.6k
[test] Add CCoinsViewCache Access/Modify/Write tests #9308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
ada92a8 to
03ffa4c
Compare
|
utACK 03ffa4c, thanks for adding tests for this important system |
|
Concept ACK 03ffa4c |
src/test/coins_tests.cpp
Outdated
|
|
||
| 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
|
ACK (left a couple of comments to slightly increase test coverage) |
03ffa4c to
07df40b
Compare
07df40b [test] Add CCoinsViewCache Access/Modify/Write tests (Russell Yanofsky)
|
@ryanofsky What about this warning? Do you plan to use it or can it be removed? |
Pointed out by Pavel Janík <[email protected]> in bitcoin#9308.
|
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. |
Pointed out by Pavel Janík <[email protected]> in bitcoin#9308.
Remove unused variable in test, fixing warning. Pointed out by Pavel Janík <[email protected]> in bitcoin#9308.
07df40b [test] Add CCoinsViewCache Access/Modify/Write tests (Russell Yanofsky)
Pointed out by Pavel Janík <[email protected]> in bitcoin#9308.
Pointed out by Pavel Janík <[email protected]> in bitcoin#9308.
Pointed out by Pavel Janík <[email protected]> in bitcoin#9308.
Pointed out by Pavel Janík <[email protected]> in bitcoin#9308.
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
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.