Skip to content

feat: validate expired bid cleanup semantics#752

Merged
Baskarayelu merged 7 commits intoQuickLendX:mainfrom
Agbasimere:feature/expired-bid-cleanup-semantics
Apr 1, 2026
Merged

feat: validate expired bid cleanup semantics#752
Baskarayelu merged 7 commits intoQuickLendX:mainfrom
Agbasimere:feature/expired-bid-cleanup-semantics

Conversation

@Agbasimere
Copy link
Copy Markdown
Contributor

Closes: #710

Summary

Improved the robustness, accuracy, and idempotency of the cleanup_expired_bids mechanism to ensure reliable bid index hygiene and precise reporting of cleaned records.

Key Changes

  • Refactored refresh_expired_bids in src/bid.rs:
    • Enhanced the cleanup loop to handle already-expired bids and orphaned bid IDs (IDs present in the index but with missing records).
    • Updated the function to return a precise count of items cleaned from the invoice's internal bid index.
    • Optimized storage writes by only updating the invoice's bid record if changes were actually made (idempotency).
  • Added Comprehensive Tests:
    • test_cleanup_expired_bids_with_pre_set_expired: Verified that bids already transitioned to Expired but still in the index are correctly handled and counted.
    • test_cleanup_expired_bids_partial_idempotency: Validated partial cleanup across multiple TTL windows and confirmed 0 results on repeated calls.
    • test_cleanup_expired_bids_integration: Demonstrated correct index pruning over 7+ days of placement history.
  • Fixed Infrastructure/Test Failures:
    • Resolved a syntax error (extra bracket) at the end of src/test_bid.rs.
    • Fixed missing unwrap() calls on get_invoice() results in the test suite to match the current contract API.
  • Documentation:
    • Updated docs/contracts/bidding.md with a new section for the Cleanup Mechanism, detailing the public function and its return semantics.

Testing Performed

  • Ran targeted unit tests: cargo test -p quicklendx-contracts test_cleanup_expired_bids
  • Verified return count accuracy: Expecting 1 for a single expired bid and 0 for immediate subsequent calls.
  • Validated state transitions: Confirmed Placed bids correctly transition to Expired when the TTL is exceeded.

Security Considerations

  • The cleanup_expired_bids function remains public but read-and-delete only on the target invoice index, preventing manipulation of active bids.
  • Bounded loops ensure that even if the MAX_BIDS_PER_INVOICE limit is reached, the cleanup operation remains gas-efficient.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

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

@Agbasimere
Copy link
Copy Markdown
Contributor Author

@Baskarayelu Kindly merge

@Baskarayelu Baskarayelu merged commit 6d9a1b8 into QuickLendX:main Apr 1, 2026
1 check failed
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.

Validate cleanup_expired_bids return count and idempotent cleanup

2 participants