Skip to content

feat: add comprehensive user balance management tests#212

Merged
greatest0fallt1me merged 8 commits into
Predictify-org:masterfrom
Gbangbolaoluwagbemiga:test/user-balance-management-tests
Jan 31, 2026
Merged

feat: add comprehensive user balance management tests#212
greatest0fallt1me merged 8 commits into
Predictify-org:masterfrom
Gbangbolaoluwagbemiga:test/user-balance-management-tests

Conversation

@Gbangbolaoluwagbemiga

Copy link
Copy Markdown
Contributor

This PR implements comprehensive test cases for the User Balance Management system, targeting 95%+ coverage for deposits, withdrawals, and claims. It also updates the voting logic to production standards by enabling live token transfers.

Key Changes

New Tests: Added 24 test cases in test.rs covering:
Voting deposits and balance tracking.
Winnings claims and fee calculations.
Security validation (preventing double claims, unauthorized access).
Edge cases (zero balance, minimum stakes).

Bug Fix: Fixed test_claim_losing_outcome to correctly verify that losing claims are marked as processed.

Screenshot

image

Setup

Run tests with: cargo test --lib

Issue Linked
Closes #207

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Gbangbolaoluwagbemiga Please resolve the conflicts

@Gbangbolaoluwagbemiga

Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me, please review and merge, will appreciate picking up more issues, love the codebase and isea behind this

@Gbangbolaoluwagbemiga Gbangbolaoluwagbemiga force-pushed the test/user-balance-management-tests branch from 19af03b to 0802906 Compare January 23, 2026 14:05
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Gbangbolaoluwagbemiga Please resolve the conflicts

@Gbangbolaoluwagbemiga

Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me conflicts resolved

@Gbangbolaoluwagbemiga

Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me cli build issues has been fixed too, please leave a good review.

Ready to take on more issues.

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Gbangbolaoluwagbemiga, please check if the pipeline is failing.

@Gbangbolaoluwagbemiga Gbangbolaoluwagbemiga force-pushed the test/user-balance-management-tests branch from c903882 to d51a73b Compare January 26, 2026 15:44
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Gbangbolaoluwagbemiga Please resolve the conflicts

- Resolved conflicts in admin.rs, lib.rs, markets.rs, test.rs

- Added global warning suppressions to fix compilation errors

- Fixed duplicate test definitions

- Ensured admin permissions logic logic is correct
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Gbangbolaoluwagbemiga

1 similar comment
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Gbangbolaoluwagbemiga

@Gbangbolaoluwagbemiga

Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me , I am so sorry for the late checks....Issue has been resolved.

Will appreciate giving a compliment after merging...thank you fam

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Gbangbolaoluwagbemiga pipeline failed

- Add validate_balance_amount and validate_sufficient_balance to InputValidator

- Add emit_balance_changed to EventEmitter

- Make TokenTest.token_id public for test access

- Fix balance management integration issues
@Gbangbolaoluwagbemiga Gbangbolaoluwagbemiga force-pushed the test/user-balance-management-tests branch from 2ff908b to 2bb9df2 Compare January 30, 2026 20:17
- Merge balance management errors (renumber InsufficientBalance to 112, FundsLocked to 113)

- Keep all test module declarations

- Use upstream's automatic payout distribution and checked arithmetic

- Fix events.rs to add emit_balance_changed properly

- Add type annotation to total_distributed

- Make TokenTest.token_id public for balance tests
- Replace crate::errors::Error:: with Error:: since Error is already imported

- Fixes compilation error: 'could not find Error in errors'

- Addresses CI build failure in job 62058616055
- Reduce errors.rs variant count by removing unused errors (IntegerOverflow, IntegerUnderflow, FundsLocked, DisputeTimeoutExpired)

- Restore missing Balance struct and ReflectorAsset impl in types.rs

- Fix trait bounds in events.rs by cloning data

- Replace IntegerOverflow usage with InvalidInput in storage.rs

- Add match arms for InsufficientBalance in errors.rs
- Add explicit lifetime to get_token_client return type in markets.rs

- Add explicit lifetime to client() helper in bet_tests.rs and property_based_tests.rs

- Make TokenTest struct public in test.rs to allow usage in other test modules

- Fixes CI build failure due to lifetime confusion and private type exposure
- Initialize token contract and set TokenID in storage for event management tests

- Mint tokens for test users to allow voting/betting

- Fixes 'Error(Contract, Predictify-org#400)' (InvalidState) panic in tests requiring token operations
@Gbangbolaoluwagbemiga

Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me , pipeline issue resolved will appreciate some compliments fam and would love to pick more issues

@greatest0fallt1me greatest0fallt1me merged commit 73cfb45 into Predictify-org:master Jan 31, 2026
1 check passed
Martinsandre007 pushed a commit to Martinsandre007/predictify-contracts that referenced this pull request Mar 27, 2026
feature:Insufficient Event Metadata in refund_withdrawn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add comprehensive tests for user balance management

2 participants