diff --git a/packages/phishing/src/addrcheck.spec.ts b/packages/phishing/src/addrcheck.spec.ts index 8761fb276..2bb266f74 100644 --- a/packages/phishing/src/addrcheck.spec.ts +++ b/packages/phishing/src/addrcheck.spec.ts @@ -18,14 +18,7 @@ ${error} } } -function delayLoop (): Promise { - return new Promise((resolve): void => { - setTimeout(() => resolve(), 1500); - }); -} - -// shared between polkadot.center & polkadot-event.com (addresses are also the same on first run) -async function checkGetWallet (ours: Record, site: string): Promise { +async function loopSome (ours: Record, site: string, matcher: () => Promise): Promise { const all = Object.values(ours).reduce((all: string[], addrs: string[]): string[] => { all.push(...addrs); @@ -33,22 +26,22 @@ async function checkGetWallet (ours: Record, site: string): Pr }, []); const found: string[] = []; - for (let i = 0; i < 25; i++) { + for (let i = 0; i < 20; i++) { try { - const result = await (await fetch(`https://${site}/get_wallet.php`)).json() as Record; + const addresses = await matcher(); - if (result && result.wallet) { - const wallet = result.wallet.replace('\r', ''); - - if (!found.includes(wallet)) { - found.push(wallet); - } + if (addresses) { + addresses.forEach((address): void => { + if (address && !found.includes(address)) { + found.push(address); + } + }); } } catch (error) { // ignore } - await delayLoop(); + await new Promise((resolve) => setTimeout(() => resolve(true), Math.floor((Math.random() * 750) + 1000))); } console.log(site, JSON.stringify(found)); @@ -58,6 +51,29 @@ async function checkGetWallet (ours: Record, site: string): Pr assertAndLog(missing.length === 0, `Missing entries found for ${site}: ${JSON.stringify(missing)}`); } +// shared between polkadot.center & polkadot-event.com (addresses are also the same on first run) +async function checkGetWallet (ours: Record, site: string): Promise { + await loopSome(ours, site, async (): Promise => { + const result = await (await fetch(`https://${site}/get_wallet.php`)).json() as Record; + + return (result && result.wallet) + ? [result.wallet.replace('\r', '').trim()] + : null; + }); +} + +// shared between polkadotlive.network & polkadots.network +async function checkTrnsctin (ours: Record, site: string, url: string): Promise { + await loopSome(ours, site, async (): Promise => { + const result = await (await fetch(url)).text(); + const match = result.match(/

(.*?)<\/p>/g); + + return match && match.length + ? match.map((v) => v.replace(/<\/?p( id="trnsctin")?>/g, '').trim()) + : null; + }); +} + describe('addrcheck', (): void => { let ours: Record; @@ -73,4 +89,23 @@ describe('addrcheck', (): void => { it('has all entries from polkadot-event.com', async (): Promise => { await checkGetWallet(ours, 'polkadot-event.com'); }); + + it('has the addresses for polkadotlive.network', async (): Promise => { + await checkTrnsctin(ours, 'polkadotlive.network', 'https://polkadotlive.network/block-assets/index.html'); + }); + + it('has the addresses for polkadots.network', async (): Promise => { + await checkTrnsctin(ours, 'polkadots.network', 'https://polkadots.network/block.html'); + }); + + it('has the addresses for dot4.org', async (): Promise => { + await loopSome(ours, 'dot4.org', async (): Promise => { + const result = await (await fetch('https://dot4.org/promo/')).text(); + const match = result.match(/

(.*?)<\/p>/g); + + return match && match.length + ? match.map((v) => v.replace(/<\/?p( class="payment-title")?>/g, '').trim()) + : null; + }); + }); });