aboutsummaryrefslogtreecommitdiffstats
path: root/tools/nwc-test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-14 09:06:02 -0700
committerAdam Soltys <[email protected]>2026-09-14 09:06:02 -0700
commit671d2a96474f59ca9234c876ce6604d03de95727 (patch)
treed732896288985033c0531b70b7bcad0cc388cb00 /tools/nwc-test.js
parent6394de43d4e596aaeddd2b262bb7a595679d8fbc (diff)
downloadcoinosv3-671d2a96474f59ca9234c876ce6604d03de95727.tar.gz
coinosv3-671d2a96474f59ca9234c876ce6604d03de95727.zip
One device pays a zap, whichever of them heard it first.
Every awake device of a wallet hears a wallet-connect pay request within the same second, and the per-tab lock only reaches one browser profile: two profiles on one laptop each locked an HTLC for the same 21-sat zap. The push notifier now hands each pay request to the first device that claims it; a device that loses the claim stands down silently, and a device that cannot reach the notifier answers as before so nobody goes quiet over a hiccup. The worker path claims the same way. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYJfZ4A1TDCEY4Foq3CApR
Diffstat (limited to 'tools/nwc-test.js')
-rw-r--r--tools/nwc-test.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/nwc-test.js b/tools/nwc-test.js
index 5bb08e2..b68a89b 100644
--- a/tools/nwc-test.js
+++ b/tools/nwc-test.js
@@ -14,6 +14,7 @@ globalThis.localStorage = { getItem:k=>k in store?store[k]:null, setItem:(k,v)=>
let subHandler = null;
let priorReplies = [];
+let claimOk = true;
const published = [];
// fake relay transport: capture the subscription handler and any replies
const nwcTransport = {
@@ -21,6 +22,7 @@ const nwcTransport = {
publish: async (relays, evt) => { published.push(evt); return true; },
query: async () => priorReplies, // what other devices have answered (none, unless a test says so)
errGraceMs: 20, // the sibling-first hold, shortened for the harness
+ claim: async () => claimOk, // the notifier's first-come-first-pays verdict
};
let paid = [];
const wallet = {
@@ -133,6 +135,17 @@ console.log('\n[sibling payment in flight]');
delete hooks.arkLnOutcome;
}
+console.log('\n[cross-device claim]');
+{
+ claimOk = false;
+ const n = published.length, wasPaid = paid.length;
+ await request('pay_invoice', { invoice: INV21 });
+ check('unclaimed pay request stays silent and unpaid', published.length === n && paid.length === wasPaid);
+ claimOk = true;
+ r = await request('get_balance', {});
+ check('non-pay methods need no claim', r?.result?.balance === 42000*1000);
+}
+
console.log('\n[nip04 fallback]');
r = await request('get_balance', {}, 'nip04');
check('nip04 request answered', r?.result?.balance === 42000*1000);