Problem
The repay_installment() function in contracts/creditline-contract/src/lib.rs lacks isolated unit tests. The only existing coverage is incidental via end-to-end flow tests, leaving error paths (double-pay, out-of-bounds, unauthorized, zero-amount) untested. Without these, regressions in repayment logic can silently break borrower balances.
Context
Repayment correctness is the most safety-critical operation in StepFi — a bug here can either lock learners out of repaying or allow them to pay twice. Sponsors lose trust if installments are mis-accounted, and the reputation contract derives scoring from these calls. This must be airtight before mainnet.
Before Starting
Read these context files first:
- context/architecture-context.md
- context/code-standards.md
- context/progress-tracker.md
- contracts/creditline-contract/src/lib.rs
- contracts/creditline-contract/src/tests.rs
What To Build
- Add a helper
setup_loan_with_schedule(env, borrower, amount, n_installments) at the top of tests.rs that initializes the contract, creates a loan, and approves it.
- Test
repay_installment_happy_path: pay installment 0, assert Installment.paid == true, assert outstanding balance decremented by exact amount.
- Test
repay_installment_double_pay_rejected: pay installment 0, then call again — assert ContractError::InstallmentAlreadyPaid is returned.
- Test
repay_installment_out_of_bounds: call with index installments.len() — assert ContractError::InvalidInstallmentIndex.
- Test
repay_installment_non_borrower_rejected: call from a wallet other than the loan borrower — assert auth panic via env.mock_auths() mismatch.
- Test
repay_installment_zero_amount_rejected: ensure zero-amount payments are explicitly rejected with ContractError::InvalidAmount.
Files To Touch
contracts/creditline-contract/src/tests.rs
contracts/creditline-contract/src/errors.rs (if InvalidInstallmentIndex / InstallmentAlreadyPaid not yet defined)
Acceptance Criteria
Mandatory Checks Before PR
Problem
The
repay_installment()function incontracts/creditline-contract/src/lib.rslacks isolated unit tests. The only existing coverage is incidental via end-to-end flow tests, leaving error paths (double-pay, out-of-bounds, unauthorized, zero-amount) untested. Without these, regressions in repayment logic can silently break borrower balances.Context
Repayment correctness is the most safety-critical operation in StepFi — a bug here can either lock learners out of repaying or allow them to pay twice. Sponsors lose trust if installments are mis-accounted, and the reputation contract derives scoring from these calls. This must be airtight before mainnet.
Before Starting
Read these context files first:
What To Build
setup_loan_with_schedule(env, borrower, amount, n_installments)at the top oftests.rsthat initializes the contract, creates a loan, and approves it.repay_installment_happy_path: pay installment 0, assertInstallment.paid == true, assert outstanding balance decremented by exact amount.repay_installment_double_pay_rejected: pay installment 0, then call again — assertContractError::InstallmentAlreadyPaidis returned.repay_installment_out_of_bounds: call with indexinstallments.len()— assertContractError::InvalidInstallmentIndex.repay_installment_non_borrower_rejected: call from a wallet other than the loan borrower — assert auth panic viaenv.mock_auths()mismatch.repay_installment_zero_amount_rejected: ensure zero-amount payments are explicitly rejected withContractError::InvalidAmount.Files To Touch
contracts/creditline-contract/src/tests.rscontracts/creditline-contract/src/errors.rs(ifInvalidInstallmentIndex/InstallmentAlreadyPaidnot yet defined)Acceptance Criteria
#[test]functions covering each scenario abovecargo test -p creditline-contractpasses with all new tests greenEnv::default()andmock_all_auths()where appropriaterepay_installment_<scenario>conventionrepay_installment()branch coverage ≥ 90%Mandatory Checks Before PR