test: market lifecycle stateful fuzzing - #905
Merged
greatest0fallt1me merged 1 commit intoJul 24, 2026
Merged
Conversation
Implement comprehensive stateful property-based testing for the Predictify Hybrid prediction market lifecycle using proptest. Changes: - Add tests/stateful.rs with fuzzing infrastructure - Add STATEFUL_FUZZING_README.md documentation - Add PR_STATEFUL_FUZZING.md summary - Register stateful test target in Cargo.toml The test suite validates: - Market state transitions (Active → Ended → Resolved → Closed) - Invariants (stake non-negativity, outcome consistency, etc.) - Authorization requirements - Idempotency guarantees - Balance consistency Coverage includes: - Market creation (varying parameters) - Voting and betting on active markets - Time-based state transitions - Market resolution - Winnings claims - Edge cases and error conditions Test configuration: - 100 test cases per property - 1-20 random operations per case - Shrinking on failure for minimal reproduction Ref: GrantFox FWC26 campaign
|
@JClark011 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! 🚀 |
Contributor
|
Merged into master via admin resolver (-X theirs). |
4 tasks
Contributor
|
LGTM ✅ appreciate the detailed PR description! |
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.
Market Lifecycle Stateful Fuzzing
Overview
This PR implements comprehensive stateful property-based testing for the
Predictify Hybrid prediction market lifecycle using proptest. The test suite
validates invariants, discovers edge cases, and ensures correctness across
arbitrary operation sequences.
Implementation
New Files
ResolveMarket, ClaimWinnings
Modified Files
Cargo.toml
binary
Features
Stateful Test Architecture
TestState
├── Soroban Environment
├── Contract & Token Addresses
├── Admin & User Addresses
├── Market Models (Expected State)
└── Balance Tracking
Operations (Proptest Strategies)
├── CreateMarket (1-30 days, 2-4 outcomes)
├── PlaceVote (random users/stakes)
├── PlaceBet (random users/amounts)
├── AdvanceTime (1-60 days)
├── ResolveMarket (random outcome)
└── ClaimWinnings (eligible users)
Invariants Validated
├── State Transition Validity
├── Outcome Consistency
├── Stake Non-Negativity
├── Vote/Bet Exclusivity
└── Claim Ordering
Property-Based Tests
test_market_lifecycle_invariants
- Validates all invariants across 1-20 random operations
- 100 test cases with automatic shrinking on failure
test_state_transitions
- Verifies time-based state transitions
- Ensures markets transition from Active → Ended correctly
test_idempotency
- Tests duplicate operation handling
- Validates AlreadyVoted error on second vote
Coverage
✅ Market creation with varying parameters
✅ Voting and betting on active markets
✅ Time-based state transitions
✅ Market resolution with winning outcomes
✅ Winnings claims
✅ Authorization checks
✅ Idempotency guarantees
✅ Balance consistency
✅ State machine correctness
Testing
Run Stateful Tests
cargo test -p predictify-hybrid --test stateful
Expected Output
running 6 tests
test test_basic_market_creation ... ok
test test_vote_on_active_market ... ok
test test_no_vote_after_market_ends ... ok
test test_market_lifecycle_invariants ... ok
test test_state_transitions ... ok
test test_idempotency ... ok
test result: ok. 6 tests passed
Security Benefits
Configuration
const MAX_OPERATIONS: usize = 20; // Max operations per test
const MAX_USERS: usize = 5; // Users to simulate
const MAX_STAKE: i128 = 1_000_000_000; // 1,000 XLM max
const INITIAL_BALANCE: i128 = 10_000_000_000; // 10,000 XLM per user
ProptestConfig {
cases: 100, // Test cases per property
max_shrink_iters: 1000, // Shrinking iterations
}
Acceptance Criteria
lifecycle)
References
(https://developers.stellar.org/docs/build/guides/testing)
(https://developers.stellar.org/docs/build/guides/testing/fuzzing)
Ref: GrantFox FWC26 campaign
Test configuration:
Ref: GrantFox FWC26 campaign
Pull Request Description
📋 Basic Information
Type of Change
Please select the type of change this PR introduces:
Related Issues
Closes #(issue number)
Fixes #(issue number)
Related to #(issue number)
Priority Level
📝 Detailed Description
What does this PR do?
Why is this change needed?
How was this tested?
Alternative Solutions Considered
🏗️ Smart Contract Specific
Contract Changes
Please check all that apply:
Oracle Integration
Market Resolution Logic
Security Considerations
🧪 Testing
Test Coverage
Test Results
Manual Testing Steps
📚 Documentation
Documentation Updates
Breaking Changes
Breaking Changes:
Migration Guide:
🔍 Code Quality
Code Review Checklist
Performance Impact
Security Review
🚀 Deployment & Integration
Deployment Notes
Integration Points
📊 Impact Assessment
User Impact
Business Impact
✅ Final Checklist
Pre-Submission
Review Readiness
📸 Screenshots (if applicable)
🔗 Additional Resources
💬 Notes for Reviewers
Please pay special attention to:
Questions for reviewers:
Thank you for your contribution to Predictify! 🚀
Close #851