Skip to content

Feat/e2e nwc payment tests#537

Open
DSanich wants to merge 8 commits intogetAlby:masterfrom
DSanich:feat/e2e-nwc-payment-tests
Open

Feat/e2e nwc payment tests#537
DSanich wants to merge 8 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 comprehensive end-to-end test coverage for Nostr Wallet Connect functionality, including invoice operations, payment flows, transaction retrieval, and keysend transfers.
    • Optimized test execution configuration for improved stability and reliability.

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

This PR introduces a suite of end-to-end tests for NWC (Nostr Wallet Connect) operations including invoice creation, payments, keysend transfers, and transaction listing. It adds websocket polyfill support to the test runtime and configures Jest to execute e2e tests serially with a single worker.

Changes

Cohort / File(s) Summary
WebSocket Integration
e2e/nwc-faucet.test.ts
Added websocket-polyfill import to enable WebSocket functionality in test runtime.
NWC Operation 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 new E2E test files validating NWC workflows: invoice creation and payment, keysend transfers, insufficient funds error handling, invoice lookup, and transaction listing after payment. Each test provisions test wallets, instantiates NWC clients, executes payment operations, and verifies expected outcomes with proper cleanup.
Test Configuration
jest.e2e.config.ts
Added maxWorkers: 1 to force serial execution of e2e tests instead of parallel worker concurrency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • rolznz

Poem

🐰 Hop, hop, through the WebSocket streams,
E2E tests fulfill our dreams!
Pay invoices, send keysends with care,
NWC flows tested fair and square!

🚥 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 clearly and specifically describes the main change: addition of end-to-end NWC payment tests covering multiple payment flows and faucet integration.
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
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment on lines +37 to +39
await expect(
senderClient.payInvoice({ invoice: invoiceResult.invoice }),
).rejects.toBeInstanceOf(Nip47WalletError);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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 intended INSUFFICIENT_BALANCE path.

🎯 Suggested assertion tightening
-        await expect(
-          senderClient.payInvoice({ invoice: invoiceResult.invoice }),
-        ).rejects.toBeInstanceOf(Nip47WalletError);
+        await expect(
+          senderClient.payInvoice({ invoice: invoiceResult.invoice }),
+        ).rejects.toMatchObject(
+          expect.objectContaining({
+            // Use the exact field your Nip47WalletError exposes (e.g. `code` or `error.code`)
+            code: "INSUFFICIENT_BALANCE",
+          }),
+        );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/nwc-pay-invoice-insufficient-funds.test.ts` around lines 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.

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.

1 participant