aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/own-boost-feed-test.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/tools/own-boost-feed-test.js b/tools/own-boost-feed-test.js
index e5e3440..ab2a88f 100644
--- a/tools/own-boost-feed-test.js
+++ b/tools/own-boost-feed-test.js
@@ -7,7 +7,7 @@
// Run: bun tools/own-boost-feed-test.js
import puppeteer, { seedWords, skipSeedCheck } from './puppeteer.js';
import { cacheKeyFor } from '../src/wallet.js';
-import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure';
+import { generateSecretKey, getPublicKey, finalizeEvent, verifyEvent } from 'nostr-tools/pure';
import { privateKeyFromSeedWords } from 'nostr-tools/nip06';
import { buildHtml } from '../build.js';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -78,7 +78,8 @@ try {
for (let i = 0; i < 40; i++) { r = await rows(); top = r[0]; if (top && top.paff && top.reposted) break; await sleep(250); }
check('the boost is at the top of my feed, under "… reposted"', !!top && top.paff && top.reposted, JSON.stringify(r.slice(0, 3)));
check('the row I tapped is still where it was', r.filter((x) => x.paff).length === 2);
- check('the boost was published', await page.evaluate(() => JSON.parse(localStorage.getItem('__pub') || '[]').length === 1));
+ const first = await page.evaluate(() => JSON.parse(localStorage.getItem('__pub') || '[]'));
+ check('the boost was published, with the signed post inside', first.length === 1 && verifyEvent(JSON.parse(first[0].content)));
await sleep(1500); // the feed cache is written
await page.reload({ waitUntil: 'domcontentloaded' });
await waitText('receive', 20000);
@@ -88,6 +89,13 @@ try {
r = await rows();
const both = (r) => !!r[0] && r[0].paff && r[0].reposted && r.filter((x) => x.paff).length === 2 && r.filter((x) => x.paff && x.reposted).length === 1 && r[r.length - 1].paff && !r[r.length - 1].reposted;
check('after a reload: my boost first (the newest), the post itself still in its place', both(r), JSON.stringify(r.map((x) => [+x.paff, +x.reposted])));
+ // a post painted from the saved feed has no signature in memory: its boost must still carry one
+ const before = await page.evaluate(() => JSON.parse(localStorage.getItem('__pub') || '[]').length);
+ const cachedTap = await page.evaluate(() => { const row = [...document.querySelectorAll('.notes-feed > .row[data-key]')].find((n) => n.textContent.includes('filler post number 3 ')); const b = row && [...row.querySelectorAll('.note-acts button')].find((x) => /boost/i.test(x.getAttribute('aria-label') || x.title || '')); if (b) { b.click(); return true; } return false; });
+ let second = null;
+ for (let i = 0; i < 40 && !second; i++) { await sleep(250); second = await page.evaluate((n) => JSON.parse(localStorage.getItem('__pub') || '[]')[n] || null, before); }
+ const inner = second && JSON.parse(second.content);
+ check('a boost of a post from the saved feed carries the signed post', cachedTap && !!inner && !!inner.sig && verifyEvent(inner), JSON.stringify(inner && Object.keys(inner)));
// a second device: nothing cached, the post and the boost both come from relays
await page.evaluate(() => { for (const k of Object.keys(localStorage)) if (/feed-cache|feedcache|:feed:|notes/i.test(k)) localStorage.removeItem(k); });
await page.evaluate(async () => { if (indexedDB.databases) for (const d of await indexedDB.databases()) if (/feed|note/i.test(d.name || '')) indexedDB.deleteDatabase(d.name); });
@@ -97,7 +105,8 @@ try {
await waitText('Running a PAFF server', 30000);
await sleep(4000);
r = await rows();
- check('with no cache: the same two rows', both(r), JSON.stringify(r.map((x) => [+x.paff, +x.reposted])));
+ const p = r.filter((x) => x.paff);
+ check('with no cache: my boosts lead in time order, the post itself still in its place', r[0].reposted && r[1].reposted && r[1].paff && p.length === 2 && !p[1].reposted && r.filter((x) => x.reposted).length === 2, JSON.stringify(r.map((x) => [+x.paff, +x.reposted])));
check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
} finally { await browser.close(); server.stop(true); }
console.log(ok ? '\n✅ my own boost shows in my feed' : '\n❌ failed');