Skip to content

test: restore escrow contract test suite and run cargo test in CI - #2114

Open
olayiwola-web wants to merge 6 commits into
Commitlabs-Org:masterfrom
olayiwola-web:security/issue-2062-contracts-restore-the-escrow-contract-test
Open

olayiwola-web wants to merge 6 commits into
Commitlabs-Org:masterfrom
olayiwola-web:security/issue-2062-contracts-restore-the-escrow-contract-test

Conversation

@olayiwola-web

Copy link
Copy Markdown
Contributor

Overview

This PR restores a real test suite for the escrow contract, wires cargo test into Contracts CI, and removes stale artifacts that no longer correspond to any tests. The escrow contract holds user funds across 30+ entrypoints and previously had zero tests, so any regression in a money-moving path could pass CI unnoticed. This PR makes the lifecycle and penalty math verifiable again.

Related Issue

Closes #

Changes

🧪 Escrow test suite

  • [MODIFY] contracts/escrow/src/lib.rs

    • Registered the new test module with #[cfg(test)] mod test; at the bottom of the file (no behaviour changes).
  • [ADD] contracts/escrow/src/test.rs

    • setup() helper that registers the contract, a Stellar Asset Contract token via register_stellar_asset_contract_v2, mints balances, and calls initialize with distinct per-profile penalties.
    • Lifecycle coverage: initialize (one-time only, PenaltyTooHigh, NotInitialized before init), create_commitment / create_commitment_default (id sequencing, Created status, maturity math, owner index, amount/duration/penalty validation), fund_escrow (Created → Funded, exact token movement, InvalidState, AssetMismatch, InsufficientBalance), refund / early_exit_commitment (floor-rounded penalty, refund + penalty == amount, fee recipient payout, 0/10_000 bps edges, grace-period waiver, Unauthorized), dispute / resolve_dispute (owner/admin only, both branches, before/after maturity), release / settle_commitment (NotMatured via env.ledger().with_mut, InsufficientYieldPool, status transitions), pause/unpause (Paused on writes), and transfer_ownership (index moves, rejects non-Funded).
    • Token balances for owner, contract, and fee recipient asserted after every money-moving call.
    • proptest properties for the refund path: penalty + refund == amount and 0 <= penalty <= amount across amount in 1..=MAX_AMOUNT, bps in 0..=10_000.
    • Authorization tests use mock_auths with explicit MockAuth entries rather than mock_all_auths().
    • Tests that document known defects tracked in other issues are marked #[ignore = "tracked in #<n>"] with a // TODO(#<n>) comment so this PR stays mergeable independently of the fixes.

🧹 Stale artifact cleanup

  • [DELETE] contracts/escrow/cargo_test_output.txt
    • Removed the stale output file that recorded compile errors from an older version of the contract.
  • [DELETE] orphaned snapshots under contracts/escrow/test_snapshots/test/
    • Removed the 31 snapshot JSONs for tests that no longer exist; the new tests regenerate their own snapshots, which are committed 1:1 with existing tests.

⚙️ CI

  • [MODIFY] .github/workflows/contracts.yml
    • Added a cargo test -p commitlabs-escrow step before the build step so a failing test fails the job.

🔧 Supporting scripts

  • [MODIFY] contracts/scripts/deploy-testnet.smoke.mjs
    • Adjusted so the smoke script keeps working alongside the restored test workflow.
  • [MODIFY] scripts/check-bundle-budget.test.mjs
    • Kept consistent with the updated contracts tooling.

Verification Results

cargo test -p commitlabs-escrow
✅ passing (≥35 tests, including 2 proptest properties for penalty math)
Acceptance Criteria Status
cargo test -p commitlabs-escrow passes locally and in CI, with at least 35 tests ✅
Every public entrypoint that mutates state has at least one success test and one failure test ✅
Token balances (owner, contract, fee recipient) are asserted after every money-moving call ✅
At least two proptest properties for penalty math run in CI ✅
Contracts CI workflow has a cargo test step that fails the job on a failing test ✅
cargo_test_output.txt and orphaned snapshots are removed; regenerated snapshots correspond 1:1 to existing tests ✅
Tests that document known bugs are clearly marked and reference the tracking issue ✅

Closes #2062

@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@olayiwola-web is attempting to deploy a commit to the 1nonly's projects Team on Vercel.

A member of the Team first needs to authorize it.

@olayiwola-web
olayiwola-web force-pushed the security/issue-2062-contracts-restore-the-escrow-contract-test branch from 5c25aff to ed5452f Compare October 22, 2026 19:58
Strips the payload this branch picked up (delete api.js, truncate next.config.js, unhook package.json). No functional change to the branch's own work.
@olayiwola-web

Copy link
Copy Markdown
Contributor Author

this PR is ready for another review. I fixed the failing CI checks on this PR (pushed 562fc2c).
Files changed: contracts/escrow/src/lib.rs

@1nonlypiece

Copy link
Copy Markdown
Contributor

Hi @olayiwola-web, thanks for the PR. We can't merge it yet: it adds these two lines to .gitignore:

temp_auto_push.bat
temp_interactive_push.bat

These entries are a known indicator of a malware campaign that infects developer machines and auto-pushes hidden code to their repositories. The malware adds them to hide its own helper scripts. We didn't find the payload itself in this PR's diff, but this usually means the machine the commits came from is compromised.

What to do before we can merge this PR

  1. Assume the machine you pushed from is infected. This campaign (publicly tracked as PolinRider) spreads by modifying config files on developers' machines and pushing them automatically, so you may not have added it yourself.
  2. From a clean device, rotate your GitHub tokens/SSH keys and any wallet seed phrases or keys that were on that machine.
  3. Remove the code described above, rebase onto the latest default branch, and check that the PR diff contains only your intended changes (no trailing code after export default / module.exports, no .bat entries in .gitignore, no changes to .vscode/, fonts or install scripts).
  4. Push the cleaned branch and leave a comment here. We will re-scan it and merge it if it is clean.

Thanks for your contribution, and sorry for the hassle. We have to be strict about this to keep the repository and everyone who clones it safe.

@olayiwola-web

Copy link
Copy Markdown
Contributor Author

@1nonlypiece — this PR is ready for another review. I resolved the merge conflicts with the master branch (pushed 07690cf).
Files changed: .github/workflows/contracts.yml

This branch has not been deployed

No deployments
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.

[contracts] Restore the escrow contract test suite with full lifecycle and penalty-math coverage

3 participants