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

Wallet: wtx cached balances test coverage + getAvailableCredit problem fix. #1810

Merged
merged 7 commits into from
Sep 1, 2020

Conversation

furszy
Copy link

@furszy furszy commented Aug 17, 2020

Added test coverage for the CWalletTx balances cache structure to verify the correctness of CREDIT/ISMINE_SPENDABLE, DEBIT/ISMINE_SPENDABLE, AVAILABLE_CREDIT/ISMINE_SPENDABLE, and a 'fake' block creation flow to verify CWallet::GetUnconfirmedBalance. (Leaving for a future PR, the cold staking balance types coverage)
Plus, popped up an issue in CWalletTx::GetAvailableCredit that is solved too.

Issue description:
As is now, CWalletTx::GetAvailableCredit is caching the amount using the AmountType::CREDIT when need to be using AmountType::AVAILABLE_CREDIT.
As them are different type of balances and are using the same cache position, only one of those is stored and the other one returns, invalidly, the value of the first one cached.

I intentionally have committed the unit test before the fix. So it can be tested easier with and without the fix. Placing the repo's head at 7f45afd, the wallet_tests.cpp will fail due this issue. Then can move to the next one (or directly to the last one) and it will successfully pass.

Essentially adding unit test coverage for the CWalletTx cached balances structure and fake block creation flow to expand the unit test coverage of the wallet in the future.
 Plus, popping up an issue in `CWalletTx::GetAvailableCredit`.

Issue description:
As is now, `CWalletTx::GetAvailableCredit` is using the AmountType::CREDIT cached storage when should be using AmountType::AVAILABLE_CREDIT.
So, as them are different type of balances and are using the same storage position, only one of those is stored and the other one returns, invalidly, the value of the first one cached.
@furszy furszy force-pushed the 2020_cached_balances_unit_test branch from 3973167 to d7813f8 Compare August 21, 2020 14:43
@furszy furszy requested review from random-zebra and Fuzzbawls and removed request for random-zebra August 25, 2020 01:35
src/wallet/wallet.h Outdated Show resolved Hide resolved
…en it should be stored in AVAILABLE_CREDIT position.
…the GetCredit/GetCacheableAmount methods (it was wrong there, causing issues between different balances amount types) and moved GetColdStakingCredit and GetStakeDelegationCredit to the proper GetAvailableCredit where them will be, correctly, cached in AVAILABLE_CREDIT position.
@furszy furszy force-pushed the 2020_cached_balances_unit_test branch from d7813f8 to ba2a5b0 Compare August 26, 2020 02:37
@furszy furszy requested a review from Fuzzbawls August 26, 2020 02:37
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

ACK cecb071

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

ACK cecb071

@furszy furszy merged commit 49bd999 into PIVX-Project:master Sep 1, 2020
@random-zebra random-zebra modified the milestones: 5.0.0, 4.3.0 Sep 10, 2020
@furszy furszy deleted the 2020_cached_balances_unit_test branch November 29, 2022 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants