Skip to content

Commit e5e46cf

Browse files
committed
add list_transactions test
1 parent eb0ac9d commit e5e46cf

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

tests/integration/test_all.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,3 +992,130 @@ async def create_valid_invoice(wallet, amount=1000):
992992
if error:
993993
raise Exception(f"Failed to create invoice: {error}")
994994
return result["invoice"]
995+
996+
@pytest.mark.asyncio
997+
async def test_list_transactions():
998+
# Create wallets with required permissions
999+
nwc1 = await create_nwc(
1000+
"wallet1", "test_list_transactions", ["invoice", "pay", "balance", "transactions"], [], 0
1001+
)
1002+
nwc2 = await create_nwc(
1003+
"wallet2", "test_list_transactions", ["invoice", "pay", "balance", "transactions"], [], 0
1004+
)
1005+
1006+
wallet1 = NWCWallet(nwc1["pairing"])
1007+
wallet2 = NWCWallet(nwc2["pairing"])
1008+
1009+
await wallet1.start()
1010+
await wallet2.start()
1011+
1012+
# Create some transactions with different timestamps
1013+
start_time = int(time.time())
1014+
1015+
# First invoice
1016+
await wallet1.send_event(
1017+
"make_invoice", {"amount": 100000, "description": "test invoice 1"}
1018+
)
1019+
result1, _, error = await wallet1.wait_for("make_invoice")
1020+
assert not error
1021+
invoice1 = result1["invoice"]
1022+
1023+
# Pay first invoice
1024+
await wallet2.send_event("pay_invoice", {"invoice": invoice1})
1025+
_, _, error = await wallet2.wait_for("pay_invoice")
1026+
assert not error
1027+
1028+
mid_timestamp = int(time.time())
1029+
1030+
# Second invoice
1031+
await wallet1.send_event(
1032+
"make_invoice", {"amount": 200000, "description": "test invoice 2"}
1033+
)
1034+
result2, _, error = await wallet1.wait_for("make_invoice")
1035+
assert not error
1036+
invoice2 = result2["invoice"]
1037+
1038+
# Pay second invoice
1039+
await wallet2.send_event("pay_invoice", {"invoice": invoice2})
1040+
_, _, error = await wallet2.wait_for("pay_invoice")
1041+
assert not error
1042+
1043+
# Create an unpaid invoice
1044+
await wallet1.send_event(
1045+
"make_invoice", {"amount": 300000, "description": "test invoice 3 (unpaid)"}
1046+
)
1047+
_, _, error = await wallet1.wait_for("make_invoice")
1048+
assert not error
1049+
1050+
end_time = int(time.time())
1051+
1052+
# Test 1: List all transactions
1053+
await wallet1.send_event("list_transactions", {})
1054+
result, _, error = await wallet1.wait_for("list_transactions")
1055+
assert not error
1056+
assert "transactions" in result
1057+
transactions = result["transactions"]
1058+
1059+
# Should have at least 2 paid invoices
1060+
assert len(transactions) >= 2
1061+
1062+
# Verify transaction structure
1063+
for tx in transactions:
1064+
assert "type" in tx
1065+
assert "amount" in tx
1066+
assert "created_at" in tx
1067+
assert "payment_hash" in tx
1068+
1069+
# Test 2: Filter by type (incoming)
1070+
await wallet1.send_event("list_transactions", {"type": "incoming"})
1071+
result, _, error = await wallet1.wait_for("list_transactions")
1072+
assert not error
1073+
incoming_txs = result["transactions"]
1074+
assert all(tx["type"] == "incoming" for tx in incoming_txs)
1075+
1076+
# Test 3: Filter by time range
1077+
await wallet1.send_event(
1078+
"list_transactions", {"from": start_time, "until": mid_timestamp}
1079+
)
1080+
result, _, error = await wallet1.wait_for("list_transactions")
1081+
assert not error
1082+
early_txs = result["transactions"]
1083+
# Should only include transactions from the first time period
1084+
for tx in early_txs:
1085+
assert tx["created_at"] >= start_time
1086+
assert tx["created_at"] <= mid_timestamp
1087+
1088+
# Test 4: Test limit and offset
1089+
await wallet1.send_event("list_transactions", {"limit": 1})
1090+
result, _, error = await wallet1.wait_for("list_transactions")
1091+
assert not error
1092+
limited_txs = result["transactions"]
1093+
assert len(limited_txs) == 1
1094+
1095+
await wallet1.send_event("list_transactions", {"limit": 1, "offset": 1})
1096+
result, _, error = await wallet1.wait_for("list_transactions")
1097+
assert not error
1098+
offset_txs = result["transactions"]
1099+
assert len(offset_txs) == 1
1100+
# Should be different transactions
1101+
assert offset_txs[0]["payment_hash"] != limited_txs[0]["payment_hash"]
1102+
1103+
# Test 5: Include unpaid invoices
1104+
await wallet1.send_event("list_transactions", {"unpaid": True})
1105+
result, _, error = await wallet1.wait_for("list_transactions")
1106+
assert not error
1107+
all_txs = result["transactions"]
1108+
# Should find at least one unpaid invoice
1109+
assert any(tx.get("settled_at") is None for tx in all_txs)
1110+
1111+
# Test 6: Check outgoing transactions from wallet2
1112+
await wallet2.send_event("list_transactions", {"type": "outgoing"})
1113+
result, _, error = await wallet2.wait_for("list_transactions")
1114+
assert not error
1115+
outgoing_txs = result["transactions"]
1116+
assert all(tx["type"] == "outgoing" for tx in outgoing_txs)
1117+
assert len(outgoing_txs) >= 2
1118+
1119+
# Cleanup
1120+
await wallet1.close()
1121+
await wallet2.close()

0 commit comments

Comments
 (0)