Add contract test enhancements and lightweight view function#1236
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@designsage8 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
- Add comprehensive test for get_platform_statistics (Arena1X#1036) - Add get_user_joined_events_count lightweight view function (Arena1X#1038) - Add tests for get_prediction_distribution with all three outcomes (Arena1X#1035) - Add test for cancel_market refunds all stakers (Arena1X#1042) Closes Arena1X#1036, Arena1X#1038, Arena1X#1035, Arena1X#1042
348d2a6 to
e66b1b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Contract Test Enhancements and Lightweight View Function
Overview
This PR adds comprehensive test coverage for platform statistics, prediction distribution, and market cancellation, plus a new lightweight view function for counting user-joined events. These changes improve test coverage, add performance optimizations for dashboard queries, and ensure refund correctness in the open-market contract.
Closes #1036
Closes #1038
Closes #1035
Closes #1042
Changes
🧪 Task 1: Add comprehensive test for get_platform_statistics (#1036)
Problem:
views::get_platform_statisticsreturns aPlatformStatisticsstruct with counters for total events, matches, predictions, participants, and fees. There was no integration test that drives all of these counters through multiple operations and asserts each field.Solution:
test_get_platform_statistics_comprehensive_counter_test()inviews_tests.rstotal_events == 2total_matches == 4total_predictions == 12(3 users × 2 events × 2 matches)unique_participants == 3total_fees_collected == FEE * 2Files Changed:
contracts/creator-event-manager/tests/views_tests.rs- Added comprehensive counter testAcceptance Criteria Met:
✨ Task 2: Add get_user_joined_events_count lightweight view function (#1038)
Problem:
get_user_eventsreturns the fullVecof event IDs a user has joined. For dashboards that display only a "X events joined" badge, loading the entire vector is wasteful. A lightweight count function is needed.Solution:
get_user_joined_events_count(env, user) -> u32insrc/views.rssrc/lib.rsas a public contract methodtests/views_tests.rs:get_user_events().len()Files Changed:
contracts/creator-event-manager/src/views.rs- Added lightweight count functioncontracts/creator-event-manager/src/lib.rs- Wired function into contract interfacecontracts/creator-event-manager/tests/views_tests.rs- Added 3 comprehensive testsAcceptance Criteria Met:
get_user_events().len()🧪 Task 3: Add test for get_prediction_distribution with all three outcomes (#1035)
Problem:
prediction::get_prediction_distributionreturns(team_a_count, draw_count, team_b_count). The existing tests did not exercise a scenario where users predict all three outcomes (TEAM_A, TEAM_B, DRAW) for the same match and verify each count independently.Solution:
test_get_prediction_distribution_all_three_outcomes()with 5 users:test_get_prediction_distribution_zero_predictions_all_zero():test_get_prediction_distribution_single_outcome_saturation():Files Changed:
contracts/creator-event-manager/tests/prediction_tests.rs- Added 3 comprehensive testsAcceptance Criteria Met:
🧪 Task 4: Add test for cancel_market refunds all stakers (#1042)
Problem:
market::cancel_marketshould refund every staker their original stake in full. The existing market tests did not have an end-to-end test that stakes from multiple users with different amounts, cancels the market, and verifies each user's balance is restored exactly.Solution:
cancel_market_refunds_exact_stake_amounts()inmarket_tests.rscancel_marketMarketAlreadyCancelledFiles Changed:
contracts/open-market/tests/market_tests.rs- Added comprehensive refund verification testAcceptance Criteria Met:
Testing
All changes include comprehensive unit tests:
Test Coverage:
Run Tests:
Breaking Changes
None. All changes are additive (new tests and new view function).
Migration Notes
No database migrations or contract upgrades required. All changes are test additions and a new read-only view function.
Performance Impact
Security Considerations
get_user_joined_events_countis a read-only view function with no authentication requirements, consistent with existing view functionsFuture Improvements
Checklist