lightning
Version:
Lightning Network client library
68 lines (62 loc) • 1.81 kB
JavaScript
const {rejects} = require('node:assert').strict;
const {strictEqual} = require('node:assert').strict;
const test = require('node:test');
const {getChainFeeRate} = require('./../../../lnd_methods');
const tests = [
{
args: {},
description: 'LND is required',
error: [400, 'ExpecteAuthenticatedLndToGetFeeEstimate'],
},
{
args: {lnd: {}},
description: 'LND with wallet object is required',
error: [400, 'ExpecteAuthenticatedLndToGetFeeEstimate'],
},
{
args: {lnd: {wallet: {}}},
description: 'LND with estimateFee method is required',
error: [400, 'ExpecteAuthenticatedLndToGetFeeEstimate'],
},
{
args: {
lnd: {wallet: {estimateFee: ({}, cbk) => cbk('err')}},
},
description: 'Unexpected errors are passed back',
error: [503, 'UnexpectedErrorGettingFeeFromLnd', {err: 'err'}],
},
{
args: {
lnd: {wallet: {estimateFee: ({}, cbk) => cbk()}},
},
description: 'A response is expected',
error: [503, 'ExpectedResponseForEstimateFeeRequest'],
},
{
args: {
lnd: {wallet: {estimateFee: ({}, cbk) => cbk(null, {})}},
},
description: 'A response is expected',
error: [503, 'ExpectedSatPerKwResponseForFeeEstimate'],
},
{
args: {
lnd: {
wallet: {estimateFee: ({}, cbk) => cbk(null, {sat_per_kw: '250'})},
},
},
description: 'Tokens per vbyte are returned',
expected: {tokens_per_vbyte: 1},
},
];
tests.forEach(({args, description, error, expected}) => {
return test(description, async () => {
if (!!error) {
await rejects(getChainFeeRate(args), error, 'Got expected error');
} else {
const res = await getChainFeeRate(args);
strictEqual(res.tokens_per_vbyte, expected.tokens_per_vbyte, 'Got rate');
}
return;
});
});