balanceofsatoshis
Version:
Lightning balance CLI
54 lines (47 loc) • 1.52 kB
JavaScript
const {equal} = require('node:assert').strict;
const {rejects} = require('node:assert').strict;
const test = require('node:test');
const getMacaroon = require('./../../lnd/get_macaroon');
const os = {
homedir: () => 'homedir',
platform: () => 'platform',
userInfo: () => ({username: 'username'}),
};
const tests = [
{
args: {},
description: 'File system methods are required',
error: [400, 'ExpectedFileSystemMethodsToGetMacaroon'],
},
{
args: {fs: {getFile: ({}, cbk) => cbk()}},
description: 'Operating system methods are required',
error: [400, 'ExpectedOperatingSystemMethodsToGetMacaroon'],
},
{
args: {os, fs: {getFile: ({}, cbk) => cbk()}, node: 'node'},
description: 'If a node is specified, no macaroon is returned',
expected: {},
},
{
args: {os, fs: {getFile: ({}, cbk) => cbk()}},
description: 'If no macaroon is found, an error is returned',
error: [503, 'FailedToGetMacaroonFileFromDefaultLocation'],
},
{
args: {os, fs: {getFile: ({}, cbk) => cbk(null, Buffer.alloc(1))}},
description: 'A macaroon in the default location is returned',
expected: {macaroon: 'AA=='},
},
];
tests.forEach(({args, description, error, expected}) => {
return test(description, async () => {
if (!!error) {
await rejects(getMacaroon(args), error, 'Got expected error');
} else {
const {macaroon} = await getMacaroon(args);
equal(macaroon, expected.macaroon, 'Got expected macaroon');
}
return;
});
});