Comprehensive Tests for Query Functions #235
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cleses #209
Summary
This PR adds comprehensive test coverage for all query/getter functions in the Predictify Hybrid smart contract, achieving the required 95% test coverage with extensive edge case handling and gas efficiency validation.
Changes Made
New Test Cases (40+ tests added)
Query Function Coverage:
get_bet()- 4 tests covering data retrieval, non-existent users/markets, and post-claim statehas_user_bet()- 3 tests for bet existence checking and edge casesget_market_bet_stats()- 4 tests for statistics aggregation and consistencyget_implied_probability()- 4 tests for balanced/skewed markets and invalid scenariosget_payout_multiplier()- 3 tests for payout calculations across different oddsget_market()- 3 tests for market data retrieval and state transitionsget_market_analytics()- 2 tests for analytics data validationget_resolution_analytics()- 1 test for resolution statisticsget_admin_roles()&get_admin_analytics()- 2 tests for admin functionalityEdge Case Coverage:
Gas Efficiency Tests:
Infrastructure Improvements
Helper Function Added:
This helper ensures all test users are properly funded with tokens, preventing balance-related test failures.
Test Pattern Fixes:
Address::generate()calls tocreate_funded_user()Test Results
Before:
After:
Testing Guidelines Met
Files Modified
Validation
All tests follow existing patterns and conventions:
PredictifyTest::setup()mock_all_auths()for authenticationshould_panicfor error casestest_<function>_<scenario>patternNotes