-
Notifications
You must be signed in to change notification settings - Fork 12
Mike/test/directional rounding #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ng tests - Add get_user_debt_in_base_currency_for_testing - Add get_user_balance_in_base_currency_for_testing - These helpers expose private calculation functions for unit testing
…esting - Add update_interest_rates_and_virtual_balance_for_testing - Exposes private interest rate update function for unit testing
…fer testing - Add transfer_on_liquidation_for_testing - Exposes private liquidation transfer function for unit testing
- Test zero value returns 0 - Test unit value returns 1 - Verify round down result <= half-up result - Coverage: ray_mul_down boundary behavior
- Test zero value returns 0 - Test unit value returns 1 - Verify round up result >= half-up result - Coverage: ray_mul_up boundary behavior
- Verify down <= half <= up relationship - Test ray_mul and ray_div consistency - Coverage: directional rounding consistency
- Test small debt amounts dont round to zero - Verify ceil_div prevents debt invisibility - Coverage: Issue #2 prevention
- Test mint_scaled with rounding_down=false - Verify aToken conservative minting - Coverage: token_base mint_scaled down path
- Test mint_scaled with rounding_up=true - Verify vToken conservative minting - Coverage: token_base mint_scaled up path
- Test aToken mint-burn cycle cannot profit - Verify double-down prevents rounding attack - Coverage: Issue #1 prevention
- Test 1 octa dust handling in mint/burn - Verify early return prevents assert failure - Coverage: dust amount handling
- Test treasury minting with normal amount - Verify ray_div_down produces conservative result - Coverage: mint_to_treasury normal path
- Test aToken total_supply uses ray_mul_down - Verify conservative total supply calculation - Coverage: a_token_factory total_supply direction
- Test treasury skips dust amounts (1-2 octa) - Verify early return when ray_div_down rounds to 0 - Coverage: mint_to_treasury dust protection
- Test treasury early returns when amount is 0 - Verify no operation when supply == 0 - Coverage: mint_to_treasury zero amount edge case
- Test aToken balance_of never exceeds half-up result - Verify ray_mul_down conservative behavior - Coverage: a_token_factory balance_of safety guarantee
- Test aToken mint uses ray_div_down - Verify conservative minting (user receives less) - Coverage: a_token_factory mint conservative behavior
- Test aToken burn uses ray_div_up - Verify conservative burning (burns more scaled) - Coverage: a_token_factory burn conservative behavior
…ervative - Add treasury_scaled_before/after tracking - Add assertion for treasury_scaled_delta validation - Verify double-down rounding at both scaled and actual levels - Coverage: Validates scaled balance correctness in double conservative path
- Test liquidation transfer handles dust amounts gracefully - Verify early return when ray_div rounds to 0 scaled - Coverage: transfer_on_liquidation dust protection (L629)
- Test vToken balance_of uses ray_mul_up - Verify conservative debt calculation (never underestimated) - Coverage: variable_debt_token_factory balance_of L135
- Test vToken balance never falls below mathematical expectation - Verify ray_mul_up ensures debt is not underestimated - Coverage: variable_debt_token_factory balance_of safety guarantee
- Test small debt amounts remain visible after ceil_div - Verify debt conversion never rounds to zero - Coverage: generic_logic debt conversion with ceil_div (L45)
- Test vToken mint passes rounding_up=true to token_base - Verify conservative debt minting (records more debt) - Coverage: variable_debt_token_factory mint L348
- Test vToken burn passes rounding_up=false to token_base - Verify conservative debt burning (burns less scaled) - Coverage: variable_debt_token_factory burn L386
- Test pool_logic.update_interest_rates treasury accrual with ray_div_down - Supply 10000 + borrow 1000, fast-forward 1 day, trigger state update - Conditional validation: if accrued, verify delta <= borrow_amount - Handles reserve_factor=0 case (no accrual expected) - Coverage: pool_logic.update_interest_rates→accrue_to_treasury L442
- Test multi-cycle treasury accrual remains conservative - Supply 10000 + borrow 2000, execute 5 daily cycles - Add treasury_initial tracking to measure total accrual - Conditional validation: if accrued, verify total <= borrow amount - Verify meaningful accrual occurred (not just dust) - Coverage: pool_logic.update_interest_rates multi-cycle stability L442
…_mul_up - Add initial vs updated rate tracking (borrow_rate + liquidity_rate) - Verify rates increase after borrow (debt → utilization → rates) - Verify ray_mul_up gives conservative debt estimate - Remove redundant conditional check (already verified at L2304) - Coverage: Validates pool_logic.update_interest_rates uses ray_mul_up (L95)
- Pure functional test verifying ray_div_down consistency - Remove all unnecessary setup (supply/borrow/oracle) - Simplify to #[test] (no parameters needed) - Add exact value assertion: scaled_result == 666 - Coverage: Mathematical consistency of treasury accrual across 3 modules
- Test debt calculation for interest rate uses ray_mul_up - Verify conservative debt estimate for rate calculation - Coverage: pool_logic.update_interest_rates L95-102
- Test debt vs collateral asymmetry in liquidation calculations - Verify debt uses ray_mul_up while collateral uses ray_mul_down - Coverage: liquidation_logic debt and collateral calculation asymmetry - Ensures liquidation favors protocol (debt overestimated, collateral underestimated)
…y_mul_down - Add actual withdraw operation (was missing before) - Add liquidity setup to prevent virtual_balance underflow - Verify withdraw uses ray_mul_down for balance calculation - Coverage: supply_logic.withdraw L199-206 actual flow validation
- Verify borrow operation mints vToken debt using ray_div_up - Test borrow 1001 units with index=1.5*RAY results in scaled=668 - Coverage: borrow_logic → vToken.mint L348 conservative debt minting
- Verify repay operation burns vToken debt using ray_div_down - Test borrow 1000 then repay 100 units with index=1.5*RAY - Coverage: repay_logic → vToken.burn L386 conservative debt burning
- Verify complete liquidation flow with directional rounding - Test debt uses ceil_div, collateral uses floor division - Coverage: liquidation_logic.liquidation_call full flow
…_down - Verify complete flashloan flow: borrow and repay - Test flashloan_simple with 25 tokens (50% of 50 supply) - Verify premium calculation and repayment - Coverage: flashloan_logic full flow with conservative liquidity
…onal - Verify complete supply→borrow→repay→withdraw cycle - Test all operations use correct directional rounding - Coverage: End-to-end integration of all modified modules
- Verify directional rounding consistency across all protocol modules - Test aToken uses ray_mul_down, vToken uses ray_mul_up - Coverage: Cross-module integration validation
- Verify directional rounding accuracy over 5-year index growth - Test indices from 1.0 to 1.42 RAY (7% APY simulation) - Confirm error remains bounded (≤2 octa) regardless of index magnitude
- Verify directional rounding eliminates arbitrage opportunities - Test multiple supply→withdraw cycles with varying amounts and indices - Confirm user cannot profit from rounding (loss ≤1 octa acceptable)
- Verify directional rounding handles extreme values and boundary conditions - Test max safe values, minimal values, and magnitude independence - Coverage: Edge case safety and overflow protection
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #75 +/- ##
==========================================
+ Coverage 96.75% 97.58% +0.82%
==========================================
Files 16 38 +22
Lines 524 786 +262
==========================================
+ Hits 507 767 +260
- Misses 17 19 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mpsc0x
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing tests
meng-xu-cs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving approval as all changes are on tests and are not related to the contract code itself
add dedicated test cases specially for directional rounding, all tests passed.