Registry / testing / mock-lnd

mock-lnd

JSON →
library4.0.0jsnpmunverified

Mock LND gRPC Object for unit testing Lightning Network applications. Current version: 4.0.0 (requires Node >=22). Provides factory functions to create mock LND gRPC responses for invoices, forwards, payments, subscriptions, and more. Designed to simulate the authenticated LND API object returned by `ln-service`, enabling isolated unit tests without a real LND node. Provides overrides for key LND methods like `getChannels`, `getForwards`, `subscribeToInvoice`, and `payViaRoutes`. No external runtime dependencies.

npm install mock-lnd
INSTALL
IMPORT
SIG · MOCK-LND
M
mock-lnd
testingjavascriptv4.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

makeInvoice
import { makeInvoice } from 'mock-lnd'
const makeInvoice = require('mock-lnd').makeInvoice
ESM import style is preferred; CJS require works but may cause issues with mocking in some test runners.
makeLnd
import { makeLnd } from 'mock-lnd'
import makeLnd from 'mock-lnd'
Default export does not exist; must use named import.
makeForwardsResponse
import { makeForwardsResponse } from 'mock-lnd'
import { makeForwardsResponse } from 'mock-lnd/makeForwardsResponse'
Subpath imports are not supported; use top-level package import.

Shows basic usage: create a mock lnd object with overrides for getForwards and getInvoice, then test behavior.

import { makeInvoice, makeLnd, makeForwardsResponse } from 'mock-lnd'; // Create a mock lnd object with overrides const lndMock = makeLnd({ getForwards: ({}) => { return makeForwardsResponse({ offset: 0 }); }, getInvoice: ({}) => { return makeInvoice({ is_confirmed: true }); }, }); // Use the mock in a test (e.g., with Jest) describe('getInvoice', () => { it('returns a confirmed invoice', async () => { const invoice = await lndMock.getInvoice({ id: 'test' }); expect(invoice.is_confirmed).toBe(true); }); });
Debug
Known issues
breakingVersion 4.0.0 drops support for Node.js versions below 22. Ensure your environment runs Node >=22.
fix
Upgrade Node.js to v22 or later.
affects: >=4.0.0
breakingThe `makeLnd` function no longer accepts the `lnd` parameter from previous versions. All configuration is done via overrides object.
fix
Use the overrides object directly as the argument to `makeLnd`.
affects: >=4.0.0
deprecatedThe `makePayViaRoutesResponse` function signature changed in v4: the `is_unknown_failure` option replaces the older boolean parameter.
fix
Pass an object with `is_unknown_failure` instead of a boolean.
affects: >=4.0.0
gotchaMock objects returned by `makeLnd` do not fully replicate LND behavior; only override explicit methods. Calls to non-overridden methods throw an error.
fix
Always override the methods you intend to use in tests.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mockLnd.getInfo is not a function
Only explicitly overridden methods are available on the mock object.
fix
Add `getInfo: () => Promise.resolve({})` to the overrides object passed to `makeLnd`.
ERR_REQUIRE_ESM: require() of ES Module not supported
Using CommonJS require() for an ES module package in Node 22+.
fix
Switch to dynamic import: `const { makeInvoice } = await import('mock-lnd')` or configure package.json with `"type": "module"`.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
ln-serviceoptionalPeer dependency: mock objects mirror the lnd API from ln-service
Agent activity
4 hits · last 30 days
node
4
Resources
mock-lnd — npm install mock-lnd · libregistry