Skip to content

feat(SC-11): increase reputation score on full loan repayment#85

Merged
Josue19-08 merged 7 commits into
TrustUp-app:mainfrom
akintewe:feat/82-reputation-score-on-repayment
Jun 26, 2026
Merged

feat(SC-11): increase reputation score on full loan repayment#85
Josue19-08 merged 7 commits into
TrustUp-app:mainfrom
akintewe:feat/82-reputation-score-on-repayment

Conversation

@akintewe

Copy link
Copy Markdown
Contributor

Summary

  • Extracts reputation increment values into named constants in types.rs:
    • REPUTATION_INCREMENT_ON_TIME = 10 (full repayment at or after due date)
    • REPUTATION_INCREMENT_EARLY = 15 (full repayment before due date, bonus)
  • Adds emit_reputation_updated() to events.rs, emitting a REPUPD event with (score_delta, increase: bool, timestamp) after a successful reputation score change from the CreditLine contract
  • Updates handle_reputation_increase in lib.rs to use the named constants and emit the REPUPD event when the increase_score call to the Reputation contract succeeds (failure is still silently ignored so repayment is never blocked)
  • Resolves the two TODO stubs in test_multi_contract_integration_full_flow
  • Adds 3 new RealIntegrationCtx integration tests (full real contract stack):
    1. test_full_repayment_emits_reputation_updated_event — REPUPD event payload verified
    2. test_on_time_repayment_uses_increment_on_time_constant — score delta tied to the constant
    3. test_default_decreases_score_while_full_repayment_increases_score — SC-11 + SC-12 coexistence

Test plan

  • cargo test --locked -p creditline-contract — 98 tests pass, 0 failed, 4 ignored
  • All SC-11 tasks addressed:
    • Full repayment → increase_score called with REPUTATION_INCREMENT_ON_TIME or REPUTATION_INCREMENT_EARLY
    • Increment constants defined in types.rs
    • CreditLine registered as authorised updater in RealIntegrationCtx::setup
    • Only triggered on full repayment (not partial) ✅
    • ReputationUpdated (REPUPD) event emitted after successful call ✅
    • Unit tests: full repayment → increase, partial → unchanged, default → decrease (SC-12) ✅
    • TODO comments in existing tests resolved ✅

Closes #82

actions-user and others added 7 commits June 22, 2026 02:59
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 Josue19-08 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.

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.

@Josue19-08
Josue19-08 merged commit 7f4671e into TrustUp-app:main Jun 26, 2026
2 checks 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.

[FEATURE] SC-11: Increase reputation score on full loan repayment

3 participants