Skip to content

fix: return InsufficientCollateral instead of InsufficientScore in refinance_loan#43

Merged
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
Godbrand0:fix/refinance-loan-insufficient-collateral-error
Jun 23, 2026
Merged

fix: return InsufficientCollateral instead of InsufficientScore in refinance_loan#43
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
Godbrand0:fix/refinance-loan-insufficient-collateral-error

Conversation

@Godbrand0

Copy link
Copy Markdown
Contributor

Summary

Closes #6

  • Bug fix: The collateral coverage check in refinance_loan (loan_manager/src/lib.rs:1814) was returning LoanError::InsufficientScore when loan.collateral_amount < new_amount. Changed to return LoanError::InsufficientCollateral (variant = 26), which already existed in the enum but was never exercised.
  • Audit: Reviewed all other LoanError::InsufficientScore returns in lib.rs — the remaining two usages (lines 1045 and 1810) correctly guard against a low credit score and are unchanged.
  • Test: Added test_refinance_loan_fails_with_insufficient_collateral which asserts that attempting to refinance with collateral below the new amount returns LoanError::InsufficientCollateral, exercising the variant for the first time.

Test plan

  • cargo test -p loan_manager refinance — all 4 refinance tests pass, including the new regression test
  • Existing test_refinance_loan_fails_when_score_drops_below_minimum still returns InsufficientScore (credit-score path is untouched)

…finance_loan

The collateral coverage check in refinance_loan was returning the wrong
error variant (InsufficientScore) when loan.collateral_amount < new_amount.
This made it impossible for callers to distinguish a credit-score failure
from a collateral shortfall. Fixed to return InsufficientCollateral (= 26)
as intended by the existing enum definition.

Adds a regression test that asserts refinance with insufficient collateral
returns LoanError::InsufficientCollateral, exercising the variant for the
first time.

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean and correct, merging. this is a genuine fix not just a rename: the collateral guard at loan_manager/src/lib.rs:1814 (loan.collateral_amount < new_amount) now returns InsufficientCollateral, while the score check stays a separate guard above it (current_score < min_score -> InsufficientScore), so the two failure modes are properly distinguished. the new test_refinance_loan_fails_with_insufficient_collateral isolates the collateral path and ci is green. nice work.

if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

@ogazboiz ogazboiz merged commit 71cb0c2 into LabsCrypt:main Jun 23, 2026
1 check passed
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.

[Contracts] LoanManager refinance_loan returns InsufficientScore for an insufficient-collateral condition

2 participants