fix: return InsufficientCollateral instead of InsufficientScore in refinance_loan#43
Merged
ogazboiz merged 1 commit intoJun 23, 2026
Conversation
…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
approved these changes
Jun 23, 2026
ogazboiz
left a comment
Contributor
There was a problem hiding this comment.
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
4 tasks
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.
Summary
Closes #6
refinance_loan(loan_manager/src/lib.rs:1814) was returningLoanError::InsufficientScorewhenloan.collateral_amount < new_amount. Changed to returnLoanError::InsufficientCollateral(variant = 26), which already existed in the enum but was never exercised.LoanError::InsufficientScorereturns inlib.rs— the remaining two usages (lines 1045 and 1810) correctly guard against a low credit score and are unchanged.test_refinance_loan_fails_with_insufficient_collateralwhich asserts that attempting to refinance with collateral below the new amount returnsLoanError::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 testtest_refinance_loan_fails_when_score_drops_below_minimumstill returnsInsufficientScore(credit-score path is untouched)