v0.1.0-dev: initial public extraction + new abstractions
This commit is contained in:
commit
e38120cf11
17 changed files with 2429 additions and 0 deletions
49
tests/test_invoice.py
Normal file
49
tests/test_invoice.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
"""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="example-studio",
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue