diff --git a/.github/addrcheck.md b/.github/addrcheck.md new file mode 100644 index 000000000..94a4f023e --- /dev/null +++ b/.github/addrcheck.md @@ -0,0 +1,10 @@ +--- +title: Missing address entries +labels: ['ci', '@all.json'] +--- + +cc @polkadot-js/notifications + +Additional entries for addresses have been detected. + +Check the nightly cron output or run `yarn phishing:addrcheck` locally. The output as found from the test includes: diff --git a/.github/crosscheck.md b/.github/crosscheck.md index d8edf0721..2ddef7d66 100644 --- a/.github/crosscheck.md +++ b/.github/crosscheck.md @@ -1,5 +1,5 @@ --- -title: Phishing missing cross-check entries +title: Missing cross-check entries labels: ['ci', '@all.json'] --- diff --git a/.github/workflows/crosscheck.yml b/.github/workflows/crosscheck.yml index c44e2bd5c..163bc832b 100644 --- a/.github/workflows/crosscheck.yml +++ b/.github/workflows/crosscheck.yml @@ -14,7 +14,6 @@ jobs: run: | yarn install --immutable | grep -v 'YN0013' yarn phishing:crosscheck - - name: issue if: ${{ failure() }} uses: JasonEtco/create-an-issue@v2 @@ -22,3 +21,21 @@ jobs: GITHUB_TOKEN: ${{ secrets.GH_PAT }} with: filename: .github/crosscheck.md + + addrcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: check + env: + CI_LOG: 123 + run: | + yarn install --immutable | grep -v 'YN0013' + yarn phishing:addrcheck + - name: issue + if: ${{ failure() }} + uses: JasonEtco/create-an-issue@v2 + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + with: + filename: .github/addrcheck.md diff --git a/package.json b/package.json index 597ae2b6b..1a4ea287d 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,10 @@ "build:release": "polkadot-ci-ghact-build --skip-beta", "lint": "polkadot-dev-run-lint", "clean": "polkadot-dev-clean-build", + "phishing:addrcheck": "polkadot-dev-run-test packages/phishing/src/addrcheck", "phishing:crosscheck": "polkadot-dev-run-test packages/phishing/src/crosscheck", "postinstall": "polkadot-dev-yarn-only", - "test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck" + "test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns addrcheck --testPathIgnorePatterns crosscheck" }, "devDependencies": { "@babel/core": "^7.12.10", diff --git a/packages/phishing/src/addrcheck.spec.ts b/packages/phishing/src/addrcheck.spec.ts new file mode 100644 index 000000000..76a31c05a --- /dev/null +++ b/packages/phishing/src/addrcheck.spec.ts @@ -0,0 +1,55 @@ +// Copyright 2020-2021 @polkadot/phishing authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import fs from 'fs'; + +import { fetch } from '@polkadot/x-fetch'; + +import { retrieveAddrList } from '.'; + +function assertAndLog (check: boolean, error: string): void { + if (!check) { + process.env.CI_LOG && fs.appendFileSync('./.github/addrcheck.md', ` + +${error} +`); + + throw new Error(error); + } +} + +function delayLoop (): Promise { + return new Promise((resolve): void => { + setTimeout(() => resolve(), 1500); + }); +} + +describe('addrcheck', (): void => { + let ours: Record; + + beforeAll(async (): Promise => { + jest.setTimeout(120000); + ours = await retrieveAddrList(); + }); + + it('has all entries from polkadot.center', async (): Promise => { + const found: string[] = []; + + for (let i = 0; i < 25; i++) { + const result = await (await fetch('https://polkadot.center/get_wallet.php')).json() as Record; + const wallet = result.wallet.replace('\r', ''); + + if (!found.includes(wallet)) { + found.push(wallet); + } + + await delayLoop(); + } + + console.log('polkadot.center', JSON.stringify(found)); + + const missing = found.filter((a) => !ours['polkadot.center'].includes(a)); + + assertAndLog(missing.length === 0, `Missing entries found for polkadot.center: ${JSON.stringify(missing)}`); + }); +}); diff --git a/packages/phishing/src/crosscheck.spec.ts b/packages/phishing/src/crosscheck.spec.ts index 16b8ded8f..874b91593 100644 --- a/packages/phishing/src/crosscheck.spec.ts +++ b/packages/phishing/src/crosscheck.spec.ts @@ -40,6 +40,7 @@ describe('crosscheck', (): void => { let ours: string[]; beforeAll(async (): Promise => { + jest.setTimeout(120000); ours = (await retrieveHostList()).deny; });