Skip to content
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

test: clean and extend availablecoins_tests coverage #25789

Merged

Conversation

furszy
Copy link
Member

@furszy furszy commented Aug 5, 2022

Negative PR with extended test coverage :).

  1. Cleaned duplicated code and added coverage for the 'AvailableCoins' incremental result.

  2. The class AvailableCoinsTestingSetup inside availablecoins_tests.cpp is a plain copy
    of ListCoinsTestingSetup that is inside wallet_tests.cpp.

    So, deleted the file and moved the BasicOutputTypesTest test case to wallet_tests.cpp.

  3. Added arg to include/skip locked coins from the AvailableCoins result. This is needed for point (1) as otherwise the wallet will spend the coins that we recently created due its closeness to the recipient amount.
    Note: this last point comes from wallet: simplify ListCoins implementation #25659 where I'm using the same functionality to clean/speedup another flow as well.

@fanquake fanquake added the Wallet label Aug 5, 2022
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 6, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK theStack, aureleoules, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26756 (wallet: Replace GetBalance() logic with AvailableCoins() by w0xlt)
  • #25665 (refactor: Add util::Result failure values, multiple error and warning messages by ryanofsky)
  • #25659 (wallet: simplify ListCoins implementation by furszy)
  • #25273 (wallet: Pass through transaction locktime and preset input sequences and scripts to CreateTransaction by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@furszy
Copy link
Member Author

furszy commented Aug 18, 2022

rebased, conflicts solved.

Copy link
Member

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

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

ACK d799db5 - LGTM

src/wallet/test/wallet_tests.cpp Outdated Show resolved Hide resolved
@furszy furszy force-pushed the 2022_test_clean_redundant_availablecoins_test branch from d799db5 to 6ef8af2 Compare November 16, 2022 15:27
Copy link
Member

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

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

reACK 6ef8af2

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Concept ACK

One suggestion (feel free to ignore, as there is already an ACK): I think the changes in the second commit would be much easier to review if the deduplication refactors and the additional test coverage ("coverage for 'AvailableCoins' incremental result") are not mixed up and are split into two individual commits instead.

@furszy
Copy link
Member Author

furszy commented Dec 7, 2022

Thanks for the review!

One suggestion (feel free to ignore, as there is already an ACK): I think the changes in the second commit would be much easier to review if the deduplication refactors and the additional test coverage ("coverage for 'AvailableCoins' incremental result") are not mixed up and are split into two individual commits instead.

The "incremental result" coverage just means we are now checking that previous coins are still on the available coins vector too (before, we were merely checking that the new ones appear there). It was actually a good side-effect of the cleanup and code improvements.
I don't think that is something that worth to split-up (plus, it would probably mean more code into the first commit, not less).

@furszy furszy force-pushed the 2022_test_clean_redundant_availablecoins_test branch from 6ef8af2 to de541b1 Compare December 13, 2022 23:19
@furszy
Copy link
Member Author

furszy commented Dec 13, 2022

Updated per feedback.
Flipped the expected size checks. Small Diff

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Updated per feedback. Flipped the expected size checks. Small Diff

Thanks, that solved the issue. Running the test with filter.skip_locked set to true fails now as expected:

wallet/test/wallet_tests.cpp(636): error: in "wallet_tests/BasicOutputTypesTest": check size == available_coins.coins[type].size() has failed [2 != 0]

Just one organizational nit: seems like this latest change is unintentionally part of the last commit (which is supposed to be purely move-only) rather than in the second one?

Clean redundant code and add coverage for 'AvailableCoins' incremental result.
The class `AvailableCoinsTestingSetup` inside `availablecoins_tests.cpp` is a plain copy
of `ListCoinsTestingSetup` that is inside wallet_tests.cpp.
@furszy furszy force-pushed the 2022_test_clean_redundant_availablecoins_test branch from de541b1 to 9622fe6 Compare December 14, 2022 14:16
@furszy
Copy link
Member Author

furszy commented Dec 14, 2022

Just one organizational nit: seems like this latest change is unintentionally part of the last commit (which is supposed to be purely move-only) rather than in the second one?

Pushed, thanks.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

ACK 9622fe6

Verified that the commits deduplicate code in a nice way and increase test coverage at the same time. I don't have a strong opinion about the last commit, since I'm not sure if decreasing the number of compilation units is necessarily better (-> longer compilation time if only changes in BasicOutputTypesTest are made), and if we can be sure that AvailableCoinsTestingSetup will never differ from ListCoinsTestingSetup. Absolutely not a blocker, but would still be interesting to know what the original motivation was to put this test in an extra file with its own test setup and if it still applies (@josibake).

Copy link
Member

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

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

reACK 9622fe6, nice cleanup!

@achow101
Copy link
Member

achow101 commented Jan 3, 2023

ACK 9622fe6

@achow101 achow101 merged commit 65d7c31 into bitcoin:master Jan 3, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 4, 2023
@furszy furszy deleted the 2022_test_clean_redundant_availablecoins_test branch May 27, 2023 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants