|
| 1 | +import { NWCClient } from "../src/nwc/NWCClient"; |
| 2 | +import { createTestWallet } from "./helpers"; |
| 3 | + |
| 4 | +/** |
| 5 | + * E2E test for list_transactions after a successful invoice payment. |
| 6 | + * Requires network access. |
| 7 | + */ |
| 8 | +describe("NWC list_transactions after pay_invoice", () => { |
| 9 | + const AMOUNT_MSATS = 100_000; // 100 sats |
| 10 | + const BALANCE_SATS = 10_000; |
| 11 | + |
| 12 | + let sender: { nwcUrl: string }; |
| 13 | + let receiver: { nwcUrl: string }; |
| 14 | + |
| 15 | + beforeAll(async () => { |
| 16 | + receiver = await createTestWallet(BALANCE_SATS); |
| 17 | + sender = await createTestWallet(BALANCE_SATS); |
| 18 | + }, 60_000); |
| 19 | + |
| 20 | + test( |
| 21 | + "returns an outgoing settled transaction for the paid invoice", |
| 22 | + async () => { |
| 23 | + const receiverClient = new NWCClient({ |
| 24 | + nostrWalletConnectUrl: receiver.nwcUrl, |
| 25 | + }); |
| 26 | + const senderClient = new NWCClient({ nostrWalletConnectUrl: sender.nwcUrl }); |
| 27 | + |
| 28 | + try { |
| 29 | + const invoiceResult = await receiverClient.makeInvoice({ |
| 30 | + amount: AMOUNT_MSATS, |
| 31 | + description: "E2E list_transactions after payment", |
| 32 | + }); |
| 33 | + expect(invoiceResult.invoice).toBeDefined(); |
| 34 | + |
| 35 | + await senderClient.payInvoice({ invoice: invoiceResult.invoice }); |
| 36 | + |
| 37 | + const listResult = await senderClient.listTransactions({ |
| 38 | + limit: 20, |
| 39 | + type: "outgoing", |
| 40 | + }); |
| 41 | + |
| 42 | + expect(Array.isArray(listResult.transactions)).toBe(true); |
| 43 | + |
| 44 | + const matchingTx = listResult.transactions.find( |
| 45 | + (tx) => tx.invoice === invoiceResult.invoice, |
| 46 | + ); |
| 47 | + |
| 48 | + expect(matchingTx).toBeDefined(); |
| 49 | + expect(matchingTx?.type).toBe("outgoing"); |
| 50 | + expect(matchingTx?.state).toBe("settled"); |
| 51 | + expect(matchingTx?.amount).toBe(AMOUNT_MSATS); |
| 52 | + } finally { |
| 53 | + receiverClient.close(); |
| 54 | + senderClient.close(); |
| 55 | + } |
| 56 | + }, |
| 57 | + 60_000, |
| 58 | + ); |
| 59 | +}); |
0 commit comments