aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/ln-receive-twin-test.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/ln-receive-twin-test.js b/tools/ln-receive-twin-test.js
new file mode 100644
index 0000000..bbec971
--- /dev/null
+++ b/tools/ln-receive-twin-test.js
@@ -0,0 +1,31 @@
+// One Lightning receive, told twice: the claim's ln-receive and the mailbox's
+// plain receive of the same coin (The Daniel: two "Received 1,005" rows and a
+// 2,010 celebration). lnFoldedIds names the twin; nothing else is folded.
+// Run: bun tools/ln-receive-twin-test.js
+import { lnFoldedIds } from '../src/ark/manager.js';
+let ok = true;
+const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; };
+const T = 1_790_000_000_000;
+const rcv = (id, sat, ts, extra = {}) => ({ id, type: 'receive', status: 'complete', amountSat: sat, ts, vtxoId: 'v-' + id, ...extra });
+const ln = (id, sat, ts, extra = {}) => ({ id, type: 'ln-receive', status: 'complete', amountSat: sat, ts, ...extra });
+
+let f = lnFoldedIds([ln('L', 1005, T, { vtxoIds: ['v-R'] }), rcv('R', 1005, T + 900)]);
+check('a claim stamped with its coin folds the mailbox\'s receive of it', f.has('R') && f.size === 1);
+f = lnFoldedIds([rcv('R', 1005, T - 400), ln('L', 1005, T, { vtxoIds: ['v-R'] })]);
+check('...whichever came first', f.has('R'));
+f = lnFoldedIds([ln('L', 1005, T, { vtxoIds: ['v-X'] }), rcv('R', 1005, T + 900)]);
+check('a stamped claim never folds some other coin of the same amount', f.size === 0);
+f = lnFoldedIds([ln('L', 1005, T), rcv('R', 1005, T + 60_000)]);
+check('an unstamped (older) claim folds the same amount within minutes', f.has('R'));
+f = lnFoldedIds([ln('L', 1005, T), rcv('R', 1005, T + 30 * 60_000)]);
+check('...not half an hour apart', f.size === 0);
+f = lnFoldedIds([ln('L', 1005, T), rcv('R', 1006, T + 1000)]);
+check('...nor a different amount', f.size === 0);
+f = lnFoldedIds([ln('L', 1005, T), rcv('R', 1005, T + 1000, { viaLn: true })]);
+check('...nor a name@ receive the registrar\'s receipts claimed', f.size === 0);
+f = lnFoldedIds([ln('L1', 500, T), ln('L2', 500, T + 5000), rcv('R1', 500, T + 1000), rcv('R2', 500, T + 6000)]);
+check('two claims of one amount fold one receive each', f.has('R1') && f.has('R2') && f.size === 2);
+f = lnFoldedIds([rcv('R', 1005, T), rcv('S', 2000, T)]);
+check('plain receives with no claim stay', f.size === 0);
+console.log(ok ? '\n✅ a claimed LN receive is told once' : '\n❌ failed');
+process.exit(ok ? 0 : 1);