Skip to content

Prevent duplicate payment#105

Merged
Cedarich merged 2 commits intoZyntariHQ:mainfrom
Kaylahray:prevent-duplicate-payment
Mar 7, 2026
Merged

Prevent duplicate payment#105
Cedarich merged 2 commits intoZyntariHQ:mainfrom
Kaylahray:prevent-duplicate-payment

Conversation

@Kaylahray
Copy link
Copy Markdown
Contributor

Prevent duplicate payments for the same invoice

Closes #89

What changed

  • lib.rsrecord_payment already contains an idempotency guard at step 4
    (has_payment check → ContractError::PaymentAlreadyRecorded). No logic change
    needed; the guard was verified to fire before any state mutation or event emission.

  • test.rs — Added three new acceptance-criteria tests under the section
    // Prevent duplicate payments — acceptance-criteria tests:

    Test What it proves
    test_first_payment_succeeds_emits_event_and_increments_count Happy path: first record_payment stores the record, emits invoice_payment_recorded, and increments payment_count to 1.
    test_duplicate_payment_fails_no_event_count_unchanged Duplicate: second call with the same invoice_id reverts with PaymentAlreadyRecorded, emits no event, and leaves payment_count unchanged.
    test_cross_asset_duplicate_same_invoice_id_fails Cross-asset: same invoice_id with a different asset (XLM → USDC) also reverts with PaymentAlreadyRecordedinvoice_id is the sole uniqueness key.

Acceptance criteria satisfied

  • ✅ Duplicate invoice_id reliably reverts with ContractError::PaymentAlreadyRecorded
  • ✅ No payment_recorded event emitted on failure; success path unchanged
  • ✅ State (count, storage) is not mutated on a failed duplicate attempt
  • ✅ Cross-asset replay with same invoice_id is also rejected
  • ✅ No additional storage writes on failed duplicates — gas unaffected

Copy link
Copy Markdown
Contributor

@Cedarich Cedarich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Cedarich Cedarich merged commit 7010d23 into ZyntariHQ:main Mar 7, 2026
1 check passed
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.

Enforce Idempotency and Duplicate Protection in record_payment

2 participants