Additional addrcheck (#90)

This commit is contained in:
Jaco Greeff
2021-02-12 09:52:32 +01:00
committed by GitHub
parent aad3294add
commit 165782eafb
+59 -33
View File
@@ -7,18 +7,20 @@ import { fetch } from '@polkadot/x-fetch';
import { retrieveAddrList } from '.'; import { retrieveAddrList } from '.';
function assertAndLog (check: boolean, error: string): void { function logMissing (site: string, missing: string[]): string | null {
if (!check) { if (missing.length) {
process.env.CI_LOG && fs.appendFileSync('./.github/addrcheck.md', ` 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<string, string[]>, site: string, matcher: () => Promise<string[] | null>): Promise<void> { async function loopSome (ours: Record<string, string[]>, site: string, matcher: () => Promise<string[] | null>): Promise<string | null> {
const all = Object.values(ours).reduce((all: string[], addrs: string[]): string[] => { const all = Object.values(ours).reduce((all: string[], addrs: string[]): string[] => {
all.push(...addrs); all.push(...addrs);
@@ -46,14 +48,12 @@ async function loopSome (ours: Record<string, string[]>, site: string, matcher:
console.log(site, JSON.stringify(found)); console.log(site, JSON.stringify(found));
const missing = found.filter((a) => !all.includes(a)); return logMissing(site, found.filter((a) => !all.includes(a)));
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) // shared between polkadot.center & polkadot-event.com (addresses are also the same on first run)
async function checkGetWallet (ours: Record<string, string[]>, site: string): Promise<void> { function checkGetWallet (ours: Record<string, string[]>, site: string): Promise<string | null> {
await loopSome(ours, site, async (): Promise<string[] | null> => { return loopSome(ours, site, async (): Promise<string[] | null> => {
const result = await (await fetch(`https://${site}/get_wallet.php`)).json() as Record<string, string>; const result = await (await fetch(`https://${site}/get_wallet.php`)).json() as Record<string, string>;
return (result && result.wallet) return (result && result.wallet)
@@ -62,9 +62,9 @@ async function checkGetWallet (ours: Record<string, string[]>, site: string): Pr
}); });
} }
// shared between polkadotlive.network & polkadots.network // shared between claimpolka.live & polkadots.network
async function checkTrnsctin (ours: Record<string, string[]>, site: string, url: string): Promise<void> { function checkTrnsctin (ours: Record<string, string[]>, site: string, url: string): Promise<string | null> {
await loopSome(ours, site, async (): Promise<string[] | null> => { return loopSome(ours, site, async (): Promise<string[] | null> => {
const result = await (await fetch(url)).text(); const result = await (await fetch(url)).text();
const match = result.match(/<p id="trnsctin">(.*?)<\/p>/g); const match = result.match(/<p id="trnsctin">(.*?)<\/p>/g);
@@ -74,6 +74,18 @@ async function checkTrnsctin (ours: Record<string, string[]>, site: string, url:
}); });
} }
// shared between polkadotlive.network & polkadot-airdrop.org
async function checkRealAddr (ours: Record<string, string[]>, site: string, url: string): Promise<string | null> {
return loopSome(ours, site, async (): Promise<string[] | null> => {
const result = await (await fetch(url)).text();
const match = result.match(/<span class="real-address">(.*?)<\/span>/g);
return match && match.length
? match.map((v) => v.replace(/<\/?span( class="real-address")?>/g, '').trim())
: null;
});
}
describe('addrcheck', (): void => { describe('addrcheck', (): void => {
let ours: Record<string, string[]>; let ours: Record<string, string[]>;
@@ -82,30 +94,44 @@ describe('addrcheck', (): void => {
ours = await retrieveAddrList(); ours = await retrieveAddrList();
}); });
it('has all entries from polkadot.center', async (): Promise<void> => { it('has all known addresses', async (): Promise<void> => {
await checkGetWallet(ours, 'polkadot.center'); 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<string[] | null> => {
const result = await (await fetch('https://polkadotairdrop.com/address/')).text();
const match = result.match(/<cool>(.*?)<\/cool>/g);
it('has all entries from polkadot-event.com', async (): Promise<void> => { return match && match.length
await checkGetWallet(ours, 'polkadot-event.com'); ? match.map((v) => v.replace(/<\/?cool>/g, '').trim())
}); : null;
}),
loopSome(ours, 'polkadot-get.com', async (): Promise<string[] | null> => {
const result = await (await fetch('https://polkadot-get.com/')).text();
const match = result.match(/<span id="cosh">(.*?)<\/span>/g);
it('has the addresses for polkadotlive.network', async (): Promise<void> => { return match && match.length
await checkTrnsctin(ours, 'polkadotlive.network', 'https://polkadotlive.network/block-assets/index.html'); ? match.map((v) => v.replace(/<\/?span( id="cosh")?>/g, '').trim())
}); : null;
}),
loopSome(ours, 'dot4.org', async (): Promise<string[] | null> => {
const result = await (await fetch('https://dot4.org/promo/')).text();
const match = result.match(/<p class="payment-title">(.*?)<\/p>/g);
it('has the addresses for polkadots.network', async (): Promise<void> => { return match && match.length
await checkTrnsctin(ours, 'polkadots.network', 'https://polkadots.network/block.html'); ? match.map((v) => v.replace(/<\/?p( class="payment-title")?>/g, '').trim())
}); : null;
})
]);
it('has the addresses for dot4.org', async (): Promise<void> => { const missing = results.filter((site) => !!site);
await loopSome(ours, 'dot4.org', async (): Promise<string[] | null> => {
const result = await (await fetch('https://dot4.org/promo/')).text();
const match = result.match(/<p class="payment-title">(.*?)<\/p>/g);
return match && match.length missing.length && console.error(`Discrepancies found on ${missing.join(', ')}`);
? match.map((v) => v.replace(/<\/?p( class="payment-title")?>/g, '').trim())
: null; expect(missing).toHaveLength(0);
});
}); });
}); });