import pytest
import glsdk
class TestResponseTypes:
def test_get_info_response_type_exists(self):
assert hasattr(glsdk, "GetInfoResponse")
def test_list_peers_response_type_exists(self):
assert hasattr(glsdk, "ListPeersResponse")
def test_list_peer_channels_response_type_exists(self):
assert hasattr(glsdk, "ListPeerChannelsResponse")
def test_list_funds_response_type_exists(self):
assert hasattr(glsdk, "ListFundsResponse")
def test_peer_type_exists(self):
assert hasattr(glsdk, "Peer")
def test_peer_channel_type_exists(self):
assert hasattr(glsdk, "PeerChannel")
def test_fund_output_type_exists(self):
assert hasattr(glsdk, "FundOutput")
def test_fund_channel_type_exists(self):
assert hasattr(glsdk, "FundChannel")
def test_channel_state_enum_exists(self):
assert hasattr(glsdk, "ChannelState")
assert hasattr(glsdk.ChannelState, "OPENINGD")
assert hasattr(glsdk.ChannelState, "CHANNELD_NORMAL")
assert hasattr(glsdk.ChannelState, "ONCHAIN")
def test_output_status_enum_exists(self):
assert hasattr(glsdk, "OutputStatus")
assert hasattr(glsdk.OutputStatus, "UNCONFIRMED")
assert hasattr(glsdk.OutputStatus, "CONFIRMED")
assert hasattr(glsdk.OutputStatus, "SPENT")
class TestNodeMethods:
def test_node_has_get_info_method(self):
assert hasattr(glsdk.Node, "get_info")
def test_node_has_list_peers_method(self):
assert hasattr(glsdk.Node, "list_peers")
def test_node_has_list_peer_channels_method(self):
assert hasattr(glsdk.Node, "list_peer_channels")
def test_node_has_list_funds_method(self):
assert hasattr(glsdk.Node, "list_funds")
class TestSendResponseFields:
def test_send_response_has_payment_hash(self):
response = glsdk.SendResponse(
status=glsdk.PayStatus.COMPLETE,
preimage=b"\x01" * 32,
payment_hash=b"\x00" * 32,
destination_pubkey=b"\x02" * 33,
amount_msat=1000,
amount_sent_msat=1010,
parts=1,
)
assert response.payment_hash == b"\x00" * 32
assert response.destination_pubkey == b"\x02" * 33
def test_send_response_destination_pubkey_is_optional(self):
response = glsdk.SendResponse(
status=glsdk.PayStatus.COMPLETE,
preimage=b"\x01" * 32,
payment_hash=b"\x00" * 32,
destination_pubkey=None,
amount_msat=1000,
amount_sent_msat=1010,
parts=1,
)
assert response.destination_pubkey is None
class TestResponseTypeFields:
def test_get_info_response_has_expected_fields(self):
response = glsdk.GetInfoResponse(
id=b"\x02" * 33,
alias="test-node",
color=b"\xff\x00\x00",
num_peers=0,
num_pending_channels=0,
num_active_channels=0,
num_inactive_channels=0,
version="v24.11",
lightning_dir="/tmp/lightning",
blockheight=100,
network="regtest",
fees_collected_msat=0,
)
assert response.id == b"\x02" * 33
assert response.alias == "test-node"
assert response.network == "regtest"
assert response.blockheight == 100
def test_list_peers_response_has_peers_field(self):
response = glsdk.ListPeersResponse(peers=[])
assert response.peers == []
def test_list_peer_channels_response_has_channels_field(self):
response = glsdk.ListPeerChannelsResponse(channels=[])
assert response.channels == []
def test_list_funds_response_has_expected_fields(self):
response = glsdk.ListFundsResponse(outputs=[], channels=[])
assert response.outputs == []
assert response.channels == []
def test_peer_record_has_expected_fields(self):
peer = glsdk.Peer(
id=b"\x03" * 33,
connected=True,
num_channels=1,
netaddr=["127.0.0.1:9735"],
remote_addr="192.168.1.1:9735",
features=b"\x00",
)
assert peer.id == b"\x03" * 33
assert peer.connected is True
assert peer.num_channels == 1
assert "127.0.0.1:9735" in peer.netaddr
def test_peer_channel_record_has_expected_fields(self):
channel = glsdk.PeerChannel(
peer_id=b"\x03" * 33,
peer_connected=True,
state=glsdk.ChannelState.CHANNELD_NORMAL,
short_channel_id="123x1x0",
channel_id=b"\x00" * 32,
funding_txid=b"\xab" * 32,
funding_outnum=0,
to_us_msat=500000000,
total_msat=1000000000,
spendable_msat=400000000,
receivable_msat=400000000,
)
assert channel.peer_id == b"\x03" * 33
assert channel.peer_connected is True
assert channel.state == glsdk.ChannelState.CHANNELD_NORMAL
assert channel.total_msat == 1000000000
def test_fund_output_record_has_expected_fields(self):
output = glsdk.FundOutput(
txid=b"\xab" * 32,
output=0,
amount_msat=1000000000,
status=glsdk.OutputStatus.CONFIRMED,
address="bcrt1qtest",
blockheight=100,
)
assert output.txid == b"\xab" * 32
assert output.amount_msat == 1000000000
assert output.status == glsdk.OutputStatus.CONFIRMED
def test_fund_channel_record_has_expected_fields(self):
channel = glsdk.FundChannel(
peer_id=b"\x03" * 33,
our_amount_msat=500000000,
amount_msat=1000000000,
funding_txid=b"\xab" * 32,
funding_output=0,
connected=True,
state=glsdk.ChannelState.CHANNELD_NORMAL,
short_channel_id="123x1x0",
channel_id=b"\x00" * 32,
)
assert channel.peer_id == b"\x03" * 33
assert channel.our_amount_msat == 500000000
assert channel.connected is True