From 04858070ab53cb5308e93f569ab6d07c9a34a774 Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Wed, 18 Feb 2026 18:05:09 +0300 Subject: [PATCH 01/10] feat: add NWC faucet integration test --- src/test/helpers.ts | 51 +++++++++++++++++++++++++++++++++++++ src/test/nwc-faucet.test.ts | 27 ++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/test/helpers.ts create mode 100644 src/test/nwc-faucet.test.ts diff --git a/src/test/helpers.ts b/src/test/helpers.ts new file mode 100644 index 00000000..16b5af18 --- /dev/null +++ b/src/test/helpers.ts @@ -0,0 +1,51 @@ +/** + * Test helpers for integration tests using the NWC faucet. + * @see https://github.com/getAlby/cli/tree/master/src/test + */ + +export interface TestWallet { + nwcUrl: string; + lightningAddress: string; +} + +const FAUCET_URL = "https://faucet.nwc.dev"; + +/** + * Creates a test wallet via the NWC faucet with the given balance in sats. + * Retries on failure (faucet can be rate-limited or temporarily unavailable). + */ +export async function createTestWallet( + balanceSats = 10_000, + retries = 5, +): Promise { + for (let i = 0; i < retries; i++) { + try { + const response = await fetch(`${FAUCET_URL}?balance=${balanceSats}`, { + method: "POST", + }); + if (!response.ok) { + if (i < retries - 1) { + await new Promise((r) => setTimeout(r, 2000 * (i + 1))); + continue; + } + throw new Error(`Faucet request failed: ${response.status}`); + } + const nwcUrl = (await response.text()).trim(); + const lud16Match = nwcUrl.match(/lud16=([^&\s]+)/); + if (!lud16Match) { + throw new Error("No lud16 in NWC URL"); + } + return { + nwcUrl, + lightningAddress: decodeURIComponent(lud16Match[1]), + }; + } catch (error) { + if (i < retries - 1) { + await new Promise((r) => setTimeout(r, 2000 * (i + 1))); + continue; + } + throw error; + } + } + throw new Error("Failed to create test wallet"); +} diff --git a/src/test/nwc-faucet.test.ts b/src/test/nwc-faucet.test.ts new file mode 100644 index 00000000..2fa48377 --- /dev/null +++ b/src/test/nwc-faucet.test.ts @@ -0,0 +1,27 @@ +import "websocket-polyfill"; +import { NWCClient } from "../nwc/NWCClient"; +import { createTestWallet } from "./helpers"; + +/** + * Integration test using the NWC faucet. + * Creates a wallet with 10_000 sats and verifies the balance via get_balance. + * Requires network access. + */ +describe("NWC faucet integration", () => { + const EXPECTED_BALANCE_SATS = 10_000; + const EXPECTED_BALANCE_MSATS = EXPECTED_BALANCE_SATS * 1000; + + test( + "creates wallet via faucet and balance is 10_000 sats", + async () => { + const { nwcUrl } = await createTestWallet(EXPECTED_BALANCE_SATS); + + const nwc = new NWCClient({ nostrWalletConnectUrl: nwcUrl }); + const result = await nwc.getBalance(); + nwc.close(); + + expect(result.balance).toBe(EXPECTED_BALANCE_MSATS); + }, + 30_000, + ); +}); From 61c7fa634629522f7e0cb37d66559a55436ba7a6 Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Thu, 19 Feb 2026 09:46:17 +0300 Subject: [PATCH 02/10] refactor(test): move NWC faucet test to e2e directory --- e2e/nwc-faucet.test.ts | 1 + src/test/helpers.ts | 51 ------------------------------------- src/test/nwc-faucet.test.ts | 27 -------------------- 3 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 src/test/helpers.ts delete mode 100644 src/test/nwc-faucet.test.ts diff --git a/e2e/nwc-faucet.test.ts b/e2e/nwc-faucet.test.ts index 4e3c2d55..c70e5053 100644 --- a/e2e/nwc-faucet.test.ts +++ b/e2e/nwc-faucet.test.ts @@ -1,3 +1,4 @@ +import "websocket-polyfill"; import { NWCClient } from "../src/nwc/NWCClient"; import { createTestWallet } from "./helpers"; diff --git a/src/test/helpers.ts b/src/test/helpers.ts deleted file mode 100644 index 16b5af18..00000000 --- a/src/test/helpers.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Test helpers for integration tests using the NWC faucet. - * @see https://github.com/getAlby/cli/tree/master/src/test - */ - -export interface TestWallet { - nwcUrl: string; - lightningAddress: string; -} - -const FAUCET_URL = "https://faucet.nwc.dev"; - -/** - * Creates a test wallet via the NWC faucet with the given balance in sats. - * Retries on failure (faucet can be rate-limited or temporarily unavailable). - */ -export async function createTestWallet( - balanceSats = 10_000, - retries = 5, -): Promise { - for (let i = 0; i < retries; i++) { - try { - const response = await fetch(`${FAUCET_URL}?balance=${balanceSats}`, { - method: "POST", - }); - if (!response.ok) { - if (i < retries - 1) { - await new Promise((r) => setTimeout(r, 2000 * (i + 1))); - continue; - } - throw new Error(`Faucet request failed: ${response.status}`); - } - const nwcUrl = (await response.text()).trim(); - const lud16Match = nwcUrl.match(/lud16=([^&\s]+)/); - if (!lud16Match) { - throw new Error("No lud16 in NWC URL"); - } - return { - nwcUrl, - lightningAddress: decodeURIComponent(lud16Match[1]), - }; - } catch (error) { - if (i < retries - 1) { - await new Promise((r) => setTimeout(r, 2000 * (i + 1))); - continue; - } - throw error; - } - } - throw new Error("Failed to create test wallet"); -} diff --git a/src/test/nwc-faucet.test.ts b/src/test/nwc-faucet.test.ts deleted file mode 100644 index 2fa48377..00000000 --- a/src/test/nwc-faucet.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import "websocket-polyfill"; -import { NWCClient } from "../nwc/NWCClient"; -import { createTestWallet } from "./helpers"; - -/** - * Integration test using the NWC faucet. - * Creates a wallet with 10_000 sats and verifies the balance via get_balance. - * Requires network access. - */ -describe("NWC faucet integration", () => { - const EXPECTED_BALANCE_SATS = 10_000; - const EXPECTED_BALANCE_MSATS = EXPECTED_BALANCE_SATS * 1000; - - test( - "creates wallet via faucet and balance is 10_000 sats", - async () => { - const { nwcUrl } = await createTestWallet(EXPECTED_BALANCE_SATS); - - const nwc = new NWCClient({ nostrWalletConnectUrl: nwcUrl }); - const result = await nwc.getBalance(); - nwc.close(); - - expect(result.balance).toBe(EXPECTED_BALANCE_MSATS); - }, - 30_000, - ); -}); From 83411904bc47f17b9375284eb7a57757b2c55b27 Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Fri, 20 Feb 2026 16:11:35 +0300 Subject: [PATCH 03/10] feat(e2e): add nwc-pay-invoice test --- e2e/nwc-pay-invoice.test.ts | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 e2e/nwc-pay-invoice.test.ts diff --git a/e2e/nwc-pay-invoice.test.ts b/e2e/nwc-pay-invoice.test.ts new file mode 100644 index 00000000..b8858f3c --- /dev/null +++ b/e2e/nwc-pay-invoice.test.ts @@ -0,0 +1,47 @@ +import "websocket-polyfill"; +import { NWCClient } from "../src/nwc/NWCClient"; +import { createTestWallet } from "./helpers"; + +/** + * E2E test for make_invoice and pay_invoice using the NWC faucet. + * Requires network access. + */ +describe("NWC make_invoice and pay_invoice", () => { + const AMOUNT_MSATS = 100_000; // 100 sats + const BALANCE_SATS = 10_000; + + let sender: { nwcUrl: string }; + let receiver: { nwcUrl: string }; + + beforeAll(async () => { + receiver = await createTestWallet(BALANCE_SATS, 3); + sender = await createTestWallet(BALANCE_SATS, 3); + }, 60_000); + + test( + "receiver creates invoice, sender pays it", + async () => { + const receiverClient = new NWCClient({ nostrWalletConnectUrl: receiver.nwcUrl }); + const senderClient = new NWCClient({ nostrWalletConnectUrl: sender.nwcUrl }); + + try { + const invoiceResult = await receiverClient.makeInvoice({ + amount: AMOUNT_MSATS, + description: "E2E test invoice", + }); + expect(invoiceResult.invoice).toBeDefined(); + expect(invoiceResult.invoice).toMatch(/^ln/); + + const payResult = await senderClient.payInvoice({ + invoice: invoiceResult.invoice, + }); + expect(payResult.preimage).toBeDefined(); + expect(typeof payResult.preimage).toBe("string"); + } finally { + receiverClient.close(); + senderClient.close(); + } + }, + 60_000, + ); +}); From e2dee77c468fff665417d7aa8b9cb935faccad76 Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Fri, 20 Feb 2026 16:20:44 +0300 Subject: [PATCH 04/10] feat(e2e): add nwc-lookup-invoice test --- e2e/nwc-lookup-invoice.test.ts | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 e2e/nwc-lookup-invoice.test.ts diff --git a/e2e/nwc-lookup-invoice.test.ts b/e2e/nwc-lookup-invoice.test.ts new file mode 100644 index 00000000..ebc63eff --- /dev/null +++ b/e2e/nwc-lookup-invoice.test.ts @@ -0,0 +1,48 @@ +import "websocket-polyfill"; +import { NWCClient } from "../src/nwc/NWCClient"; +import { createTestWallet } from "./helpers"; + +/** + * E2E test for lookup_invoice using the NWC faucet. + * Requires network access. + */ +describe("NWC lookup_invoice", () => { + const AMOUNT_MSATS = 100_000; // 100 sats + const BALANCE_SATS = 10_000; + + let sender: { nwcUrl: string }; + let receiver: { nwcUrl: string }; + + beforeAll(async () => { + receiver = await createTestWallet(BALANCE_SATS, 3); + sender = await createTestWallet(BALANCE_SATS, 3); + }, 60_000); + + test( + "finds paid invoice by invoice string", + async () => { + const receiverClient = new NWCClient({ nostrWalletConnectUrl: receiver.nwcUrl }); + const senderClient = new NWCClient({ nostrWalletConnectUrl: sender.nwcUrl }); + + try { + const invoiceResult = await receiverClient.makeInvoice({ + amount: AMOUNT_MSATS, + description: "E2E lookup test", + }); + expect(invoiceResult.invoice).toBeDefined(); + + await senderClient.payInvoice({ invoice: invoiceResult.invoice }); + + const lookupResult = await receiverClient.lookupInvoice({ + invoice: invoiceResult.invoice, + }); + expect(lookupResult.payment_hash).toBeDefined(); + expect(lookupResult.invoice).toBe(invoiceResult.invoice); + } finally { + receiverClient.close(); + senderClient.close(); + } + }, + 60_000, + ); +}); From afc8342af2282ed04f73b164a92fac2d9bbf3a69 Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Fri, 20 Feb 2026 16:38:08 +0300 Subject: [PATCH 05/10] feat(e2e): add nwc-pay-keysend test --- e2e/nwc-pay-keysend.test.ts | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 e2e/nwc-pay-keysend.test.ts diff --git a/e2e/nwc-pay-keysend.test.ts b/e2e/nwc-pay-keysend.test.ts new file mode 100644 index 00000000..0d02de06 --- /dev/null +++ b/e2e/nwc-pay-keysend.test.ts @@ -0,0 +1,44 @@ +import "websocket-polyfill"; +import { NWCClient } from "../src/nwc/NWCClient"; +import { createTestWallet } from "./helpers"; + +/** + * E2E test for pay_keysend using the NWC faucet. + * Requires network access. + */ +describe("NWC pay_keysend", () => { + const AMOUNT_MSATS = 100_000; // 100 sats + const BALANCE_SATS = 10_000; + + let sender: { nwcUrl: string }; + let receiver: { nwcUrl: string }; + + beforeAll(async () => { + receiver = await createTestWallet(BALANCE_SATS, 3); + sender = await createTestWallet(BALANCE_SATS, 3); + }, 60_000); + + test( + "sends keysend payment to receiver pubkey", + async () => { + const receiverClient = new NWCClient({ nostrWalletConnectUrl: receiver.nwcUrl }); + const senderClient = new NWCClient({ nostrWalletConnectUrl: sender.nwcUrl }); + + try { + const infoResult = await receiverClient.getInfo(); + expect(infoResult.pubkey).toBeDefined(); + + const keysendResult = await senderClient.payKeysend({ + amount: AMOUNT_MSATS, + pubkey: infoResult.pubkey, + }); + expect(keysendResult.preimage).toBeDefined(); + expect(typeof keysendResult.preimage).toBe("string"); + } finally { + receiverClient.close(); + senderClient.close(); + } + }, + 60_000, + ); +}); From ae0810970c065ab1f8b921321fd7de663d23088a Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Fri, 20 Feb 2026 16:40:29 +0300 Subject: [PATCH 06/10] feat(e2e): run Jest e2e tests serially to avoid faucet rate limit --- jest.e2e.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.e2e.config.ts b/jest.e2e.config.ts index 6b2a6036..35afca4f 100644 --- a/jest.e2e.config.ts +++ b/jest.e2e.config.ts @@ -4,4 +4,5 @@ export default { testEnvironment: 'node', testMatch: ['/e2e/**/*.test.ts'], testPathIgnorePatterns: ['/node_modules/', '/e2e/browser'], + maxWorkers: 1, // Run e2e tests serially to avoid faucet rate limiting }; From fdb557447e001be72f62e6c19cf2029a94b634c7 Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Fri, 20 Mar 2026 16:07:09 +0300 Subject: [PATCH 07/10] feat(e2e): added nwc-list-transactions-after-payment-test --- ...wc-list-transactions-after-payment.test.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 e2e/nwc-list-transactions-after-payment.test.ts diff --git a/e2e/nwc-list-transactions-after-payment.test.ts b/e2e/nwc-list-transactions-after-payment.test.ts new file mode 100644 index 00000000..5907602a --- /dev/null +++ b/e2e/nwc-list-transactions-after-payment.test.ts @@ -0,0 +1,60 @@ +import "websocket-polyfill"; +import { NWCClient } from "../src/nwc/NWCClient"; +import { createTestWallet } from "./helpers"; + +/** + * E2E test for list_transactions after a successful invoice payment. + * Requires network access. + */ +describe("NWC list_transactions after pay_invoice", () => { + const AMOUNT_MSATS = 100_000; // 100 sats + const BALANCE_SATS = 10_000; + + let sender: { nwcUrl: string }; + let receiver: { nwcUrl: string }; + + beforeAll(async () => { + receiver = await createTestWallet(BALANCE_SATS, 3); + sender = await createTestWallet(BALANCE_SATS, 3); + }, 60_000); + + test( + "returns an outgoing settled transaction for the paid invoice", + async () => { + const receiverClient = new NWCClient({ + nostrWalletConnectUrl: receiver.nwcUrl, + }); + const senderClient = new NWCClient({ nostrWalletConnectUrl: sender.nwcUrl }); + + try { + const invoiceResult = await receiverClient.makeInvoice({ + amount: AMOUNT_MSATS, + description: "E2E list_transactions after payment", + }); + expect(invoiceResult.invoice).toBeDefined(); + + await senderClient.payInvoice({ invoice: invoiceResult.invoice }); + + const listResult = await senderClient.listTransactions({ + limit: 20, + type: "outgoing", + }); + + expect(Array.isArray(listResult.transactions)).toBe(true); + + const matchingTx = listResult.transactions.find( + (tx) => tx.invoice === invoiceResult.invoice, + ); + + expect(matchingTx).toBeDefined(); + expect(matchingTx?.type).toBe("outgoing"); + expect(matchingTx?.state).toBe("settled"); + expect(matchingTx?.amount).toBe(AMOUNT_MSATS); + } finally { + receiverClient.close(); + senderClient.close(); + } + }, + 60_000, + ); +}); From 8db1e008355a67304816d99a0c7b74be42f1cda3 Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Fri, 20 Mar 2026 16:07:35 +0300 Subject: [PATCH 08/10] feat(e2e): added nwc-pay-invoice-insufficient-funds test --- ...nwc-pay-invoice-insufficient-funds.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 e2e/nwc-pay-invoice-insufficient-funds.test.ts diff --git a/e2e/nwc-pay-invoice-insufficient-funds.test.ts b/e2e/nwc-pay-invoice-insufficient-funds.test.ts new file mode 100644 index 00000000..5d652fda --- /dev/null +++ b/e2e/nwc-pay-invoice-insufficient-funds.test.ts @@ -0,0 +1,47 @@ +import "websocket-polyfill"; +import { NWCClient } from "../src/nwc/NWCClient"; +import { Nip47WalletError } from "../src/nwc/types"; +import { createTestWallet } from "./helpers"; + +/** + * E2E negative test for pay_invoice using the NWC faucet. + * Requires network access. + */ +describe("NWC pay_invoice insufficient funds", () => { + const INVOICE_AMOUNT_MSATS = 1_000_000; // 1_000 sats + const RECEIVER_BALANCE_SATS = 10_000; + const SENDER_BALANCE_SATS = 50; + + let sender: { nwcUrl: string }; + let receiver: { nwcUrl: string }; + + beforeAll(async () => { + receiver = await createTestWallet(RECEIVER_BALANCE_SATS, 3); + sender = await createTestWallet(SENDER_BALANCE_SATS, 3); + }, 60_000); + + test( + "fails with wallet error when invoice amount exceeds sender balance", + async () => { + const receiverClient = new NWCClient({ + nostrWalletConnectUrl: receiver.nwcUrl, + }); + const senderClient = new NWCClient({ nostrWalletConnectUrl: sender.nwcUrl }); + + try { + const invoiceResult = await receiverClient.makeInvoice({ + amount: INVOICE_AMOUNT_MSATS, + description: "E2E insufficient funds test", + }); + + await expect( + senderClient.payInvoice({ invoice: invoiceResult.invoice }), + ).rejects.toBeInstanceOf(Nip47WalletError); + } finally { + receiverClient.close(); + senderClient.close(); + } + }, + 60_000, + ); +}); From cb39ad9cd7e942d09d30bdb186900c6b8f52a4dc Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Wed, 25 Mar 2026 15:51:07 +0300 Subject: [PATCH 09/10] refactor(e2e): remove websocket polyfill and hardcoded wallet retries --- e2e/nwc-faucet.test.ts | 3 +-- e2e/nwc-list-transactions-after-payment.test.ts | 5 ++--- e2e/nwc-lookup-invoice.test.ts | 5 ++--- e2e/nwc-pay-invoice-insufficient-funds.test.ts | 5 ++--- e2e/nwc-pay-invoice.test.ts | 5 ++--- e2e/nwc-pay-keysend.test.ts | 11 +++++------ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/e2e/nwc-faucet.test.ts b/e2e/nwc-faucet.test.ts index c70e5053..aee53412 100644 --- a/e2e/nwc-faucet.test.ts +++ b/e2e/nwc-faucet.test.ts @@ -1,4 +1,3 @@ -import "websocket-polyfill"; import { NWCClient } from "../src/nwc/NWCClient"; import { createTestWallet } from "./helpers"; @@ -14,7 +13,7 @@ describe("NWC faucet integration", () => { test( "creates wallet via faucet and balance is 10_000 sats", async () => { - const { nwcUrl } = await createTestWallet(EXPECTED_BALANCE_SATS, 3); + const { nwcUrl } = await createTestWallet(EXPECTED_BALANCE_SATS); const nwc = new NWCClient({ nostrWalletConnectUrl: nwcUrl }); try { diff --git a/e2e/nwc-list-transactions-after-payment.test.ts b/e2e/nwc-list-transactions-after-payment.test.ts index 5907602a..6213ac9b 100644 --- a/e2e/nwc-list-transactions-after-payment.test.ts +++ b/e2e/nwc-list-transactions-after-payment.test.ts @@ -1,4 +1,3 @@ -import "websocket-polyfill"; import { NWCClient } from "../src/nwc/NWCClient"; import { createTestWallet } from "./helpers"; @@ -14,8 +13,8 @@ describe("NWC list_transactions after pay_invoice", () => { let receiver: { nwcUrl: string }; beforeAll(async () => { - receiver = await createTestWallet(BALANCE_SATS, 3); - sender = await createTestWallet(BALANCE_SATS, 3); + receiver = await createTestWallet(BALANCE_SATS); + sender = await createTestWallet(BALANCE_SATS); }, 60_000); test( diff --git a/e2e/nwc-lookup-invoice.test.ts b/e2e/nwc-lookup-invoice.test.ts index ebc63eff..b937ca71 100644 --- a/e2e/nwc-lookup-invoice.test.ts +++ b/e2e/nwc-lookup-invoice.test.ts @@ -1,4 +1,3 @@ -import "websocket-polyfill"; import { NWCClient } from "../src/nwc/NWCClient"; import { createTestWallet } from "./helpers"; @@ -14,8 +13,8 @@ describe("NWC lookup_invoice", () => { let receiver: { nwcUrl: string }; beforeAll(async () => { - receiver = await createTestWallet(BALANCE_SATS, 3); - sender = await createTestWallet(BALANCE_SATS, 3); + receiver = await createTestWallet(BALANCE_SATS); + sender = await createTestWallet(BALANCE_SATS); }, 60_000); test( diff --git a/e2e/nwc-pay-invoice-insufficient-funds.test.ts b/e2e/nwc-pay-invoice-insufficient-funds.test.ts index 5d652fda..a958a444 100644 --- a/e2e/nwc-pay-invoice-insufficient-funds.test.ts +++ b/e2e/nwc-pay-invoice-insufficient-funds.test.ts @@ -1,4 +1,3 @@ -import "websocket-polyfill"; import { NWCClient } from "../src/nwc/NWCClient"; import { Nip47WalletError } from "../src/nwc/types"; import { createTestWallet } from "./helpers"; @@ -16,8 +15,8 @@ describe("NWC pay_invoice insufficient funds", () => { let receiver: { nwcUrl: string }; beforeAll(async () => { - receiver = await createTestWallet(RECEIVER_BALANCE_SATS, 3); - sender = await createTestWallet(SENDER_BALANCE_SATS, 3); + receiver = await createTestWallet(RECEIVER_BALANCE_SATS); + sender = await createTestWallet(SENDER_BALANCE_SATS); }, 60_000); test( diff --git a/e2e/nwc-pay-invoice.test.ts b/e2e/nwc-pay-invoice.test.ts index b8858f3c..06e91c9c 100644 --- a/e2e/nwc-pay-invoice.test.ts +++ b/e2e/nwc-pay-invoice.test.ts @@ -1,4 +1,3 @@ -import "websocket-polyfill"; import { NWCClient } from "../src/nwc/NWCClient"; import { createTestWallet } from "./helpers"; @@ -14,8 +13,8 @@ describe("NWC make_invoice and pay_invoice", () => { let receiver: { nwcUrl: string }; beforeAll(async () => { - receiver = await createTestWallet(BALANCE_SATS, 3); - sender = await createTestWallet(BALANCE_SATS, 3); + receiver = await createTestWallet(BALANCE_SATS); + sender = await createTestWallet(BALANCE_SATS); }, 60_000); test( diff --git a/e2e/nwc-pay-keysend.test.ts b/e2e/nwc-pay-keysend.test.ts index 0d02de06..3be55c8c 100644 --- a/e2e/nwc-pay-keysend.test.ts +++ b/e2e/nwc-pay-keysend.test.ts @@ -1,4 +1,3 @@ -import "websocket-polyfill"; import { NWCClient } from "../src/nwc/NWCClient"; import { createTestWallet } from "./helpers"; @@ -14,8 +13,8 @@ describe("NWC pay_keysend", () => { let receiver: { nwcUrl: string }; beforeAll(async () => { - receiver = await createTestWallet(BALANCE_SATS, 3); - sender = await createTestWallet(BALANCE_SATS, 3); + receiver = await createTestWallet(BALANCE_SATS); + sender = await createTestWallet(BALANCE_SATS); }, 60_000); test( @@ -25,12 +24,12 @@ describe("NWC pay_keysend", () => { const senderClient = new NWCClient({ nostrWalletConnectUrl: sender.nwcUrl }); try { - const infoResult = await receiverClient.getInfo(); - expect(infoResult.pubkey).toBeDefined(); + const receiverInfoResult = await receiverClient.getInfo(); + expect(receiverInfoResult.pubkey).toBeDefined(); const keysendResult = await senderClient.payKeysend({ amount: AMOUNT_MSATS, - pubkey: infoResult.pubkey, + pubkey: receiverInfoResult.pubkey, }); expect(keysendResult.preimage).toBeDefined(); expect(typeof keysendResult.preimage).toBe("string"); From c7049ee2c72bd158188d5fecd332c8d46f608b2f Mon Sep 17 00:00:00 2001 From: Dmitriy E Date: Wed, 25 Mar 2026 16:05:07 +0300 Subject: [PATCH 10/10] refactor(e2e): assert INSUFFICIENT_BALANCE in pay_invoice insufficient funds test --- e2e/nwc-pay-invoice-insufficient-funds.test.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/e2e/nwc-pay-invoice-insufficient-funds.test.ts b/e2e/nwc-pay-invoice-insufficient-funds.test.ts index a958a444..58984a15 100644 --- a/e2e/nwc-pay-invoice-insufficient-funds.test.ts +++ b/e2e/nwc-pay-invoice-insufficient-funds.test.ts @@ -33,9 +33,13 @@ describe("NWC pay_invoice insufficient funds", () => { description: "E2E insufficient funds test", }); - await expect( - senderClient.payInvoice({ invoice: invoiceResult.invoice }), - ).rejects.toBeInstanceOf(Nip47WalletError); + const payInvoicePromise = senderClient.payInvoice({ + invoice: invoiceResult.invoice, + }); + await expect(payInvoicePromise).rejects.toBeInstanceOf(Nip47WalletError); + await expect(payInvoicePromise).rejects.toMatchObject({ + code: "INSUFFICIENT_BALANCE", + }); } finally { receiverClient.close(); senderClient.close();