feat(SC-11): increase reputation score on full loan repayment#85
Merged
Josue19-08 merged 7 commits intoJun 26, 2026
Merged
Conversation
Define REPUTATION_INCREMENT_ON_TIME (10) and REPUTATION_INCREMENT_EARLY (15) as named constants so the score increments are documented alongside the rest of the protocol parameters rather than being magic numbers in the implementation.
Adds emit_reputation_updated() so off-chain services can observe when the CreditLine contract successfully changes a borrower's reputation score. The event carries the score delta, direction (increase/decrease), and the ledger timestamp.
…repayment Replace magic numbers 15/10 in handle_reputation_increase with the typed constants REPUTATION_INCREMENT_EARLY and REPUTATION_INCREMENT_ON_TIME. After a successful increase_score call, emit the REPUPD event so callers can confirm the score change happened.
…_full_flow
Replace the two TODO stubs ("assert reputation score increased",
"assert liquidity pool received the repayment") with real assertions:
the loan status becomes Repaid and remaining_balance is 0 after full
repayment. Actual reputation score assertions are covered by the
RealIntegrationCtx integration tests that wire the real Reputation
contract. Also adds Val/Vec imports needed by upcoming event tests.
…tests Three new RealIntegrationCtx tests: 1. test_full_repayment_emits_reputation_updated_event — verifies the REPUPD event is emitted with the correct payload (score_delta using REPUTATION_INCREMENT_EARLY, increase=true) after early full repayment. 2. test_on_time_repayment_uses_increment_on_time_constant — confirms that on-time repayment awards exactly REPUTATION_INCREMENT_ON_TIME points, preventing silent regressions if the constant changes. 3. test_default_decreases_score_while_full_repayment_increases_score — SC-11 + SC-12 coexistence: two borrowers in the same pool; the good borrower's score increases on full repayment, the bad borrower's score decreases on default, independently and without interference.
Josue19-08
approved these changes
Jun 26, 2026
Josue19-08
left a comment
Contributor
There was a problem hiding this comment.
Solid implementation of SC-11. Named constants in types.rs replace the magic numbers cleanly, the REPUPD event in events.rs carries the right payload (score_delta, increase, timestamp), and the conditional emit in lib.rs correctly fires only on a successful increase_score call without blocking repayment on failure. The three RealIntegrationCtx integration tests cover the early path, the on-time path, and the SC-11/SC-12 coexistence scenario. TODO stubs in test_multi_contract_integration_full_flow are properly resolved with real assertions. CI is green (Build + Test pass). Merging.
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
types.rs:REPUTATION_INCREMENT_ON_TIME = 10(full repayment at or after due date)REPUTATION_INCREMENT_EARLY = 15(full repayment before due date, bonus)emit_reputation_updated()toevents.rs, emitting aREPUPDevent with(score_delta, increase: bool, timestamp)after a successful reputation score change from the CreditLine contracthandle_reputation_increaseinlib.rsto use the named constants and emit theREPUPDevent when theincrease_scorecall to the Reputation contract succeeds (failure is still silently ignored so repayment is never blocked)test_multi_contract_integration_full_flowRealIntegrationCtxintegration tests (full real contract stack):test_full_repayment_emits_reputation_updated_event— REPUPD event payload verifiedtest_on_time_repayment_uses_increment_on_time_constant— score delta tied to the constanttest_default_decreases_score_while_full_repayment_increases_score— SC-11 + SC-12 coexistenceTest plan
cargo test --locked -p creditline-contract— 98 tests pass, 0 failed, 4 ignoredincrease_scorecalled withREPUTATION_INCREMENT_ON_TIMEorREPUTATION_INCREMENT_EARLY✅types.rs✅RealIntegrationCtx::setup✅ReputationUpdated(REPUPD) event emitted after successful call ✅Closes #82