make list_transactions simpler to avoid timeouts

This commit is contained in:
Riccardo Balbo 2025-06-09 18:18:44 +02:00
commit dd1d35b99d

View file

@ -1010,116 +1010,51 @@ async def test_list_transactions():
wallet1 = NWCWallet(nwc1["pairing"])
wallet2 = NWCWallet(nwc2["pairing"])
await wallet1.start()
await wallet2.start()
try:
await wallet1.start()
await wallet2.start()
# Create some transactions with different timestamps
start_time = int(time.time())
# First invoice
await wallet1.send_event(
"make_invoice", {"amount": 1000, "description": "test invoice 1"}
)
result1, _, error = await wallet1.wait_for("make_invoice")
assert not error
invoice1 = result1["invoice"]
# First invoice
await wallet1.send_event(
"make_invoice", {"amount": 100000, "description": "test invoice 1"}
)
result1, _, error = await wallet1.wait_for("make_invoice")
assert not error
invoice1 = result1["invoice"]
# Pay first invoice
await wallet2.send_event("pay_invoice", {"invoice": invoice1})
_, _, error = await wallet2.wait_for("pay_invoice")
assert not error
# Pay first invoice
await wallet2.send_event("pay_invoice", {"invoice": invoice1})
_, _, error = await wallet2.wait_for("pay_invoice")
assert not error
# Second invoice
await wallet1.send_event(
"make_invoice", {"amount": 2000, "description": "test invoice 2"}
)
result2, _, error = await wallet1.wait_for("make_invoice")
assert not error
invoice2 = result2["invoice"]
mid_timestamp = int(time.time())
# Pay second invoice
await wallet2.send_event("pay_invoice", {"invoice": invoice2})
_, _, error = await wallet2.wait_for("pay_invoice")
assert not error
# Second invoice
await wallet1.send_event(
"make_invoice", {"amount": 200000, "description": "test invoice 2"}
)
result2, _, error = await wallet1.wait_for("make_invoice")
assert not error
invoice2 = result2["invoice"]
# Test basic transaction listing
await wallet1.send_event("list_transactions", {})
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
assert "transactions" in result
transactions = result["transactions"]
assert len(transactions) >= 2
# Pay second invoice
await wallet2.send_event("pay_invoice", {"invoice": invoice2})
_, _, error = await wallet2.wait_for("pay_invoice")
assert not error
# Test limit
await wallet1.send_event("list_transactions", {"limit": 1})
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
limited_txs = result["transactions"]
assert len(limited_txs) == 1
# Create an unpaid invoice
await wallet1.send_event(
"make_invoice", {"amount": 300000, "description": "test invoice 3 (unpaid)"}
)
_, _, error = await wallet1.wait_for("make_invoice")
assert not error
end_time = int(time.time())
# Test 1: List all transactions
await wallet1.send_event("list_transactions", {})
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
assert "transactions" in result
transactions = result["transactions"]
# Should have at least 2 paid invoices
assert len(transactions) >= 2
# Verify transaction structure
for tx in transactions:
assert "type" in tx
assert "amount" in tx
assert "created_at" in tx
assert "payment_hash" in tx
# Test 2: Filter by type (incoming)
await wallet1.send_event("list_transactions", {"type": "incoming"})
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
incoming_txs = result["transactions"]
assert all(tx["type"] == "incoming" for tx in incoming_txs)
# Test 3: Filter by time range
await wallet1.send_event(
"list_transactions", {"from": start_time, "until": mid_timestamp}
)
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
early_txs = result["transactions"]
# Should only include transactions from the first time period
for tx in early_txs:
assert tx["created_at"] >= start_time
assert tx["created_at"] <= mid_timestamp
# Test 4: Test limit and offset
await wallet1.send_event("list_transactions", {"limit": 1})
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
limited_txs = result["transactions"]
assert len(limited_txs) == 1
await wallet1.send_event("list_transactions", {"limit": 1, "offset": 1})
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
offset_txs = result["transactions"]
assert len(offset_txs) == 1
# Should be different transactions
assert offset_txs[0]["payment_hash"] != limited_txs[0]["payment_hash"]
# Test 5: Include unpaid invoices
await wallet1.send_event("list_transactions", {"unpaid": True})
result, _, error = await wallet1.wait_for("list_transactions")
assert not error
all_txs = result["transactions"]
# Should find at least one unpaid invoice
assert any(tx.get("settled_at") is None for tx in all_txs)
# Test 6: Check outgoing transactions from wallet2
await wallet2.send_event("list_transactions", {"type": "outgoing"})
result, _, error = await wallet2.wait_for("list_transactions")
assert not error
outgoing_txs = result["transactions"]
assert all(tx["type"] == "outgoing" for tx in outgoing_txs)
assert len(outgoing_txs) >= 2
# Cleanup
await wallet1.close()
await wallet2.close()
finally:
await wallet1.close()
await wallet2.close()