mirror of
https://github.com/pezkuwichain/phishing.git
synced 2026-04-30 06:08:06 +00:00
Additional addrcheck (#90)
This commit is contained in:
@@ -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<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[] => {
|
||||
all.push(...addrs);
|
||||
|
||||
@@ -46,14 +48,12 @@ async function loopSome (ours: Record<string, string[]>, 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<string, string[]>, site: string): Promise<void> {
|
||||
await loopSome(ours, site, async (): Promise<string[] | null> => {
|
||||
function checkGetWallet (ours: Record<string, string[]>, site: string): 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>;
|
||||
|
||||
return (result && result.wallet)
|
||||
@@ -62,9 +62,9 @@ async function checkGetWallet (ours: Record<string, string[]>, site: string): Pr
|
||||
});
|
||||
}
|
||||
|
||||
// shared between polkadotlive.network & polkadots.network
|
||||
async function checkTrnsctin (ours: Record<string, string[]>, site: string, url: string): Promise<void> {
|
||||
await loopSome(ours, site, async (): Promise<string[] | null> => {
|
||||
// shared between claimpolka.live & polkadots.network
|
||||
function checkTrnsctin (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(/<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 => {
|
||||
let ours: Record<string, string[]>;
|
||||
|
||||
@@ -82,30 +94,44 @@ describe('addrcheck', (): void => {
|
||||
ours = await retrieveAddrList();
|
||||
});
|
||||
|
||||
it('has all entries from polkadot.center', async (): Promise<void> => {
|
||||
await checkGetWallet(ours, 'polkadot.center');
|
||||
});
|
||||
it('has all known addresses', async (): Promise<void> => {
|
||||
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> => {
|
||||
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<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> => {
|
||||
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<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> => {
|
||||
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<void> => {
|
||||
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);
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user