Summary
The creditline suite has two harnesses: TestCtx (mock reputation + mock pool) driving the bulk of the 148 tests, and RealIntegrationCtx (contracts/creditline-contract/src/tests.rs:2535) which wires the real reputation, vendor-registry, pool and parameters contracts. The real harness today only exercises the create_loan (auto-funded) happy path (test_end_to_end_happy_path_across_all_contracts, :2754) — the full request → approve → fund → repay → score-up lifecycle through request_loan (contracts/creditline-contract/src/lib.rs:133-177) and approve_loan (:679-752) across all-real contracts is not covered end-to-end. The Pending → Active transition, the second validation pass at approval (:705-710), and the pool funding that happens only at approval (:726-733) are asserted only against mocks (TestCtx, used by 109 tests). This workstream adds the missing all-real lifecycle so the request/approve path is proven against the actual contracts.
Why this matters: the property is the request/approve/fund/repay lifecycle is proven end-to-end against the real contracts, not mocks. Mock assertions (was_fund_loan_called) cannot catch a divergence between the real pool's accounting and what creditline expects; the request→approve path has no real-contract coverage at all today.
Labels
area: contracts type: testing priority: medium
Workstream 1 — All-real request → approve → fund → repay → score-up lifecycle
Objective
Add a RealIntegrationCtx-based test that drives a loan through request_loan → approve_loan → repay_loan against the real reputation, registry, pool and parameters contracts, asserting balances, statuses and the reputation increase.
Problem
RealIntegrationCtx (contracts/creditline-contract/src/tests.rs:2535-2666) registers ReputationContract (:2565), VendorRegistryContract (:2570), LiquidityPoolContract (:2572) and ParametersContract (:2575), and its existing tests use create_loan (:2745,2789) — the auto-funded path. The request_loan/approve_loan split exists only in the mock TestCtx (create_default_request at :301, and approve tests), where the pool and reputation are mocks and was_fund_loan_called (:353-355) stands in for real accounting. The real approval-time re-validation (validate_vendor/validate_reputation/validate_liquidity, lib.rs:705-710) and pool funding (fund_loan_from_pool, :726-733) therefore have no all-real assertion. vouching's suite likewise has no all-real three-contract flow (contracts/vouching-contract/src/tests.rs uses MockReputationContract throughout).
Scope
contracts/creditline-contract/src/tests.rs (edit — add the all-real request/approve/repay test)
contracts/vouching-contract/src/tests.rs (edit — see con-test-03; a vouch→creditline eligibility flow lives there)
Implementation
- In
RealIntegrationCtx, add a helper request_and_approve that calls creditline.request_loan and then creditline.approve_loan(admin, loan_id), funding the pool and minting the borrower's guarantee as needed.
- Add
test_real_lifecycle_request_approve_fund_repay_across_all_contracts: fund the real pool, register an active vendor in the real registry, set_score on the real reputation, request a loan, assert Pending and the guarantee transfer (lib.rs:159-161), approve it, assert Active + funded_at and the real pool's locked_liquidity increased, repay in full, assert Paid, the guarantee refund, and the real reputation score increase (early vs on-time, :1176).
- Assert the real pool received the correct principal/interest split via
pool.get_pool_stats() / receive_repayment effects, replacing the mock's was_receive_repayment_called (:360-362).
- Keep the existing mock tests where they assert pure creditline-internal logic; this workstream adds the real-contract counterpart, it does not delete the mocks (that is con-test-04/06).
Acceptance Criteria
Testing
- Integration (the deliverable): the all-real lifecycle above.
- Regression: assert the Pending→Active transition leaves
funded_at set (:717) — the mock path never checks the real pool side of this.
Shared acceptance criteria (whole epic)
Security & compatibility considerations
- These are test-only changes; they must not weaken any assertion or introduce a mock where a real contract is required.
- The real registry must be initialized and the vendor approved for the flow to pass — mirrors production wiring; do not bypass with
mock_all_auths shortcuts that hide auth failures beyond what the suite already uses.
References
contracts/creditline-contract/src/tests.rs:2535-2666 — RealIntegrationCtx::setup + helpers.
contracts/creditline-contract/src/tests.rs:2754-2793 — existing real happy path (create_loan).
contracts/creditline-contract/src/tests.rs:159-205,301-330,350-376 — mock harness and was_* helpers to supersede.
contracts/creditline-contract/src/lib.rs:133-177,679-752 — request_loan / approve_loan.
contracts/vouching-contract/src/tests.rs — vouching suite (real-reputation flow is con-test-03).
- Extends the real-integration harness introduced for the existing
test_end_to_end_* tests; adds the request/approve path they omit.
If you're solving this with AI
In scope: contracts/creditline-contract/src/tests.rs (and contracts/vouching-contract/src/tests.rs only as con-test-03 directs) — only.
Out of scope: any production lib.rs/storage.rs change; the other contracts' non-test code; new runtime deps; deleting existing mock tests (done in con-test-04/06); reformatting untouched tests.
Must: follow the repo PR template exactly; keep CI green for real (fmt + clippy + build + test); the new test must exercise real contracts (no mock externals); reference this issue (Closes #<n>); no secrets.
Contribution requirements: Follow the repo PR template exactly — https://github.com/StepFi-app/StepFi-Contracts/blob/main/.github/pull_request_template.md. Reference this issue in your PR. CI must pass green (fmt + clippy + build + tests). No secrets; no out-of-scope changes.
Summary
The creditline suite has two harnesses:
TestCtx(mock reputation + mock pool) driving the bulk of the 148 tests, andRealIntegrationCtx(contracts/creditline-contract/src/tests.rs:2535) which wires the real reputation, vendor-registry, pool and parameters contracts. The real harness today only exercises thecreate_loan(auto-funded) happy path (test_end_to_end_happy_path_across_all_contracts,:2754) — the full request → approve → fund → repay → score-up lifecycle throughrequest_loan(contracts/creditline-contract/src/lib.rs:133-177) andapprove_loan(:679-752) across all-real contracts is not covered end-to-end. ThePending → Activetransition, the second validation pass at approval (:705-710), and the pool funding that happens only at approval (:726-733) are asserted only against mocks (TestCtx, used by 109 tests). This workstream adds the missing all-real lifecycle so the request/approve path is proven against the actual contracts.Why this matters: the property is the request/approve/fund/repay lifecycle is proven end-to-end against the real contracts, not mocks. Mock assertions (
was_fund_loan_called) cannot catch a divergence between the real pool's accounting and what creditline expects; the request→approve path has no real-contract coverage at all today.Labels
area: contractstype: testingpriority: mediumWorkstream 1 — All-real request → approve → fund → repay → score-up lifecycle
Objective
Add a
RealIntegrationCtx-based test that drives a loan throughrequest_loan→approve_loan→repay_loanagainst the real reputation, registry, pool and parameters contracts, asserting balances, statuses and the reputation increase.Problem
RealIntegrationCtx(contracts/creditline-contract/src/tests.rs:2535-2666) registersReputationContract(:2565),VendorRegistryContract(:2570),LiquidityPoolContract(:2572) andParametersContract(:2575), and its existing tests usecreate_loan(:2745,2789) — the auto-funded path. Therequest_loan/approve_loansplit exists only in the mockTestCtx(create_default_requestat:301, and approve tests), where the pool and reputation are mocks andwas_fund_loan_called(:353-355) stands in for real accounting. The real approval-time re-validation (validate_vendor/validate_reputation/validate_liquidity,lib.rs:705-710) and pool funding (fund_loan_from_pool,:726-733) therefore have no all-real assertion. vouching's suite likewise has no all-real three-contract flow (contracts/vouching-contract/src/tests.rsusesMockReputationContractthroughout).Scope
contracts/creditline-contract/src/tests.rs(edit — add the all-real request/approve/repay test)contracts/vouching-contract/src/tests.rs(edit — see con-test-03; a vouch→creditline eligibility flow lives there)Implementation
RealIntegrationCtx, add a helperrequest_and_approvethat callscreditline.request_loanand thencreditline.approve_loan(admin, loan_id), funding the pool and minting the borrower's guarantee as needed.test_real_lifecycle_request_approve_fund_repay_across_all_contracts: fund the real pool, register an active vendor in the real registry,set_scoreon the real reputation, request a loan, assertPendingand the guarantee transfer (lib.rs:159-161), approve it, assertActive+ funded_at and the real pool'slocked_liquidityincreased, repay in full, assertPaid, the guarantee refund, and the real reputation score increase (early vs on-time,:1176).pool.get_pool_stats()/receive_repaymenteffects, replacing the mock'swas_receive_repayment_called(:360-362).Acceptance Criteria
request_loanthenapprove_loanare called, then the loan isActive, the real poollocked_liquidityequals the pool contribution, and the guarantee sits with creditline.repay_loanis called, then the loan isPaid, the guarantee is refunded, and the real reputation score has increased by the configured reward.:705-710runs).Testing
funded_atset (:717) — the mock path never checks the real pool side of this.Shared acceptance criteria (whole epic)
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo build --locked --target wasm32-unknown-unknown --release,cargo test --lockedall exit 0; test count does not drop.RealIntegrationCtx; no production code changed.contracts/*-contract/src/tests.rs.Security & compatibility considerations
mock_all_authsshortcuts that hide auth failures beyond what the suite already uses.References
contracts/creditline-contract/src/tests.rs:2535-2666—RealIntegrationCtx::setup+ helpers.contracts/creditline-contract/src/tests.rs:2754-2793— existing real happy path (create_loan).contracts/creditline-contract/src/tests.rs:159-205,301-330,350-376— mock harness andwas_*helpers to supersede.contracts/creditline-contract/src/lib.rs:133-177,679-752—request_loan/approve_loan.contracts/vouching-contract/src/tests.rs— vouching suite (real-reputation flow is con-test-03).test_end_to_end_*tests; adds the request/approve path they omit.If you're solving this with AI
In scope:
contracts/creditline-contract/src/tests.rs(andcontracts/vouching-contract/src/tests.rsonly as con-test-03 directs) — only.Out of scope: any production
lib.rs/storage.rschange; the other contracts' non-test code; new runtime deps; deleting existing mock tests (done in con-test-04/06); reformatting untouched tests.Must: follow the repo PR template exactly; keep CI green for real (fmt + clippy + build + test); the new test must exercise real contracts (no mock externals); reference this issue (
Closes #<n>); no secrets.Contribution requirements: Follow the repo PR template exactly — https://github.com/StepFi-app/StepFi-Contracts/blob/main/.github/pull_request_template.md. Reference this issue in your PR. CI must pass green (fmt + clippy + build + tests). No secrets; no out-of-scope changes.