feat: add comprehensive bet limit validation tests #277
+548
−0
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.
test: add comprehensive tests for minimum and maximum bet limits
Closes #244
Summary
This PR adds comprehensive test coverage for bet limit validation in the Predictify Hybrid contract. The implementation includes 31 new test cases covering boundary values, rejection scenarios, edge cases, integration flows, security checks, and comprehensive coverage scenarios.
Changes Made
Files Modified
contracts/predictify-hybrid/src/bet_tests.rs- Added 31 comprehensive bet limit validation testsTest Coverage Added
1. Boundary Value Tests (4 tests)
test_place_bet_exactly_minimum()- Successful bet at MIN_BET_AMOUNTtest_place_bet_exactly_maximum()- Successful bet at MAX_BET_AMOUNTtest_validate_bet_amount_at_minimum()- Validator accepts minimumtest_validate_bet_amount_at_maximum()- Validator accepts maximum2. Rejection Tests (8 tests)
test_place_bet_below_minimum_one_stroop()- Rejects MIN_BET_AMOUNT - 1test_place_bet_below_minimum_half()- Rejects MIN_BET_AMOUNT / 2test_place_bet_zero_amount()- Rejects zero amounttest_place_bet_negative_amount()- Rejects negative amountstest_place_bet_above_maximum_one_stroop()- Rejects MAX_BET_AMOUNT + 1test_place_bet_above_maximum_double()- Rejects MAX_BET_AMOUNT * 2test_validate_bet_amount_below_minimum()- Validator rejects below mintest_validate_bet_amount_above_maximum()- Validator rejects above max3. Edge Case Tests (7 tests)
test_validate_bet_amount_zero()- Zero validationtest_validate_bet_amount_negative()- Negative validationtest_validate_bet_amount_very_small()- Very small values (1 stroop)test_validate_bet_amount_very_large()- Very large values (i128::MAX)test_validate_bet_amount_boundary_minus_one()- MIN - 1test_validate_bet_amount_boundary_plus_one()- MAX + 1test_validate_bet_amount_within_range()- Valid values in range4. Integration Tests (5 tests)
test_place_bet_minimum_with_sufficient_balance()- Full flow with mintest_place_bet_maximum_with_sufficient_balance()- Full flow with maxtest_place_bet_below_minimum_rejects_with_error()- Error code verificationtest_place_bet_above_maximum_rejects_with_error()- Error code verificationtest_place_bet_valid_amounts_in_range()- Multiple valid amounts5. Security and Error Code Tests (3 tests)
test_bet_below_minimum_returns_insufficient_stake()- Error 107 verificationtest_bet_above_maximum_returns_invalid_input()- Error 401 verificationtest_error_codes_match_constants()- All error codes verified6. Comprehensive Coverage Tests (4 tests)
test_multiple_bets_at_different_limits()- Various users at boundariestest_bet_limit_validation_in_isolation()- Direct validator callstest_bet_limit_validation_in_place_bet_flow()- Through BetManagertest_bet_amount_edge_cases_comprehensive()- All edge casesTest Coverage
BetValidator::validate_bet_amount()Test Results
All tests compile and pass successfully.
Implementation Details
Bet Limits Tested
Error Codes Verified
Error::InsufficientStake(107) - For amounts < MIN_BET_AMOUNTError::InvalidInput(401) - For amounts > MAX_BET_AMOUNTTest Approach
BetValidator::validate_bet_amount()BetManager::place_bet()Notes
Features Not Yet Implemented
The requirements mentioned testing for:
These features would require implementation before they can be tested. The current test suite focuses on comprehensive coverage of existing functionality.
Testing
To run the bet limit tests:
To run a specific test:
Checklist
Related Issues
Closes #244