UNPKG

ln-sync

Version:
141 lines (135 loc) 3.54 kB
const {deepEqual} = require('node:assert').strict; const test = require('node:test'); const {throws} = require('node:assert').strict; const detailedBalances = require('./../../nodes/detailed_balances'); const tests = [ { args: { channels: [ { commit_transaction_fee: 1, is_partner_initiated: true, local_balance: 2, pending_payments: [{is_outgoing: true, tokens: 3}], }, { commit_transaction_fee: 4, is_partner_initiated: false, local_balance: 5, pending_payments: [{is_outgoing: false, tokens: 6}], type: 'anchor', }, ], locked: [{ tokens: 1, }], pending: [ { is_closing: true, local_balance: 2, recovered_tokens: 1, }, { is_opening: true, is_partner_initiated: true, local_balance: 0, transaction_fee: 1, }, { is_opening: true, is_partner_initiated: true, local_balance: 2, pending_payments: [{is_outgoing: true, tokens: 3}], transaction_fee: 1, }, { is_opening: false, is_partner_initiated: false, local_balance: 2, pending_payments: [{is_outgoing: true, tokens: 3}], transaction_fee: 1, }, { is_opening: true, is_partner_initiated: false, local_balance: 5, pending_payments: [{is_outgoing: false, tokens: 6}], }, { is_opening: true, is_partner_initiated: false, local_balance: 7, pending_payments: [{is_outgoing: true, tokens: 8}], transaction_fee: 9, }, ], transactions: [ { is_confirmed: false, is_outgoing: true, output_addresses: ['change-address'], }, ], utxos: [ { address: 'address', address_format: 'np2wpkh', confirmation_count: 1, tokens: 1, }, { address: 'change-address', address_format: 'p2wpkh', confirmation_count: 0, tokens: 2, }, { address: 'address2', address_format: 'p2wpkh', confirmation_count: 0, tokens: 2, }, { address: 'address3', address_format: 'p2tr', confirmation_count: 1, tokens: 3, }, ], }, description: 'Balance totals are calculated', expected: { closing_balance: 1, conflicted_pending: 0, invalid_pending: 0, offchain_balance: 344, offchain_pending: 35, onchain_balance: 7, onchain_vbytes: 268, }, }, { args: {channels: [], locked: [], pending: [], transactions: [], utxos: []}, description: 'Balance totals are calculated when there are no funds', expected: { closing_balance: 0, conflicted_pending: 0, invalid_pending: 0, offchain_balance: 0, offchain_pending: 0, onchain_balance: 0, onchain_vbytes: 0, }, }, ]; tests.forEach(({args, description, error, expected}) => { return test(description, (t, end) => { if (!!error) { throws(() => detailedBalances(args), new Error(error)); } else { const balances = detailedBalances(args); deepEqual(balances, expected, 'Got expected balances'); } return end(); }); });