Skip to content

#102 Medium: Insufficient Edge Case Coverage for Financial Bounds#127

Open
coder45oj wants to merge 2 commits into
TrusTrove:mainfrom
coder45oj:issue-102-edge-case-tests
Open

#102 Medium: Insufficient Edge Case Coverage for Financial Bounds#127
coder45oj wants to merge 2 commits into
TrusTrove:mainfrom
coder45oj:issue-102-edge-case-tests

Conversation

@coder45oj

Copy link
Copy Markdown
Contributor

Description

Adds comprehensive edge case and boundary tests for the pool contract, covering extreme u128 values, minimum positive increments, and financial bounds previously untested.

Changes

contracts/pool/src/test.rs — Added 11 edge case tests and a parameterized create_and_list_ext helper:

Overflow Protection

  • test_edge_deposit_overflow_panics — Verifies checked_mul in deposit() catches overflow when usdc_amount * total_shares > u128::MAX
  • test_edge_withdraw_overflow_panics — Verifies checked_mul in withdraw() catches overflow when shares * total_deposits > u128::MAX

Boundary Values

  • test_edge_min_deposit_and_withdraw — Minimum 1 USDC deposit and withdrawal at 1:1 price
  • test_edge_large_deposit_near_u128_max — i128::MAX deposit/withdrawal (largest value MockToken can hold)

Extreme Discount Scenarios

  • test_edge_fund_repay_with_zero_discount — Invoice with 0 bps discount (funded at 100% face value, zero yield)
  • test_edge_fund_repay_with_max_discount — Invoice with 5000 bps max discount (funded at 50%, 10B yield)

Financial Bounds

  • test_edge_fund_default_at_min_deposit — 100% utilization (9.8B deposit fully funded), then default and re-deposit after total_deposits = 0
  • test_edge_split_fund_two_invoices_min_liquidity — Fund to 0 available liquidity, then repay one to restore
  • test_edge_withdraw_exact_available_liquidity — Withdraw exactly the available liquidity amount, leaving shares backing funded invoices
  • test_edge_max_utilization_rate_boundaries — Verify 0% and 10000 bps (100%) utilization rates
  • test_edge_deposit_after_partial_default_with_remainder_shares — New LP deposits at below-par share price after default erodes pool value

Closes #102

Add comprehensive edge case and boundary tests for the pool contract,
covering extreme u128 values, minimum positive increments, and
financial bounds that were previously untested.

Tests added:
- test_edge_min_deposit_and_withdraw: 1 USDC deposit → 1 share → withdraw
- test_edge_large_deposit_near_u128_max: i128::MAX value deposit+withdraw
- test_edge_deposit_overflow_panics: confirm checked_mul catches overflow
- test_edge_withdraw_overflow_panics: confirm checked_mul catches overflow
- test_edge_fund_repay_with_zero_discount: 0 bps discount → no yield
- test_edge_fund_repay_with_max_discount: 5000 bps discount → 50% yield
- test_edge_fund_default_at_min_deposit: 100% utilization then default+redeposit
- test_edge_split_fund_two_invoices_min_liquidity: fund to 0 available
- test_edge_withdraw_exact_available_liquidity: withdraw exactly the liquid amount
- test_edge_max_utilization_rate_boundaries: 0% and 100% utilization
- test_edge_deposit_after_partial_default_with_remainder_shares: deposit below par

Closes TrusTrove#102
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@coder45oj 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! 🚀

Learn more about application limits

@K1NGD4VID

K1NGD4VID commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

fixe the ci error @coder45oj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Medium: Insufficient Edge Case Coverage for Financial Bounds

2 participants