diff --git a/packages/phishing/src/addrcheck.spec.ts b/packages/phishing/src/addrcheck.spec.ts index 2bb266f74..3b413ee46 100644 --- a/packages/phishing/src/addrcheck.spec.ts +++ b/packages/phishing/src/addrcheck.spec.ts @@ -7,18 +7,20 @@ import { fetch } from '@polkadot/x-fetch'; import { retrieveAddrList } from '.'; -function assertAndLog (check: boolean, error: string): void { - if (!check) { +function logMissing (site: string, missing: string[]): string | null { + if (missing.length) { process.env.CI_LOG && fs.appendFileSync('./.github/addrcheck.md', ` -${error} +Missing entries found for ${site}: ${JSON.stringify(missing)} `); - throw new Error(error); + return site; } + + return null; } -async function loopSome (ours: Record, site: string, matcher: () => Promise): 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); @@ -46,14 +48,12 @@ async function loopSome (ours: Record, site: string, matcher: console.log(site, JSON.stringify(found)); - const missing = found.filter((a) => !all.includes(a)); - - assertAndLog(missing.length === 0, `Missing entries found for ${site}: ${JSON.stringify(missing)}`); + return logMissing(site, found.filter((a) => !all.includes(a))); } // 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 => { +function checkGetWallet (ours: Record, site: string): Promise { + return loopSome(ours, site, async (): Promise => { const result = await (await fetch(`https://${site}/get_wallet.php`)).json() as Record; return (result && result.wallet) @@ -62,9 +62,9 @@ async function checkGetWallet (ours: Record, site: string): Pr }); } -// shared between polkadotlive.network & polkadots.network -async function checkTrnsctin (ours: Record, site: string, url: string): Promise { - await loopSome(ours, site, async (): Promise => { +// shared between claimpolka.live & polkadots.network +function checkTrnsctin (ours: Record, site: string, url: string): Promise { + return loopSome(ours, site, async (): Promise => { const result = await (await fetch(url)).text(); const match = result.match(/

(.*?)<\/p>/g); @@ -74,6 +74,18 @@ async function checkTrnsctin (ours: Record, site: string, url: }); } +// shared between polkadotlive.network & polkadot-airdrop.org +async function checkRealAddr (ours: Record, site: string, url: string): Promise { + return loopSome(ours, site, async (): Promise => { + const result = await (await fetch(url)).text(); + const match = result.match(/(.*?)<\/span>/g); + + return match && match.length + ? match.map((v) => v.replace(/<\/?span( class="real-address")?>/g, '').trim()) + : null; + }); +} + describe('addrcheck', (): void => { let ours: Record; @@ -82,30 +94,44 @@ describe('addrcheck', (): void => { ours = await retrieveAddrList(); }); - it('has all entries from polkadot.center', async (): Promise => { - await checkGetWallet(ours, 'polkadot.center'); - }); + it('has all known addresses', async (): Promise => { + const results = await Promise.all([ + checkGetWallet(ours, 'polkadot.center'), + checkGetWallet(ours, 'polkadot-event.com'), + checkTrnsctin(ours, 'polkadotlive.network', 'https://polkadotlive.network/block-assets/index.html'), + checkTrnsctin(ours, 'polkadots.network', 'https://polkadots.network/block.html'), + checkRealAddr(ours, 'claimpolka.live', 'https://claimpolka.live/claim/index.html'), + checkRealAddr(ours, 'polkadot-airdrop.org', 'https://polkadot-airdrop.org/block/index.html'), + loopSome(ours, 'polkadotairdrop.com', async (): Promise => { + const result = await (await fetch('https://polkadotairdrop.com/address/')).text(); + const match = result.match(/(.*?)<\/cool>/g); - it('has all entries from polkadot-event.com', async (): Promise => { - await checkGetWallet(ours, 'polkadot-event.com'); - }); + return match && match.length + ? match.map((v) => v.replace(/<\/?cool>/g, '').trim()) + : null; + }), + loopSome(ours, 'polkadot-get.com', async (): Promise => { + const result = await (await fetch('https://polkadot-get.com/')).text(); + const match = result.match(/(.*?)<\/span>/g); - it('has the addresses for polkadotlive.network', async (): Promise => { - await checkTrnsctin(ours, 'polkadotlive.network', 'https://polkadotlive.network/block-assets/index.html'); - }); + return match && match.length + ? match.map((v) => v.replace(/<\/?span( id="cosh")?>/g, '').trim()) + : null; + }), + loopSome(ours, 'dot4.org', async (): Promise => { + const result = await (await fetch('https://dot4.org/promo/')).text(); + const match = result.match(/

(.*?)<\/p>/g); - it('has the addresses for polkadots.network', async (): Promise => { - await checkTrnsctin(ours, 'polkadots.network', 'https://polkadots.network/block.html'); - }); + return match && match.length + ? match.map((v) => v.replace(/<\/?p( class="payment-title")?>/g, '').trim()) + : null; + }) + ]); - 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); + const missing = results.filter((site) => !!site); - return match && match.length - ? match.map((v) => v.replace(/<\/?p( class="payment-title")?>/g, '').trim()) - : null; - }); + missing.length && console.error(`Discrepancies found on ${missing.join(', ')}`); + + expect(missing).toHaveLength(0); }); });