import pytest
import glsdk
class TestEventStreamTypes:
def test_node_event_stream_type_exists(self):
assert hasattr(glsdk, "NodeEventStream")
def test_node_event_type_exists(self):
assert hasattr(glsdk, "NodeEvent")
def test_invoice_paid_event_type_exists(self):
assert hasattr(glsdk, "InvoicePaidEvent")
def test_node_event_has_invoice_paid_variant(self):
assert hasattr(glsdk.NodeEvent, "INVOICE_PAID")
def test_node_event_has_unknown_variant(self):
assert hasattr(glsdk.NodeEvent, "UNKNOWN")
def test_node_has_stream_node_events_method(self):
assert hasattr(glsdk.Node, "stream_node_events")
def test_node_event_stream_has_next_method(self):
assert hasattr(glsdk.NodeEventStream, "next")
class TestInvoicePaidEventFields:
def test_invoice_paid_event_can_be_constructed(self):
event = glsdk.InvoicePaidEvent(
payment_hash=b"\x00" * 32,
bolt11="lnbcrt1...",
preimage=b"\x01" * 32,
label="test-invoice",
amount_msat=100000,
)
assert event.payment_hash == b"\x00" * 32
assert event.bolt11 == "lnbcrt1..."
assert event.preimage == b"\x01" * 32
assert event.label == "test-invoice"
assert event.amount_msat == 100000
def test_invoice_paid_event_str(self):
event = glsdk.InvoicePaidEvent(
payment_hash=b"\x00" * 32,
bolt11="lnbcrt1...",
preimage=b"\x01" * 32,
label="test-invoice",
amount_msat=100000,
)
str_repr = str(event)
assert "InvoicePaidEvent" in str_repr
assert "test-invoice" in str_repr
class TestNodeEventVariants:
def test_invoice_paid_variant_construction(self):
details = glsdk.InvoicePaidEvent(
payment_hash=b"\x00" * 32,
bolt11="lnbcrt1...",
preimage=b"\x01" * 32,
label="test-invoice",
amount_msat=100000,
)
event = glsdk.NodeEvent.INVOICE_PAID(details=details)
assert event.details == details
def test_unknown_variant_construction(self):
event = glsdk.NodeEvent.UNKNOWN()
assert event is not None
def test_invoice_paid_is_invoice_paid(self):
details = glsdk.InvoicePaidEvent(
payment_hash=b"\x00" * 32,
bolt11="lnbcrt1...",
preimage=b"\x01" * 32,
label="test-invoice",
amount_msat=100000,
)
event = glsdk.NodeEvent.INVOICE_PAID(details=details)
assert event.is_invoice_paid()
assert not event.is_unknown()
def test_unknown_is_unknown(self):
event = glsdk.NodeEvent.UNKNOWN()
assert event.is_unknown()
assert not event.is_invoice_paid()