diff options
| author | Adam Soltys <[email protected]> | 2026-10-08 13:00:41 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-08 13:00:41 -0700 |
| commit | b0c6e8b7d0340f5ef64ddeef0f7b0c0531cb87f1 (patch) | |
| tree | ecf8c3cd8ae46175aca8cc357d015f13822baf56 /tools | |
| parent | 767ab45d9158dcd995a7647d0efaf6c127b35e3a (diff) | |
| download | coinosv3-b0c6e8b7d0340f5ef64ddeef0f7b0c0531cb87f1.tar.gz coinosv3-b0c6e8b7d0340f5ef64ddeef0f7b0c0531cb87f1.zip | |
A finished renewal adopted twice no longer shows 'Renewal in progress' forever: once its done action is pruned, a re-read round breadcrumb adopted it again as a rescue at step 'issued', whose spent inputs had lost their bytes, so every sync threw. A round counts as claimed when its 'Renewed' movement or its fresh coins are already in the wallet; the breadcrumb and rescueParticipation skip it, and a stuck issued action retires without a row
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/ark/rescue-claimed-test.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/ark/rescue-claimed-test.js b/tools/ark/rescue-claimed-test.js new file mode 100644 index 0000000..7d3c68b --- /dev/null +++ b/tools/ark/rescue-claimed-test.js @@ -0,0 +1,57 @@ +// A finished renewal adopted a second time — its done action pruned, then the +// round's mailbox breadcrumb read again — must not sit "Renewal in progress" +// forever. The issued step retires it without a row (its first claim has one), +// and neither the breadcrumb nor rescueParticipation adopts a claimed round. +// Run: bun tools/ark/rescue-claimed-test.js +import assert from 'node:assert/strict'; +import { mock } from 'bun:test'; + +const refresh = await import('../../src/ark/refresh.js'); +let claims = 0, statusAsks = 0; +mock.module('../../src/ark/refresh.js', () => ({ + ...refresh, + requestForfeitNonces: async () => { claims++; throw new Error('network'); }, + roundParticipationStatus: async () => { statusAsks++; throw new Error('network'); }, +})); +const { ArkManager } = await import('../../src/ark/manager.js'); +const mgr = new ArkManager({ storage: { save() {} }, arkUrl: 'http://test.invalid' }); +mgr._refreshOutputs = () => []; +mgr._key = () => ({}); +mgr._decoded = () => ({ point: { raw: new Uint8Array(36) } }); +// version 2, one input, one 1000-sat OP_TRUE output +const rawTx = '02000000' + '01' + '11'.repeat(32) + '00000000' + '00' + 'ffffffff' + '01' + 'e803000000000000' + '0151' + '00000000'; +const U = 'a6'.repeat(32); +const fresh = () => ({ + id: 'refresh-rescue-1', type: 'refresh', step: 'issued', inputIds: ['a:0', 'b:0'], outKeyIndex: 3, + outAmountSat: 900, feeSat: 2, unlockHash: U, fundingTxHex: rawTx, outputVtxos: [], +}); +// input b:0 has lost its bytes to pruning, as on Adam's wallet +const coins = () => [{ id: 'a:0', amountSat: 500, state: 'spent', bytes: 'AA==' }, { id: 'b:0', amountSat: 402, state: 'spent' }]; + +{ + const action = fresh(); + mgr.state = { nextKeyIndex: 4, actions: [action], vtxos: coins(), + movements: [{ id: 'm1', type: 'refresh', status: 'complete', amountSat: 900, unlockHash: U, inputIds: ['a:0', 'b:0'] }] }; + await mgr._driveRefresh(action); + assert.equal(action.step, 'failed'); + assert.equal(action.superseded, true, 'retired without a history row'); + assert.equal(claims, 0, 'never asks the server to claim again'); + assert.equal(mgr.state.movements.length, 1, 'no second "Renewed" row'); + console.log('✓ A second adoption of a finished renewal retires on the next sync'); +} + +{ + await assert.rejects(mgr.rescueParticipation(U), /already claimed/); + assert.equal(statusAsks, 0, 'refused before asking the server'); + console.log('✓ rescueParticipation refuses a round the history already shows as renewed'); +} + +{ + const action = fresh(); + mgr.state = { nextKeyIndex: 4, actions: [action], vtxos: coins(), movements: [] }; + await assert.rejects(mgr._driveRefresh(action), /network/); + assert.equal(claims, 1, 'an unclaimed round still goes on to claim'); + assert.equal(action.step, 'issued'); + console.log('✓ A round with no claim on record still drives its claim'); +} +console.log('\n✅ claimed-round rescue passes'); |
