Skip to content

Wire dead test modules, add lending risk tests, and pin proxy stub behavior - #1043

Open
Ibinola wants to merge 1 commit into
MettaChain:mainfrom
Ibinola:feature/oracle-database-test-wiring
Open

Wire dead test modules, add lending risk tests, and pin proxy stub behavior#1043
Ibinola wants to merge 1 commit into
MettaChain:mainfrom
Ibinola:feature/oracle-database-test-wiring

Conversation

@Ibinola

@Ibinola Ibinola commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves four test-coverage issues in one coherent pass over the lending, proxy, oracle, and database crates.

Database (Closes #981)

contracts/database/src/tests.rs was extracted from the contract body but never included, so its six tests were compiled as dead code and never executed. The module is now wired into lib.rs behind #[cfg(test)] and all six tests run and pass.

Oracle (Closes #980)

Same story for the oracle's extracted test suite — wired it into the contract module, then repaired the staleness that had accumulated while the file was dead:

  • oracle_source_multisig_tests called a setup_oracle() helper that only existed inside the sibling oracle_tests module; the helper is now defined per-module.
  • Tests used ink_env::test_api::get_block_timestamp, which no longer exists in ink 5.1.1; replaced with ink::env::block_timestamp::<DefaultEnvironment>().
  • Two assertions expected behavior that has since changed intentionally:
    • test_get_nonexistent_valuation_fails: unknown property ids now return a zeroed placeholder valuation (aggregation fallback) instead of PropertyNotFound; the test now pins the zeroed fallback.
    • test_auto_slash_on_staleness: sources that have never reported (last_report == 0) are exempt from staleness slashing; the fixture now records a nonzero report time so the scenario still exercises an actual stale source.

Lending (Closes #978)

Added risk-path coverage to src/test.rs:

  • Position PnL boundaries: long/short symmetric gains, zero-delta boundary, negative moves, and PositionNotFound for unknown ids.
  • Liquidation: healthy collateral → both should_liquidate_loan and liquidate_loan refuse; threshold breach → liquidation succeeds; post-state consistency (status persisted, double-liquidation rejected with LoanNotActive, non-Active loans no longer report liquidatable).
  • Restructuring: third parties can't propose or approve; borrower proposal sets pending state; single-party approval returns false; lender completion applies new terms, marks the loan Restructured, removes the record, and re-approval fails with RestructuringNotFound.

Proxy (Closes #979)

The crate is currently a documented stub. Added interim coverage pinning deploy + message dispatch, with a note that the planned transparent-proxy reimplementation must extend the module with upgrade-path tests (delegation works, upgrade admin-only, non-admin rejected) before landing.

Workspace clippy

Current nightly fires clippy::clone_on_copy inside ink!-generated storage accessors on a pristine checkout of main, failing -D warnings CI for every PR. A crate-level #![allow(clippy::clone_on_copy)] with a comment is added to each affected lib root so this PR's own changes can be evaluated on their merits.

Test plan

  • cargo +nightly fmt --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-features --workspace (0 failures; database 6, oracle 51, lending 48+1, proxy 1)

…havior

Closes MettaChain#978
Closes MettaChain#979
Closes MettaChain#980
Closes MettaChain#981

- database: wire the extracted src/tests.rs into lib.rs so its six tests
  actually run instead of being flagged dead code.
- oracle: wire src/tests.rs into the contract module and repair stale
  tests: give oracle_source_multisig_tests its own setup helper, replace
  the removed ink_env get_block_timestamp test API with
  ink::env::block_timestamp, and update two assertions whose expected
  behavior changed (missing properties now return a zeroed valuation,
  never-reported sources are exempt from staleness slashing).
- lending: add risk-path coverage for margin position PnL boundaries
  (long/short/zero-delta/unknown id), liquidation threshold enforcement
  with post-liquidation state consistency, and the full restructuring
  approval flow including unauthorized parties and record cleanup.
- proxy: interim stub test that pins deploy + dispatch while the real
  transparent-proxy reimplementation lands; documents that upgrade-path
  tests are required there.
- workspace: allow clippy::clone_on_copy crate-wide; current nightly
  fires it inside ink!-generated storage accessors on a pristine main.
@drips-wave

drips-wave Bot commented Aug 24, 2026

Copy link
Copy Markdown

@Ibinola 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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment