Skip to content

Add expires_at field to invoices and reject payments on expired invoices#129

Open
AlonsoFi wants to merge 1 commit intoShadeProtocol:mainfrom
AlonsoFi:feature/invoice-expiry
Open

Add expires_at field to invoices and reject payments on expired invoices#129
AlonsoFi wants to merge 1 commit intoShadeProtocol:mainfrom
AlonsoFi:feature/invoice-expiry

Conversation

@AlonsoFi
Copy link

Closes: #114

Description

Add invoice expiry support via an optional expires_at: Option field on
invoices. When set, pay_invoice rejects payments after the expiry timestamp
with a new InvoiceExpired error. When None, invoices remain payable
indefinitely (backward-compatible).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • Documentation update
  • Code refactoring
  • Test improvements
  • Other (please describe):

Related Issues

Fixes

Changes Made

  • Added expires_at: Option field to the Invoice struct in types.rs
  • Added InvoiceExpired = 21 variant to ContractError in errors.rs
  • Updated create_invoice and create_invoice_signed signatures in interface.rs,
    shade.rs, and components/invoice.rs to accept the new parameter
  • Added expiry validation in pay_invoice: rejects payment if
    env.ledger().timestamp() > expires_at
  • Updated signature_util.rs to include expires_at in the signed message
    (build_message and verify_invoice_signature)
  • Updated all existing test call sites (~66 calls) across 7 test files to pass
    &None as expires_at
  • Updated build_test_message and sign_invoice test helpers to include
    expires_at in signature construction
  • Created test_invoice_expiry.rs with 3 new tests and registered it in
    tests/mod.rs

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • All existing tests pass locally
  • I have tested this manually

New tests in test_invoice_expiry.rs:

  • test_pay_expired_invoice_fails — creates invoice with expiry, advances
    ledger past it, asserts payment panics with InvoiceExpired (Create Comprehensive Tests for Merchant Public Key Management #21)
  • test_pay_invoice_before_expiry_succeeds — creates invoice with expiry, pays
    before it, asserts success
  • test_invoice_no_expiry_always_payable — creates invoice with None expiry,
    pays at a far-future timestamp, asserts success

Result: 150 tests pass (118 shade + 32 account), 0 failures.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

The expires_at parameter is fully optional. Passing None preserves the
previous behavior — invoices without an expiry are payable at any time. The
expiry is also included in the signed message for create_invoice_signed,
ensuring it cannot be tampered with.

@codebestia
Copy link
Collaborator

@AlonsoFi Fix the Ci and resolve the conflicts.

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.

Create Comprehensive Tests for Invoice Expiry

2 participants