fix: prevent duplicate invoice ID double payment in payInvoicesBatch - #203
Open
g-k-s-03 wants to merge 1 commit into
Open
fix: prevent duplicate invoice ID double payment in payInvoicesBatch#203g-k-s-03 wants to merge 1 commit into
g-k-s-03 wants to merge 1 commit into
Conversation
Merge the validate and mark-paid loops in payInvoicesBatch into a single pass so isPaid is set immediately after the isPaid/isCancelled check for each id. Previously validation and mark-paid ran in separate loops, so a duplicate id in the batch would pass validation twice before either occurrence was marked paid, causing the payout loop to transfer funds to the same invoice's issuer twice. Adds a regression test asserting payInvoicesBatch reverts with AlreadySettled when the input array contains a duplicate invoice id. Fixes StabilityNexus#202 Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
Contributor
|
Warning Review limit reachedNext included review available in 39 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Fixes #202
Bug
payInvoicesBatch()validated all invoice IDs in one loop (checkingisPaid/isCancelled) before marking any of them paid in a separate,later loop. If the input array contained a duplicate invoice ID, both
occurrences passed validation since neither had been marked paid yet —
causing the payout loop to transfer funds twice for the same invoice.
Fix
Merged the validate and mark-paid loops into a single pass, so
invoices[id].isPaid = trueis set immediately after the isPaid/isCancelledcheck for that id, in the same iteration. A duplicate id's second occurrence
now correctly reverts on its second pass through the loop.
Testing
Added
testPayInvoicesBatch_RevertOnDuplicateId(), which creates an invoiceand calls
payInvoicesBatchwith a duplicate id, asserting it revertsinstead of double-paying.