diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/amber-login-test.js | 104 | ||||
| -rw-r--r-- | tools/balance-settings-row-test.js | 2 | ||||
| -rw-r--r-- | tools/send-enter-keys-test.js | 7 | ||||
| -rw-r--r-- | tools/signup-quick-test.js | 36 | ||||
| -rw-r--r-- | tools/unified-balance-test.js | 127 |
5 files changed, 158 insertions, 118 deletions
diff --git a/tools/amber-login-test.js b/tools/amber-login-test.js deleted file mode 100644 index 46a16f6..0000000 --- a/tools/amber-login-test.js +++ /dev/null @@ -1,104 +0,0 @@ -// NIP-55: on Android, "Sign in with Amber" opens a nostrsigner: intent for the -// pubkey; the answer is read from the clipboard when the tab comes back (or -// pasted); creating the wallet then makes an encrypt and a sign round trip. -// The intent launcher and the clipboard are stubbed; relays answer nothing. -// Run: bun tools/amber-login-test.js -import puppeteer from './puppeteer.js'; -import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; -import { npubEncode } from 'nostr-tools/nip19'; -import { buildHtml } from '../build.js'; -const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); -let ok = true; -const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; }; -const SK = generateSecretKey(); const PK = getPublicKey(SK); -const html = await buildHtml({ minify: true, pwa: false }); -const server = Bun.serve({ port: 5308, fetch: (req) => { const p = new URL(req.url).pathname; if (p === '/verify-worker.js' || p.startsWith('/punks')) return new Response(Bun.file('dist' + p)); return new Response(html, { headers: { 'content-type': 'text/html' } }); } }); -const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] }); -const page = await browser.newPage(); -await page.setUserAgent('Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0 Mobile Safari/537.36'); -await page.evaluateOnNewDocument(() => { - window.__amberUrls = []; - window.__coinosAmberLaunch = (u) => { window.__amberUrls.push(u); }; - window.__clip = ''; - Object.defineProperty(navigator, 'clipboard', { value: { readText: async () => window.__clip, writeText: async () => {} }, configurable: true }); - const Real = window.WebSocket; - window.WebSocket = function (...a) { const ws = new Real(...a); const send = ws.send.bind(ws); ws.send = (d) => { try { const m = JSON.parse(d); if (m[0] === 'REQ') { setTimeout(() => ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) })), 0); return; } if (m[0] === 'EVENT') { window.__published = (window.__published || []).concat([m[1]]); setTimeout(() => ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['OK', m[1].id, true, '']) })), 0); return; } } catch {} return send(d); }; return ws; }; - window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real); -}); -const errs = []; -page.on('pageerror', (e) => errs.push(String(e))); -const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t); -const waitText = async (x, ms = 20000) => { for (let i = 0; i < ms / 250; i++) { if ((await page.evaluate(() => document.body.innerText)).toLowerCase().includes(x)) return true; await sleep(250); } return false; }; -const urls = () => page.evaluate(() => window.__amberUrls); -const lastType = async () => { const u = await urls(); const last = u[u.length - 1] || ''; return (last.match(/[?&]type=([a-z_0-9]+)/) || [])[1] || null; }; -const deliver = (text) => page.evaluate((t) => { window.__clip = t; document.dispatchEvent(new Event('visibilitychange')); window.dispatchEvent(new Event('focus')); }, text); - -try { - await page.setViewport({ width: 390, height: 844 }); - await page.goto('http://localhost:5308/', { waitUntil: 'domcontentloaded' }); - await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest')); - await page.reload({ waitUntil: 'domcontentloaded' }); await sleep(500); - console.log('\n[the Amber door]'); - await click('sign in to an existing account'); await sleep(300); - check('the front door offers Nostr sign-in', await click('sign in with nostr') || await click('nostr')); - await sleep(500); - check('on Android, the login offers Amber', await waitText('sign in with a signer app', 5000)); - await click('sign in with a signer app'); await sleep(400); - check('tapping it opens a get_public_key intent', (await lastType()) === 'get_public_key', JSON.stringify(await urls())); - check('...and shows the waiting card with a paste box', await waitText('waiting for your signer', 2000) && !!(await page.$('.amber-paste'))); - await deliver(npubEncode(PK)); - // a fresh account: the wallet is minted and its backup goes to the app to be encrypted - let t0 = Date.now(); while (Date.now() - t0 < 15000 && (await lastType()) !== 'nip44_encrypt') await sleep(250); - check('the pubkey read off the clipboard signs the account in; the seed goes to the app for encryption', (await lastType()) === 'nip44_encrypt', JSON.stringify((await urls()).map((u) => (u.match(/[?&]type=([a-z_0-9]+)/) || [])[1]))); - check('...and the npub left on the clipboard is not mistaken for the ciphertext', await page.evaluate(() => !!document.querySelector('.amber-paste'))); - - console.log('\n[creating the wallet: encrypt, then sign, each a round trip]'); - const encUrl = (await urls()).pop(); - check('...addressed to the user\'s own key', new URL(encUrl.replace('nostrsigner:', 'http://x/')).searchParams.get('pubkey') === PK); - // this time the clipboard is not readable: the answer is pasted - await page.evaluate(() => { navigator.clipboard.readText = async () => { throw new Error('denied'); }; }); - const fakeCipher = 'Ag' + btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(96)))).replace(/=+$/, '').replace(/[^A-Za-z0-9+/]/g, 'a'); - await page.type('.amber-paste', fakeCipher); - await click('use it'); await sleep(800); - check('the pasted ciphertext moves things on to a signature', (await lastType()) === 'sign_event', await lastType()); - const signUrl = (await urls()).pop(); - const unsigned = JSON.parse(decodeURIComponent(signUrl.slice('nostrsigner:'.length).split('?')[0])); - check('...of an event under the signed-in pubkey', unsigned.pubkey === PK && typeof unsigned.kind === 'number', JSON.stringify({ kind: unsigned.kind, pk: unsigned.pubkey.slice(0, 8) })); - const signed = finalizeEvent({ kind: unsigned.kind, created_at: unsigned.created_at, tags: unsigned.tags, content: unsigned.content }, SK); - await page.evaluate(() => { navigator.clipboard.readText = async () => window.__clip; }); - await deliver(JSON.stringify(signed)); await sleep(2500); - const pub = await page.evaluate(() => (window.__published || []).map((e) => e.kind)); - check('the signed backup is published and the new identity walks into onboarding', pub.includes(30078) && await waitText('write down your recovery phrase', 10000), 'published kinds ' + JSON.stringify(pub)); - // the rest of the first run: every further signature (relay list, follows) - // is one more trip through Amber, taken in turn, while the words screen is - // walked through - const signedKinds = []; - let signedUrls = 1; - // answer the next sign_event intent, if one is waiting - const signNext = async () => { - const pend = (await urls()).filter((u) => /type=sign_event/.test(u)); - if (pend.length <= signedUrls) return false; - const u = pend[signedUrls]; signedUrls++; - const ev = JSON.parse(decodeURIComponent(u.slice('nostrsigner:'.length).split('?')[0])); - signedKinds.push(ev.kind); - await deliver(JSON.stringify(finalizeEvent({ kind: ev.kind, created_at: ev.created_at, tags: ev.tags, content: ev.content }, SK))); - return true; - }; - for (let i = 0; i < 80 && !(await page.evaluate(() => document.body.innerText.toLowerCase().includes('receive'))); i++) { - if (!(await signNext())) { await click('later') || await click('skip verification') || await click("i've written it down") || await click('continue'); } - await sleep(500); - } - // The starter follows wait on a deep look for a list this key may already - // have (2026-10-02 follows-overwrite fix), so their signature can arrive - // after the wallet is open: keep answering until things go quiet. - for (let i = 0, idle = 0; i < 60 && idle < 8; i++) { - if (await signNext()) idle = 0; else if (signedKinds.length) idle++; - await sleep(500); - } - if (!(await page.evaluate(() => document.body.innerText.toLowerCase().includes('receive')))) console.log(' DEBUG loop end:', JSON.stringify(await page.evaluate(() => ({ btns: [...document.querySelectorAll('button')].map((b) => b.textContent.trim()).filter(Boolean).slice(0, 12), text: document.body.innerText.slice(0, 160).replace(/\n+/g, ' | ') })))); - check('each later signature (follows, relays) was its own trip, and the wallet opens on Receive', await waitText('receive', 5000) && signedKinds.length > 0, 'signed kinds after the backup ' + JSON.stringify(signedKinds)); - check('no request cancelled another', !(await page.evaluate(() => document.body.innerText)).includes('took its place')); - check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); -} finally { await browser.close(); server.stop(true); } -console.log(ok ? '\n✅ Amber signs in and signs, one trip at a time' : '\n❌ failed'); -process.exit(ok ? 0 : 1); diff --git a/tools/balance-settings-row-test.js b/tools/balance-settings-row-test.js index 38d34b3..351e2fe 100644 --- a/tools/balance-settings-row-test.js +++ b/tools/balance-settings-row-test.js @@ -31,7 +31,7 @@ const openWalletPage = async () => { try { await page.setViewport({ width: 390, height: 844 }); await page.goto(server.url.href, { waitUntil: 'domcontentloaded' }); - await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'mainnet')); + await page.evaluate(() => (localStorage.setItem('btc-wallet-network', 'mainnet'), localStorage.setItem('btc-wallet-separate-balances', '1'))); await page.reload({ waitUntil: 'domcontentloaded' }); await sleep(400); // on mainnet Create makes a Spending-only account (signup-quick-test); a diff --git a/tools/send-enter-keys-test.js b/tools/send-enter-keys-test.js index aac95f8..54f2c02 100644 --- a/tools/send-enter-keys-test.js +++ b/tools/send-enter-keys-test.js @@ -45,8 +45,13 @@ const armPrimary = () => page.evaluate(() => { try { await page.setViewport({ width: 390, height: 844 }); await page.goto(server.url.origin, { waitUntil: 'domcontentloaded' }); + // the two-card carousel is the "separately" view now (one balance is the default) + await page.evaluate(() => localStorage.setItem('btc-wallet-separate-balances', '1')); + await page.reload({ waitUntil: 'domcontentloaded' }); await sleep(400); - await click('create a new wallet'); await sleep(500); await click('to import'); await sleep(400); + // a seed wallet comes in through the seed-phrase door (Create is a sign-up on mainnet) + await page.waitForSelector('#onb-signin'); await page.click('#onb-signin'); await sleep(400); + await page.click('#onb-restore'); await sleep(400); await page.waitForSelector('textarea'); await page.type('textarea', generateMnemonic(wordlist)); await click('open wallet'); for (let i = 0; i < 80 && !(await page.evaluate(() => [...document.querySelectorAll('button')].some((b) => b.textContent.trim() === 'Send'))); i++) { await page.evaluate(() => [...document.querySelectorAll('button')].find((b) => /^(not now|skip|continue|later)$/i.test(b.textContent.trim()))?.click()); diff --git a/tools/signup-quick-test.js b/tools/signup-quick-test.js index a269faf..3e38c5f 100644 --- a/tools/signup-quick-test.js +++ b/tools/signup-quick-test.js @@ -8,11 +8,11 @@ // // Mainnet, with the Ark server's info read for real and the names registrar // mocked (nothing is claimed): Create an account → no twelve words, no check -// → Claim your name (no "Not now") → Choose your look → in, on a Spending-only -// wallet (no carousel, no Savings face); the wallet line asks for a way back -// in; Settings → Wallet shows "Ways back in" (passkey via a CDP virtual -// authenticator → listed, the line goes away) and "Add a savings account" -// (→ the Savings face appears); a reload keeps both. +// → Claim your name (no "Not now") → Choose your look → in, on ONE balance +// (no carousel; on-chain is part of the account, a Bitcoin address a tap away +// on Receive); Settings → Wallet shows "Ways back in" (passkey via a CDP +// virtual authenticator → listed) and one balance row, with "Show Spending +// and Savings separately" (→ the two faces; a reload keeps them). // Run: bun tools/signup-quick-test.js (NO_BUILD=1 to reuse dist/) import puppeteer from './puppeteer.js'; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); @@ -81,7 +81,7 @@ try { body: document.body.innerText, })); let s = await shape(); - check('in, on Spending alone (no Savings face, no name on it)', s.faces === 1 && !s.carousel && !s.label, JSON.stringify({ faces: s.faces, carousel: s.carousel, label: s.label })); + check('in, on one balance (no carousel, no name on it)', s.faces === 1 && !s.carousel && !s.label && !!(await page.$('.balance-one')), JSON.stringify({ faces: s.faces, carousel: s.carousel, label: s.label })); // asked once, and only with money in the account (2026-11-15): not on an empty one check('no way-back-in prompt on an empty account', !/add a way back into your account/i.test(s.body) && !(await page.$('.ways-back-prompt'))); // money arrives in Spending (the ark feature, found on the heap, made to @@ -117,15 +117,22 @@ try { if (process.env.SHOT4) await page.screenshot({ path: process.env.SHOT4 }); await click('back'); await sleep(500); check('Back returns to Receive', !(await page.$('.pos-amount')) && !!(await page.$('#recv-amount'))); + // one account takes on-chain payments too: its address under the payment one + check('Receive offers a Bitcoin address', !!(await page.$('#recv-onchain'))); + await page.click('#recv-onchain'); await sleep(400); + const oc = await page.evaluate(() => document.querySelector('.addr-box')?.textContent.trim() || ''); + check('...an on-chain address', /^bc1q/.test(oc), oc); + await page.click('#recv-payaddr'); await sleep(400); + check('...and back to the payment address', !!(await page.$('#recv-amount')) && !(await page.$('#recv-payaddr'))); const acct = await page.evaluate(() => JSON.parse(sessionStorage.getItem('btc-wallet-accounts') || '{}')); const a0 = (acct.accounts || [])[0] || {}; - check('the account: spending-only, phrase unseen, saved to the device', a0.kind === 'spending' && a0.savingsLater && a0.seedSeen === false && a0.persisted, JSON.stringify({ kind: a0.kind, later: a0.savingsLater, seen: a0.seedSeen, persisted: a0.persisted })); + check('the account: one balance (no kind), phrase unseen, saved to the device', !a0.kind && !a0.savingsLater && !!a0.spendingSetup && a0.seedSeen === false && a0.persisted, JSON.stringify({ kind: a0.kind, later: a0.savingsLater, seen: a0.seedSeen, persisted: a0.persisted })); await openWalletPage(); check('Settings → Wallet opens with Ways back in', !!(await page.$('.ways-back')) && /ways back in/i.test(await text())); const views = await page.$$eval('.balance-settings-row[data-view]', (l) => l.map((e) => e.dataset.view)); check('the ways back in read as auth buttons', (await page.$$eval('.ways-back-add', (l) => l.map((e) => e.textContent.trim()))).join('|') === 'Passkey auth|Google auth|Nostr auth|Pen and paper', (await page.$$eval('.ways-back-add', (l) => l.map((e) => e.textContent.trim()))).join('|')); - check('only Spending is listed, with Add a savings account', views.join() === 'spending' && !!(await page.$('#add-savings')), views.join()); + check('one balance row, nothing to add', views.join() === 'all' && !(await page.$('#add-savings')), views.join()); if (process.env.SHOT2) { await page.evaluate(() => document.documentElement.setAttribute('data-theme', 'dark')); await page.evaluate(() => document.querySelector('.balance-settings-row').closest('.card').scrollIntoView()); await sleep(300); await page.screenshot({ path: process.env.SHOT2 }); await page.evaluate(() => document.documentElement.removeAttribute('data-theme')); } if (process.env.SHOT) { await page.evaluate(() => document.querySelector('.ways-back').scrollIntoView()); await page.screenshot({ path: process.env.SHOT }); } // a passkey: the relays are stubbed, so the publish fails offline — the @@ -141,16 +148,21 @@ try { await sleep(500); check('Pen and paper opens the recovery phrase card', !!(await page.$('.recovery-card .words'))); - await page.evaluate(() => document.getElementById('add-savings')?.click()); await sleep(800); + await page.evaluate(() => document.getElementById('separate-balances')?.click()); await sleep(800); const views2 = await page.$$eval('.balance-settings-row[data-view]', (l) => l.map((e) => e.dataset.view)); - check('Add a savings account adds Savings beside Spending', views2.join() === 'spending,savings' && !(await page.$('#add-savings')), views2.join()); + check('Show separately lists Spending and Savings', views2.join() === 'spending,savings', views2.join()); await page.goBack(); await page.goBack(); await sleep(800); s = await shape(); - check('the wallet now has both faces', s.carousel && s.faces === 2, JSON.stringify({ faces: s.faces, carousel: s.carousel })); + check('...and the wallet has both faces', s.carousel && s.faces === 2, JSON.stringify({ faces: s.faces, carousel: s.carousel })); await page.reload({ waitUntil: 'domcontentloaded' }); await page.waitForSelector('.balance-face', { timeout: 20000 }); await sleep(1500); s = await shape(); - check('a reload keeps Savings', s.carousel && s.faces === 2); + check('a reload keeps them apart', s.carousel && s.faces === 2); + await openWalletPage(); + await page.evaluate(() => document.getElementById('separate-balances')?.click()); await sleep(800); + await page.goBack(); await page.goBack(); await sleep(800); + s = await shape(); + check('unticked, one balance again', !s.carousel && s.faces === 1 && !!(await page.$('.balance-one'))); // A new device: everything here wiped, the relays holding only what the // passkey published. Sign in → Passkey opens THIS account, as itself. diff --git a/tools/unified-balance-test.js b/tools/unified-balance-test.js new file mode 100644 index 0000000..c349368 --- /dev/null +++ b/tools/unified-balance-test.js @@ -0,0 +1,127 @@ +// One balance (Adam, 2026-11-15: "combine the Ark and savings Bitcoin +// accounts into a single account … a combined history … the balance would be +// unified"). The Ark feature's side of it, without a browser: +// - the combined timeline tells a move between the two halves once: a board +// (its on-chain Sent + its Boarded) and an offboard to our own address +// (its Moved to Savings + the on-chain Received) are one row each, worth +// what the move cost; a board still confirming is one pending row; an +// offboard to someone else stays a payment +// - the separate Spending timeline is untouched +// - an on-chain address is paid from on-chain coins when there are any, and +// leaves Ark (offboard) only when there aren't +// Run: bun tools/unified-balance-test.js +import { buildFeatures } from '../src/features/index.js'; +import { getArkConfig } from '../src/api.js'; + +let fails = 0; +const check = (name, ok, detail = '') => { + console.log(` ${ok ? '✓' : '✗'} ${name}${detail ? ' — ' + String(detail).slice(0, 240) : ''}`); + if (!ok) fails++; +}; + +globalThis.fetch = async () => { throw new Error('offline (test)'); }; +globalThis.window = undefined; +globalThis.localStorage = { + _d: {}, getItem(k) { return this._d[k] ?? null; }, setItem(k, v) { this._d[k] = String(v); }, + removeItem(k) { delete this._d[k]; }, key(i) { return Object.keys(this._d)[i] ?? null; }, + get length() { return Object.keys(this._d).length; }, +}; +const cfg = getArkConfig(); +localStorage.setItem('btc-wallet-arkinfo:' + cfg.ark, JSON.stringify({ info: { minBoardAmountSat: 1000, boardFees: {} }, tip: 1, at: Date.now() })); + +const T = Date.now() - 3600_000; +const A = 'a'.repeat(64), B = 'b'.repeat(64), C = 'c'.repeat(64), D = 'd'.repeat(64), E = 'e'.repeat(64); +const arkState = { + _rev: 1, + vtxos: [{ id: 'v1', amountSat: 20000, state: 'spendable' }], + movements: [ + { id: 'm-board', type: 'board', amountSat: 9000, status: 'complete', txid: A, ts: T }, + { id: 'm-off', type: 'offboard', amountSat: 5000, feeSat: 300, status: 'complete', txid: B, to: 'bc1qown', ts: T + 1000 }, + { id: 'm-off-ext', type: 'offboard', amountSat: 7000, feeSat: 300, status: 'complete', txid: D, to: 'bc1qsomeoneelse', ts: T + 2000 }, + { id: 'm-recv', type: 'receive', amountSat: 1234, status: 'complete', vtxoId: 'v1', ts: T + 3000 }, + ], + actions: [ + { id: `board-${T + 4000}`, type: 'board', step: 'funded', amountSat: 3000, feeSat: 0, fundingTxid: C }, + ], +}; +// the on-chain wallet's view: board fundings out, the own offboard in +const txs = [ + { txid: A, net: -9200, confirmed: true, blockTime: T / 1000 }, + { txid: B, net: 5000, confirmed: true, blockTime: (T + 1000) / 1000 }, + { txid: C, net: -3150, confirmed: false }, + { txid: E, net: 40000, confirmed: true, blockTime: (T + 5000) / 1000 }, +]; + +const store = {}; +const wallet = { + watchOnly: false, offline: false, spendable: 0, feeRates: { halfHourFee: 1 }, + utxos: [], txs, history: txs, receive: [], change: [], + account: () => ({}), + isOnchainAddress: (a) => /^bc1q/.test(a), + loadFeatureState: (n, fb) => JSON.parse(store[n] || 'null') || fb, + saveFeatureState: (n, st) => { store[n] = JSON.stringify(st); }, + _cacheKey: () => 'test', saveCache: () => {}, + nostrPubkey: () => 'ab'.repeat(32), + registerCacheExtension: () => {}, registerRealtimeHook: () => {}, registerLoadHook: () => {}, + registerScanHook: () => {}, registerCacheSavedHook: () => {}, registerCoinLock: () => {}, + loadArkState: () => arkState, peekArkState: () => arkState, saveArkState: () => {}, + _arkNs: () => 'ns', _arkKey: () => 'k', _arkHoldKey: () => 'h', _arkVtxoOwner: () => null, adoptArkState: () => null, + freshReceive: () => ({ address: 'bc1qtest' }), freshChange: () => ({ address: 'bc1qchange' }), + balance: () => ({ spendableSat: 0 }), emit: () => {}, on: () => {}, +}; +let unified = true; +const ui = { account: 'spending', send: { recipients: [{ address: '' }] } }; +let features = []; +const ctx = { + h: (tag, attrs, ...kids) => ({ tag, attrs: attrs || {}, kids: kids.flat().filter((k) => k != null && k !== false) }), + ui, render: () => {}, wallet, + hook: (name, ...args) => { for (const f of features) if (f[name]) { const v = f[name](...args); if (v) return v; } return null; }, + getAccount: () => ui.account, setAccount: (a) => { ui.account = a; }, unifiedBalance: () => unified, + goHome: () => {}, openMnemonic: async () => {}, + fmtAmount: (n) => Number(n).toLocaleString('en-US'), unitLabel: () => 'sats', unitTag: () => 'sats', getUnit: () => 'sats', + parseAmount: (v) => parseInt(v, 10) || 0, amountField: (n) => String(n), + copyBtn: () => null, pasteBtn: () => null, toast: () => {}, blankSend: () => ({ recipients: [{ address: '' }] }), + openExternal: () => {}, +}; +features = buildFeatures(ctx); +const ark = features.find((f) => f.id === 'ark'); +const text = (n) => typeof n === 'string' || typeof n === 'number' ? String(n) : n && n.kids ? n.kids.map(text).join(' ') : ''; + +console.log('[one timeline]'); +{ + const rows = ark.historyEntries(txs, 'all'); + const replaced = rows.map((e) => e.replacesTxid).filter(Boolean).sort(); + check('the board, the own offboard and the confirming board stand in for their on-chain rows', replaced.join() === [A, B, C].sort().join(), replaced.map((x) => x[0]).join()); + check('the offboard to someone else is not a move', !replaced.includes(D)); + const byTx = Object.fromEntries(rows.filter((e) => e.replacesTxid).map((e) => [e.replacesTxid, text(e.render())])); + check('the board reads Made instant, worth its cost (9,200 out, 9,000 in)', /Made instant/.test(byTx[A]) && /\b200\b/.test(byTx[A]) && /9,000/.test(byTx[A]), byTx[A]); + check('the own offboard reads Moved on-chain, worth its fee', /Moved on-chain/.test(byTx[B]) && /\b300\b/.test(byTx[B]), byTx[B]); + check('the confirming board is one pending row', /Making instant/.test(byTx[C]) && /Pending/.test(byTx[C]) && /\b150\b/.test(byTx[C]), byTx[C]); + const others = rows.filter((e) => !e.replacesTxid).map((e) => text(e.render())).join(' | '); + check('the other Ark rows are as they were', /Received/.test(others) && !/Boarded/.test(others), others); + check('the offboard to someone else reads Sent, not Moved to Savings', /Sent/.test(others) && !/Savings/.test(others), others); +} + +console.log('[the Spending timeline, shown apart]'); +{ + const rows = ark.historyEntries([], 'spending'); + check('no row stands in for an on-chain one', rows.every((e) => !e.replacesTxid), rows.length); + check('the board is still its own Boarded row', rows.some((e) => /Boarded/.test(text(e.render())))); + check('Savings gets no Ark rows', ark.historyEntries(txs, 'savings').length === 0); +} + +console.log('[paying an on-chain address]'); +{ + ui.arkOffboardSend = null; wallet.spendable = 50000; + ark.matchSendText('bc1qrecipient'); + check('with on-chain coins it is an ordinary on-chain send', !ui.arkOffboardSend); + ui.arkOffboardSend = null; wallet.spendable = 0; + ark.matchSendText('bc1qrecipient'); + check('without them it leaves Ark', !!ui.arkOffboardSend && ui.arkOffboardSend.address === 'bc1qrecipient'); + ui.arkOffboardSend = null; wallet.spendable = 50000; unified = false; + ark.matchSendText('bc1qrecipient'); + check('shown apart, Spending still pays it from Ark (as before)', !!ui.arkOffboardSend); +} + +console.log(fails ? `FAIL (${fails})` : 'PASS'); +process.exit(fails ? 1 : 0); |
