Skip to content

[BUG-005] Populate buyer escrow index on fund#194

Open
isaacCodes1 wants to merge 1 commit into
JSE-ORG:mainfrom
isaacCodes1:fix/buyer-index-on-fund
Open

[BUG-005] Populate buyer escrow index on fund#194
isaacCodes1 wants to merge 1 commit into
JSE-ORG:mainfrom
isaacCodes1:fix/buyer-index-on-fund

Conversation

@isaacCodes1
Copy link
Copy Markdown

@isaacCodes1 isaacCodes1 commented Jun 1, 2026

Overview

This PR fixes BUG-005 in contracts/escrow: when an escrow is created without a buyer and later funded by a signer, the buyer index was not always populated correctly. The fix ensures fund_escrow records the actual funding address in the buyer index after the token transfer succeeds, so get_escrows_by_buyer returns funded escrows for buyers who were not known at creation time.

Related Issue

Closes #150

Changes

Buyer Index Fix

  • [MODIFY] contracts/escrow/src/lib.rs
  • Added a small helper to append escrow IDs to the buyer index.
  • Updated fund_escrow to always index the actual funding address after a successful token transfer.
  • Updated get_escrows_by_buyer to read the persisted buyer index first and fall back to a scan only if the index is missing.

Regression Test

  • [ADD] contracts/escrow/src/test_get_escrows_by_buyer.rs
  • Added test_buyer_index_populated_on_fund to cover the case where the escrow is created with buyer = None and later funded.
  • Kept the existing buyer lookup coverage intact.

Snapshot Updates

  • [ADD] contracts/escrow/test_snapshots/test_get_escrows_by_buyer/test_buyer_index_populated_on_fund.1.json
  • [MODIFY] contracts/escrow/test_snapshots/test_get_escrows_by_buyer/test_get_escrows_by_buyer.1.json
  • Captures the buyer index writes produced by the updated logic.

Verification Results

Acceptance Criteria Status
Buyer index is populated when escrow is funded by a previously unknown buyer
get_escrows_by_buyer returns the funded escrow for that buyer
Existing buyer lookup coverage still passes
Targeted buyer-index tests pass

How to Test

# Confirm the branch
git branch --show-current

# Run the buyer lookup regression tests
cargo test -p trustlink-escrow test_get_escrows_by_buyer -- --nocapture

# Run the full library test suite
cargo test -p trustlink-escrow --lib

Screenshots

✅ Buyer lookup regression passes

Run:

cargo test -p trustlink-escrow test_get_escrows_by_buyer -- --nocapture
image

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@isaacCodes1 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

Labels

None yet

Projects

None yet

1 participant