Repository navigation
test(lending): cover oracle-driven liquidation flow (#1522) - #1570
Merged
nanaf6203-bit merged 1 commit intoNov 24, 2026
Merged
nanaf6203-bit merged 1 commit into
nanaf6203-bit merged 1 commit into
Conversation
Add an integration suite under contract-extensions/tests that publishes prices through the compiled mock oracle, records the same values on lending's admin oracle feed, and exercises health-factor boundaries, missing and stale prices, full liquidation, and oracle priority over caller-supplied prices. Also repair a merge artifact in liquidate_loan. A duplicated pre-MettaChain#1088 price block referenced the renamed _current_collateral_values parameter, and the surviving block never recomputed effective_threshold, so propchain-lending did not compile. Consolidating the block restores the oracle-only valuation path and the weighted threshold calculation.
|
@Moonwalker-rgb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
nanaf6203-bit
approved these changes
Nov 24, 2026
nanaf6203-bit
left a comment
Contributor
There was a problem hiding this comment.
LGTM, nice work. Thanks for the contribution!
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.
Closes #1522
Summary
Adds a standalone integration suite at
contract-extensions/tests/lending-oracle-liquidation-tests/covering thelending liquidation path with prices supplied by the compiled
MockOracle.It also repairs a merge artifact that currently prevents
propchain-lendingfrom compiling.
Changes
contract-extensions/tests/lending-oracle-liquidation-tests/Cargo.tomlcontract-extensions/tests/lending-oracle-liquidation-tests/src/lib.rscontracts/lending/src/lib.rs— required compile repair only (see below)Checklist
contract-extensions/; the contract changeis a compile repair explicitly required to build the tests
contracts/— not applicable:liquidate_loandidnot compile, so
contracts/lending/src/lib.rshad to be repairedcargo clippypasses with no warningscargo testpasses for the new suitecargo buildsucceeds (the test run builds both compiled contracts)Testing
Coverage against the acceptance criteria
(10_000 bps = 1.0; liquidation only strictly below it).
Liquidated,one
LoanLiquidatedevent is emitted, and re-liquidation returnsLoanNotActive.until the threshold is crossed (1.12, then 1.04, then below 1.0).
PriceFeedMissing, stale prices returnPriceFeedStale, and a price exactly atprice_max_ageis still accepted.admin feed wins in both directions.
Where the oracle boundary is
Lending does not call the oracle contract. Since #1088
liquidate_loanreadsonly the admin-injected
oracle_pricesfeed and ignores the caller-suppliedvector. The suite therefore pushes each price to
MockOracle, reads it backthrough the
Oracletrait (so the compiled mock oracle really served it), andthen records the identical value on lending as admin. No price reaches lending
without first coming out of the oracle.
Liquidation semantics
liquidate_loanis an accounting finalisation in this contract: it re-pricescollateral from the oracle, compares aggregate LTV with the weighted
liquidation threshold, and marks the loan
Liquidated. It does not transfercollateral to the liquidator, repay debt from a liquidator balance, or support
partially liquidating a position. The suite pins those real semantics rather
than inventing a partial-liquidation path, which is called out in the crate
module docs.
Compile repair in
contracts/lendingA merge left two copies of the liquidation valuation block: the stale copy
referenced the renamed
_current_collateral_valuesparameter, and thesurviving copy never recomputed
effective_threshold, which is used two lineslater. This PR consolidates them into the single oracle-only block, restoring
the #1088 valuation path and the weighted-threshold calculation. Without this
the test crate cannot build.
Note:
cargo test -p propchain-lending --libstill reports pre-existingfailures in borrow-rate, deposit/escrow, marketplace and purge tests, and the
existing
lending-liquidation-testshas three assertions written before the#1088 oracle requirement. Those are outside this issue and are left untouched.