Skip to content

feat: add invoice view functions and fee_paid event test - #643

Open
fejilaup-cloud wants to merge 4 commits into
Stellar-split:mainfrom
fejilaup-cloud:implement/issues-587-590-view-functions-and-tests
Open

feat: add invoice view functions and fee_paid event test#643
fejilaup-cloud wants to merge 4 commits into
Stellar-split:mainfrom
fejilaup-cloud:implement/issues-587-590-view-functions-and-tests

Conversation

@fejilaup-cloud

Copy link
Copy Markdown

Summary

Implement four critical view functions and event test for the split-contracts invoice system:

Changes

View Functions (Contracts)

  • get_invoice_deadline(invoice_id) -> Result<u64>: Enables efficient frontend expiry countdown UI
  • get_invoice_funded(invoice_id) -> Result<i128>: Enables efficient payment UI polling
  • get_invoice_status(invoice_id) -> Result<InvoiceStatus>: Reduces data fetched for status checks

All three functions:

  • Return ContractError::InvoiceNotFound for unknown invoice IDs
  • Check InvoiceHot (instance storage) first, fall back to InvoiceCore (persistent storage)
  • Include comprehensive unit tests with success and error cases

Event Test

  • Test fee_paid event in tests/event_log_tests.rs
  • Verifies amount and treasury address fields are correctly populated
  • Critical for financial auditing and transaction validation

Test Plan

  • Unit tests for all three view functions verify correct values
  • Error handling tests confirm InvoiceNotFound is returned for invalid IDs
  • Fee paid event test validates event structure and data accuracy
  • All tests follow existing patterns and conventions in the codebase

Closes #590
Closes #589
Closes #588
Closes #587

- Add get_invoice_deadline(invoice_id: u64) -> Result<u64, ContractError>
- Returns deadline timestamp from InvoiceCore
- Returns ContractError::InvoiceNotFound for unknown invoice IDs
- Includes unit tests verifying deadline value and error handling
- Enables efficient frontend expiry countdown UI without loading full struct

Closes Stellar-split#590
- Add get_invoice_funded(invoice_id: u64) -> Result<i128, ContractError>
- Reads funded amount from InvoiceHot (instance storage) if available, falls back to InvoiceCore
- Returns ContractError::InvoiceNotFound if invoice does not exist
- Includes unit tests verifying funded value increases after payment and error handling
- Enables efficient polling by payment UIs without loading full struct

Closes Stellar-split#589
- Add get_invoice_status(invoice_id: u64) -> Result<InvoiceStatus, ContractError>
- Loads only the InvoiceHot (or InvoiceCore) struct and returns status field
- Returns ContractError::InvoiceNotFound if invoice does not exist
- Includes unit tests verifying correct status for Pending and Released invoices
- Reduces data fetched and makes intent explicit for clients and integrations

Closes Stellar-split#588
- Add test named fee_paid_event_carries_amount_and_treasury in event_log_tests.rs
- Generate random treasury address and verify fee_paid event emits correct fields
- Assert amount and treasury address match what was passed to fee_paid function
- Treasury address is critical for financial auditing

Closes Stellar-split#587
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@fejilaup-cloud 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