aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ark/renew-txid-test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-03 16:05:42 -0700
committerAdam Soltys <[email protected]>2026-10-03 16:05:42 -0700
commit202dced76eb8617c094686ef86caa979c0074320 (patch)
tree3c3e37783983f4987bac1e278294b13496dfa430 /tools/ark/renew-txid-test.js
parent328f2db9af46cda473318bb3eada0f6e83bb42f1 (diff)
downloadcoinosv3-202dced76eb8617c094686ef86caa979c0074320.tar.gz
coinosv3-202dced76eb8617c094686ef86caa979c0074320.zip
Renewing asks first, and a renewal links to its round's transaction
- The coins page's Renew button opens a confirmation instead of renewing at once: how many coins, their amount, the fee, and what is left to spend meanwhile — with a red notice when that is nothing (the button selects every coin by default, which is how a user locked their whole balance for an hour on 2026-10-03). It says the coins can't be spent until the round's transaction confirms and that a renewal can't be cancelled; the wallet renews for free near expiry anyway. The inline notice from 328f2db moves into it. - A renewal keeps its round's transaction id as soon as the round has run (before it confirms): the in-progress card on the coins page links to it, and the finished renewal's history row carries it, so its detail shows the id with View/Copy like any on-chain movement. Renewals finished before this change have no id recorded. tools/ark/renew-confirm-ui-test.js, tools/ark/renew-txid-test.js Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01ULQZS9MQa6iAsXnrJUD9Du
Diffstat (limited to 'tools/ark/renew-txid-test.js')
-rw-r--r--tools/ark/renew-txid-test.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/ark/renew-txid-test.js b/tools/ark/renew-txid-test.js
new file mode 100644
index 0000000..ea0be35
--- /dev/null
+++ b/tools/ark/renew-txid-test.js
@@ -0,0 +1,45 @@
+// A renewal remembers its round's transaction as soon as the round has run —
+// before that transaction confirms, which is exactly when someone wants to
+// look it up — so the coins page (and later the history row) can link to it.
+// Run: bun tools/ark/renew-txid-test.js
+import assert from 'node:assert/strict';
+import { mock } from 'bun:test';
+import { hex } from '@scure/base';
+
+const refresh = await import('../../src/ark/refresh.js');
+// version 2, one input, one 1000-sat OP_TRUE output
+const rawTx = hex.decode('02000000' + '01' + '11'.repeat(32) + '00000000' + '00' + 'ffffffff' + '01' + 'e803000000000000' + '0151' + '00000000');
+const wantTxid = refresh.parseTx(rawTx).txid;
+let roundRan = false;
+mock.module('../../src/ark/refresh.js', () => ({
+ ...refresh,
+ roundParticipationStatus: async () => (roundRan ? { status: 1, fundingTx: rawTx, outputVtxos: [] } : { status: 0 }),
+}));
+const { ArkManager } = await import('../../src/ark/manager.js');
+let saves = 0;
+const mgr = new ArkManager({ storage: { save() { saves++; } }, arkUrl: 'http://test.invalid' });
+const asked = [];
+Object.defineProperty(mgr, 'chain', { value: { getTxStatus: async (txid) => { asked.push(txid); return { confirmed: false }; } } });
+const action = { id: 'refresh-1', type: 'refresh', step: 'submitted', inputIds: ['a:0'], outKeyIndex: 1, outAmountSat: 900, feeSat: 0, unlockHash: '22'.repeat(32) };
+mgr.state = { nextKeyIndex: 2, movements: [], actions: [action], vtxos: [{ id: 'a:0', amountSat: 900, expiryHeight: 500, state: 'pending' }] };
+mgr._refreshOutputs = () => [];
+
+await mgr._driveRefresh(action);
+assert.equal(action.fundingTxid, undefined, 'no transaction before the round has run');
+assert.equal(action.step, 'submitted');
+console.log('✓ Before the round runs there is no transaction to point at');
+
+roundRan = true;
+const before = saves;
+await mgr._driveRefresh(action);
+assert.equal(action.fundingTxid, wantTxid, 'the round transaction is kept');
+assert.equal(action.step, 'submitted', 'still waiting for the confirmation');
+assert.deepEqual(asked, [wantTxid]);
+assert(saves > before, 'and saved, so a reload still has it');
+console.log('✓ Once the round has run its transaction id is kept, though unconfirmed: ' + wantTxid.slice(0, 16) + '…');
+
+const again = saves;
+await mgr._driveRefresh(action);
+assert.equal(saves, again, 'not saved again on every sync while it waits');
+console.log('✓ ...and waiting for the confirmation writes nothing more');
+console.log('\n✅ a renewal knows its round transaction');