diff options
Diffstat (limited to 'tools/ln-receive-twin-test.js')
| -rw-r--r-- | tools/ln-receive-twin-test.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/ln-receive-twin-test.js b/tools/ln-receive-twin-test.js index 20d4f48..167a26b 100644 --- a/tools/ln-receive-twin-test.js +++ b/tools/ln-receive-twin-test.js @@ -35,5 +35,19 @@ f = lnFoldedIds([rcv('A', 1000, T), { ...rcv('B', 1000, T + 2000), vtxoId: 'v-A' check('...or the earliest when none is tagged', f.size === 1 && f.has('B')); f = lnFoldedIds([rcv('A', 1000, T), rcv('B', 1000, T + 2000)]); check('two coins of the same amount stay two rows', f.size === 0); +// a Lightning payment the closed app's worker made: its own ln-send row +// (merged from the mirror) plus the app's "while closed" note of the same +// preimage — one row, the one that names its inputs +const snd = (id, ts, extra = {}) => ({ id, type: 'ln-send', status: 'complete', amountSat: 1, ts, ...extra }); +f = lnFoldedIds([snd('W', T, { preimage: 'pi1', paymentHash: 'h1', inputIds: ['v1'] }), snd('N', T + 60_000, { preimage: 'pi1', detail: 'while closed · fee 0 sat' })]); +check('a closed-app payment told twice shows once, the row with inputs', f.size === 1 && f.has('N')); +f = lnFoldedIds([snd('N', T, { preimage: 'pi1' }), snd('W', T + 5000, { preimage: 'pi1', paymentHash: 'h1', inputIds: ['v1'] })]); +check('...whichever order they were written', f.size === 1 && f.has('N')); +f = lnFoldedIds([snd('W', T, { paymentHash: 'h1', preimage: 'pi1', inputIds: ['v1'] }), snd('N', T + 1000, { paymentHash: 'h1' })]); +check('...matched by payment hash when the note has no preimage', f.size === 1 && f.has('N')); +f = lnFoldedIds([snd('A', T, { preimage: 'pi1', inputIds: ['v1'] }), snd('B', T + 1000, { preimage: 'pi2', inputIds: ['v2'] })]); +check('two payments stay two rows', f.size === 0); +f = lnFoldedIds([snd('A', T, { preimage: 'pi1' }), snd('B', T + 1000, { preimage: 'pi1' })]); +check('two notes with no inputs keep the earliest', f.size === 1 && f.has('B')); console.log(ok ? '\n✅ a claimed LN receive is told once' : '\n❌ failed'); process.exit(ok ? 0 : 1); |
