-
Notifications
You must be signed in to change notification settings - Fork 40
Feat/e2e nwc payment tests #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DSanich
wants to merge
8
commits into
getAlby:master
Choose a base branch
from
DSanich:feat/e2e-nwc-payment-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0485807
feat: add NWC faucet integration test
DSanich 61c7fa6
refactor(test): move NWC faucet test to e2e directory
DSanich 8341190
feat(e2e): add nwc-pay-invoice test
DSanich e2dee77
feat(e2e): add nwc-lookup-invoice test
DSanich afc8342
feat(e2e): add nwc-pay-keysend test
DSanich ae08109
feat(e2e): run Jest e2e tests serially to avoid faucet rate limit
DSanich fdb5574
feat(e2e): added nwc-list-transactions-after-payment-test
DSanich 8db1e00
feat(e2e): added nwc-pay-invoice-insufficient-funds test
DSanich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert the specific insufficient-funds error code, not only the error class.
Line 37-39 currently passes for any
Nip47WalletError, so it does not fully validate the intendedINSUFFICIENT_BALANCEpath.🎯 Suggested assertion tightening
🤖 Prompt for AI Agents