cardano-api: strip 'Fix #N:' audit-ticket prefixes from inline comments (was 50+ in main.py), drop hardening-pass changelog blocks from module docstring, rewrite README to drop deploy paths + marketing sections, keep tier/auth/TTL + policy IDs. cardano-checkout-py: drop TradeCraft lineage refs, swap chromaticcraft/tradecraft test fixtures for acme/globex, repository URL → git.sulkta.com.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""Invoice dataclass + state machine tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
from cardano_checkout.invoice import Invoice, InvoiceStatus
|
|
|
|
|
|
def _make() -> Invoice:
|
|
return Invoice(
|
|
id="inv_001",
|
|
merchant_id="acme",
|
|
derivation_index=0,
|
|
receive_address="addr1...",
|
|
expected_lovelace=5_000_000, # 5 ADA
|
|
usd_amount=2.50,
|
|
)
|
|
|
|
|
|
def test_defaults_are_pending_and_non_terminal() -> None:
|
|
inv = _make()
|
|
assert inv.status == InvoiceStatus.PENDING
|
|
assert inv.is_terminal is False
|
|
assert inv.ada_amount == 5.0
|
|
|
|
|
|
def test_terminal_states() -> None:
|
|
for s in (InvoiceStatus.CONFIRMED, InvoiceStatus.EXPIRED, InvoiceStatus.CANCELLED):
|
|
inv = _make()
|
|
inv.status = s
|
|
assert inv.is_terminal is True
|
|
|
|
|
|
def test_is_expired_honors_expires_at() -> None:
|
|
past = datetime.now(timezone.utc) - timedelta(minutes=5)
|
|
future = datetime.now(timezone.utc) + timedelta(minutes=5)
|
|
|
|
inv = _make()
|
|
inv.expires_at = past
|
|
assert inv.is_expired() is True
|
|
|
|
inv.expires_at = future
|
|
assert inv.is_expired() is False
|
|
|
|
# Confirmed invoices are never "expired" regardless of timestamp
|
|
inv.expires_at = past
|
|
inv.status = InvoiceStatus.CONFIRMED
|
|
assert inv.is_expired() is False
|