aboutsummaryrefslogtreecommitdiffstats
path: root/tools/amber-dm-upgrade-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/amber-dm-upgrade-test.js')
-rw-r--r--tools/amber-dm-upgrade-test.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/amber-dm-upgrade-test.js b/tools/amber-dm-upgrade-test.js
index 4e34a94..9a5070a 100644
--- a/tools/amber-dm-upgrade-test.js
+++ b/tools/amber-dm-upgrade-test.js
@@ -6,7 +6,7 @@
// the same account over NIP-46 (nostrconnect), after which every wrap the
// relays hold is opened again — including ones the old code wrote off.
// The remote signer is played by this script over a shimmed relay.
-// Run: bun tools/amber-dm-upgrade-test.js
+// Run: bun tools/amber-dm-upgrade-test.js (and ALL_LOGGED=1 bun tools/amber-dm-upgrade-test.js)
import puppeteer from './puppeteer.js';
import { cacheKeyFor } from '../src/wallet.js';
import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure';
@@ -20,6 +20,9 @@ const SK = generateSecretKey(); const PK = getPublicKey(SK); // the Amber accoun
const PEER_SK = generateSecretKey(); const PEER = getPublicKey(PEER_SK);
const OLD = wrapEvent(PEER_SK, { publicKey: PK }, 'an old message the wrap log wrote off');
const NEW = wrapEvent(PEER_SK, { publicKey: PK }, 'a message from before the upgrade');
+// ALL_LOGGED=1: every wrap already written off by the old code, so nothing
+// is pending and the Amber signer is never woken (isolabellart's phone)
+const ALL = process.env.ALL_LOGGED === '1';
const html = await buildHtml({ minify: true, pwa: false });
const server = Bun.serve({ port: 5311, fetch: (req) => { const p = new URL(req.url).pathname; if (p === '/verify-worker.js' || p === '/nip46.js' || p.startsWith('/punks')) return new Response(Bun.file('dist' + p)); return new Response(html, { headers: { 'content-type': 'text/html' } }); } });
@@ -106,12 +109,12 @@ try {
const base = cacheKeyFor(mn + '\n');
// an Amber login, and a wrap log in which the old code had already
// written OLD off as opened
- await page.evaluate(([k, pk, oldId]) => {
+ await page.evaluate(([k, pk, oldId, newId]) => {
localStorage.setItem(k + ':nostrlogin', JSON.stringify({ pubkey: pk, session: { amber: pk }, via: 'amber' }));
const m = JSON.parse(localStorage.getItem(k + ':messages') || '{}');
- m.wraps = [oldId.slice(0, 16)]; m.dmHeal = 2;
+ m.wraps = [oldId.slice(0, 16)].concat(newId ? [newId.slice(0, 16)] : []); m.dmHeal = 2;
localStorage.setItem(k + ':messages', JSON.stringify(m));
- }, [base, PK, OLD.id]);
+ }, [base, PK, OLD.id, ALL ? NEW.id : null]);
await page.reload({ waitUntil: 'domcontentloaded' });
await waitText('receive', 20000);
await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Messages"]')?.click());
@@ -121,7 +124,7 @@ try {
await sleep(4000);
check('no decrypt intent went to Amber for an arriving wrap', !(await page.evaluate(() => window.__amberUrls.some((u) => /nip44_decrypt/.test(u)))));
check('neither message shows', !(await text()).includes('a message from before the upgrade') && !(await text()).includes('wrote off'));
- check('the arriving wrap is not logged as opened', await page.evaluate(([k, id]) => !(JSON.parse(localStorage.getItem(k + ':messages') || '{}').wraps || []).includes(id.slice(0, 16)), [base, NEW.id]));
+ if (!ALL) check('the arriving wrap is not logged as opened', await page.evaluate(([k, id]) => !(JSON.parse(localStorage.getItem(k + ':messages') || '{}').wraps || []).includes(id.slice(0, 16)), [base, NEW.id]));
console.log('\n[Connect Amber: the same account over NIP-46]');
await click('connect amber'); await sleep(300);