Skip to content

Feat/e2e nwc payment tests#537

Merged
rolznz merged 10 commits intogetAlby:masterfrom
DSanich:feat/e2e-nwc-payment-tests
Mar 25, 2026
Merged

Feat/e2e nwc payment tests#537
rolznz merged 10 commits intogetAlby:masterfrom
DSanich:feat/e2e-nwc-payment-tests

Conversation

@DSanich
Copy link
Contributor

@DSanich DSanich commented Mar 20, 2026

Summary

  • Added e2e integration tests for core NWC payment flows using the faucet:
    • pay_invoice (success path)
    • lookup_invoice after payment
    • pay_keysend (success path)
    • pay_invoice with insufficient funds (negative case)
    • list_transactions after successful payment
  • Updated/moved the base faucet balance test into the e2e suite.
  • Stabilized e2e execution by setting maxWorkers: 1 in jest.e2e.config.ts to reduce flakiness caused by faucet rate limits.

Why

  • Close coverage gaps for real-world NWC payment behavior at end-to-end level.
  • Validate both happy-path and critical error-path behavior (INSUFFICIENT_BALANCE).
  • Improve reliability of local/CI e2e runs that depend on external faucet infrastructure.

Test plan

  • [] yarn jest --config=jest.e2e.config.ts e2e/nwc-pay-invoice.test.ts
  • [] yarn jest --config=jest.e2e.config.ts e2e/nwc-lookup-invoice.test.ts
  • [] yarn jest --config=jest.e2e.config.ts e2e/nwc-pay-keysend.test.ts
  • [] yarn jest --config=jest.e2e.config.ts e2e/nwc-faucet.test.ts
  • [] yarn jest --config=jest.e2e.config.ts e2e/nwc-pay-invoice-insufficient-funds.test.ts
  • [] yarn jest --config=jest.e2e.config.ts e2e/nwc-list-transactions-after-payment.test.ts

Summary by CodeRabbit

  • Tests
    • Added extensive end-to-end coverage for Nostr Wallet Connect: invoice creation, payment, lookup, insufficient-funds handling, transaction listing after payment, and keysend transfers. Tests include setup/teardown and timeouts for reliability.
    • Adjusted an existing faucet test to modify wallet creation parameters for test consistency.
  • Chores
    • E2E test runner configured to run serially (single worker) for more stable execution.

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a0e76962-ae88-4d1f-ad92-ff11abe234ff

📥 Commits

Reviewing files that changed from the base of the PR and between cb39ad9 and c7049ee.

📒 Files selected for processing (1)
  • e2e/nwc-pay-invoice-insufficient-funds.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/nwc-pay-invoice-insufficient-funds.test.ts

📝 Walkthrough

Walkthrough

Adds five new NWC end-to-end tests (invoice, pay, keysend, insufficient-funds, invoice lookup, transaction listing), tweaks one faucet test invocation, and sets Jest e2e to run serially via maxWorkers: 1. No public APIs changed.

Changes

Cohort / File(s) Summary
Faucet test tweak
e2e/nwc-faucet.test.ts
Removed an extra numeric argument from the createTestWallet call used by the faucet test.
New NWC E2E tests
e2e/nwc-pay-invoice.test.ts, e2e/nwc-pay-keysend.test.ts, e2e/nwc-pay-invoice-insufficient-funds.test.ts, e2e/nwc-lookup-invoice.test.ts, e2e/nwc-list-transactions-after-payment.test.ts
Added five end-to-end tests that provision test wallets, instantiate NWCClient instances, exercise make/pay/keysend flows (including an insufficient-funds negative case), lookup invoices, and list transactions. Each test uses explicit timeouts and ensures NWCClient.close() cleanup.
Test configuration
jest.e2e.config.ts
Added maxWorkers: 1 to force serial execution of e2e tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • rolznz

Poem

🐰 Hop, hop, through test and wire,

invoices chirp and keysend flares,
two wallets meet, a payment sings,
one worker watches as CI springs,
carrot-coded joy in tiny fairs.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feat/e2e nwc payment tests' accurately summarizes the main change: adding end-to-end tests for NWC payment flows and related functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DSanich
Copy link
Contributor Author

DSanich commented Mar 20, 2026

@rolznz hi! I continued working on the library's test coverage. I added tests covering the payments area.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
jest.e2e.config.ts (1)

3-7: Centralize WebSocket polyfill in Jest setup instead of per-test imports.

Running with maxWorkers: 1 is a good stability change. To reduce duplication and keep test files cleaner, load websocket-polyfill once via setupFiles. This will remove the import statement from all 6 e2e test files.

♻️ Proposed config refactor
 export default {
   preset: 'ts-jest',
   testEnvironment: 'node',
   testMatch: ['<rootDir>/e2e/**/*.test.ts'],
   testPathIgnorePatterns: ['/node_modules/', '/e2e/browser'],
+  setupFiles: ['<rootDir>/e2e/setup-websocket.ts'],
   maxWorkers: 1, // Run e2e tests serially to avoid faucet rate limiting
 };
// e2e/setup-websocket.ts
import "websocket-polyfill";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@jest.e2e.config.ts` around lines 3 - 7, Add a single global setup file to
load the websocket polyfill instead of importing it in each test: create an
e2e/setup-websocket.ts that does import "websocket-polyfill"; then update the
Jest config (the object with keys preset, testEnvironment, testMatch,
testPathIgnorePatterns, maxWorkers) to include that file in setupFiles (e.g.
setupFiles: ['<rootDir>/e2e/setup-websocket.ts']), and remove the per-test
websocket-polyfill imports from the e2e test files so the polyfill is
centralized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@e2e/nwc-pay-invoice-insufficient-funds.test.ts`:
- Around line 37-39: The test currently only asserts the thrown type; tighten it
by also asserting the specific insufficient-funds error code: when calling
senderClient.payInvoice({ invoice: invoiceResult.invoice }) update the assertion
to check both the error class (Nip47WalletError) and that the thrown error
contains the INSUFFICIENT_BALANCE code (e.g. await
expect(...).rejects.toMatchObject({ code: 'INSUFFICIENT_BALANCE' }) or combine
with .toBeInstanceOf(Nip47WalletError)); reference senderClient.payInvoice,
Nip47WalletError and the INSUFFICIENT_BALANCE error code in your assertion.

---

Nitpick comments:
In `@jest.e2e.config.ts`:
- Around line 3-7: Add a single global setup file to load the websocket polyfill
instead of importing it in each test: create an e2e/setup-websocket.ts that does
import "websocket-polyfill"; then update the Jest config (the object with keys
preset, testEnvironment, testMatch, testPathIgnorePatterns, maxWorkers) to
include that file in setupFiles (e.g. setupFiles:
['<rootDir>/e2e/setup-websocket.ts']), and remove the per-test
websocket-polyfill imports from the e2e test files so the polyfill is
centralized.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd797b9a-8d37-4702-84a0-ffd9e6cfdba2

📥 Commits

Reviewing files that changed from the base of the PR and between 3de0c54 and 8db1e00.

📒 Files selected for processing (7)
  • e2e/nwc-faucet.test.ts
  • e2e/nwc-list-transactions-after-payment.test.ts
  • e2e/nwc-lookup-invoice.test.ts
  • e2e/nwc-pay-invoice-insufficient-funds.test.ts
  • e2e/nwc-pay-invoice.test.ts
  • e2e/nwc-pay-keysend.test.ts
  • jest.e2e.config.ts

@DSanich
Copy link
Contributor Author

DSanich commented Mar 25, 2026

@rolznz Hello! Have you had a chance to test this? I think this PR is useful as a continuation of our work on test coverage.

@DSanich
Copy link
Contributor Author

DSanich commented Mar 25, 2026

@rolznz I pushed a commit with adjustments according to your review cb39ad9

@rolznz
Copy link
Contributor

rolznz commented Mar 25, 2026

@DSanich did you see the comment from coderabbit? I tagged you there

@DSanich
Copy link
Contributor Author

DSanich commented Mar 25, 2026

@DSanich did you see the comment from coderabbit? I tagged you there

Sorry, I scrolled past this, of course I'll send an additional commit 🙏

@rolznz ready c7049ee

@rolznz
Copy link
Contributor

rolznz commented Mar 25, 2026

@DSanich thanks for the additional tests, looks good now!

@rolznz rolznz merged commit 08a6cd7 into getAlby:master Mar 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants