Skip to content

Commit

Permalink
Updates 3 (#7)
Browse files Browse the repository at this point in the history
* Update paseo RPC wss://sys.dotters.network/paseo (paritytech#398)

* Prettier write

* Make properties public. Remove try catches. Lint

* remove console.log

* Increase test timeout

* try installing playwright with yarn

* Moved GitLab checks to GitHub's action (paritytech#402)

Resolves paritytech#401

* Bump yaml from 2.4.1 to 2.4.2 in /client in the npm_and_yarn group across 1 directory (paritytech#403)

* remove empty spaces

* Address more PR comments

* Address comments

* Add type check function to test file

* Fix import so that it works from tests dir2

* Update eng-automation

* fix import

* try after linting

* Suppress ESLint to get CICD to run

* yarn:fix

* pass block number to mock provider

* fix tests

* yarn format:fix

---------

Co-authored-by: Maksym H <1177472+mordamax@users.noreply.github.com>
Co-authored-by: Javier Bullrich <javier@bullrich.dev>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored May 1, 2024
1 parent 944685c commit 81a777a
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 91 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ jobs:
working-directory: client
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4.0.2
uses: actions/setup-node@v4
with:
node-version: 20
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install --frozen-lockfile
- run: yarn run check
- name: Install Playwright
Expand All @@ -33,7 +44,7 @@ jobs:
PUBLIC_CAPTCHA_KEY: 6LcgFI4nAAAAAATrEMoJ6zBacsx5udc1UhGFXemH
GITHUB_PAGES: "/${{ github.event.repository.name }}"
STATIC: true
- uses: actions/upload-artifact@v4.3.1
- uses: actions/upload-artifact@v4
with:
name: faucet
path: ./client/build
Expand All @@ -48,18 +59,18 @@ jobs:
needs: [build-faucet]
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
uses: actions/checkout@v4
- name: Download page
uses: actions/download-artifact@v4.1.4
uses: actions/download-artifact@v4
with:
name: faucet
path: ./dist
- name: Setup Pages
uses: actions/configure-pages@v4.0.0
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3.0.1
uses: actions/upload-pages-artifact@v3
with:
path: ./dist
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4.0.5
uses: actions/deploy-pages@v4
63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Tests

on:
push:
branches: ["main"]
pull_request:

permissions:
contents: read

jobs:
check-linting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install deps in root
run: yarn install --frozen-lockfile
- run: yarn generate:papi:e2e
- name: Install deps in client
run: yarn install --frozen-lockfile
working-directory: client
- run: yarn typecheck
- run: yarn format
- run: yarn lint
check-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install deps in root
run: yarn install --frozen-lockfile
- run: yarn test
20 changes: 0 additions & 20 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,6 @@ variables:
--file "$DOCKERFILE" .
- $BUILDAH_COMMAND info

#### stage: test

check-linting:
stage: test
<<: *common-refs
<<: *kubernetes-env
script:
- yarn --frozen-lockfile
- yarn generate:papi:e2e
- cd client && yarn --frozen-lockfile && cd ..
- yarn typecheck && yarn format && yarn lint

check-tests:
stage: test
<<: *common-refs
<<: *kubernetes-env
script:
- yarn --frozen-lockfile
- yarn test

#### stage: build

build-docker:
Expand Down
1 change: 0 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"svelte-check": "^3.6.1",
"svelte-markdown": "^0.4.0",
"svelte-meta-tags": "^3.1.0",
"svelte-preprocess": "^5.1.1",
"tailwindcss": "^3.3.5",
"tslib": "^2.6.2",
"typescript": "^5.3.2",
Expand Down
5 changes: 2 additions & 3 deletions client/src/lib/components/CaptchaV2.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { CaptchaProvider } from "$lib/utils/captcha";
export let captchaKey: string;
export let captchaProvider: string;
export let captchaProvider: CaptchaProvider;
const dispatch = createEventDispatcher<{ token: string }>();
const captchaId = "captcha_element";
Expand Down Expand Up @@ -57,8 +57,7 @@
dispatch("token", token);
// Forces a new captcha on page reload
if (captchaProvider === CaptchaProvider.procaptcha) {
window.localStorage.removeItem("@prosopo/current_account");
window.localStorage.removeItem("@prosopo/provider");
window.localStorage.removeItem("@prosopo/procaptcha");
}
};
Expand Down
14 changes: 4 additions & 10 deletions client/src/lib/components/Form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { request as faucetRequest } from "../utils";
import CaptchaV2 from "./CaptchaV2.svelte";
import NetworkInput from "./NetworkInput.svelte";
import { CaptchaProvider } from "$lib/utils/captcha";
import { CaptchaProvider, getCaptchaProvider } from "$lib/utils/captcha";
import NetworkDropdown from "./NetworkDropdown.svelte";
import type { NetworkData } from "$lib/utils/networkData";
Expand All @@ -14,7 +14,8 @@
let token: string = "";
let formValid: boolean;
$: formValid = !!address && !!token && !!network;
const captchaProvider = getCaptchaProvider(PUBLIC_CAPTCHA_PROVIDER);
const captchaKey = captchaProvider === CaptchaProvider.procaptcha ? PUBLIC_PROSOPO_SITE_KEY : PUBLIC_RECAPTCHA_KEY;
let webRequest: Promise<string>;
function onSubmit() {
Expand Down Expand Up @@ -59,14 +60,7 @@
</div>
{#if !webRequest}
<div class="place-items-center">
<CaptchaV2
captchaKey={PUBLIC_CAPTCHA_PROVIDER === CaptchaProvider.procaptcha
? PUBLIC_PROSOPO_SITE_KEY
: PUBLIC_RECAPTCHA_KEY}
captchaProvider={PUBLIC_CAPTCHA_PROVIDER}
on:token={onToken}
theme="dark"
/>
<CaptchaV2 {captchaKey} {captchaProvider} on:token={onToken} theme="dark" />
</div>
<button class="submit-btn" type="submit" data-testid="submit-button" disabled={!formValid}>
Get some {$testnet.currency}s
Expand Down
6 changes: 6 additions & 0 deletions client/src/lib/utils/captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ export enum CaptchaProvider {
procaptcha = "procaptcha",
recaptcha = "recaptcha",
}

export const getCaptchaProvider = (provider: string): CaptchaProvider => {
if (provider === CaptchaProvider.procaptcha) return CaptchaProvider.procaptcha;
if (provider === CaptchaProvider.recaptcha) return CaptchaProvider.recaptcha;
throw new Error(`⭕ - Invalid captcha provider: ${provider}`);
};
14 changes: 6 additions & 8 deletions client/tests/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type Frame, type FullConfig, type Locator, type Page, expect, test } from "@playwright/test";
import { stringToHex } from "@polkadot/util";

import { getCaptchaProvider as getCaptchaProviderTyped } from "../src/lib/utils/captcha";

type FormSubmit = {
address: string;
captchaResponse: string;
Expand All @@ -9,7 +11,7 @@ type FormSubmit = {

type CaptchaProvider = "recaptcha" | "procaptcha";

const getFormElements = async (page: Page, captchaProvider: "recaptcha" | "procaptcha", getCaptcha = false) => {
const getFormElements = async (page: Page, captchaProvider: CaptchaProvider, getCaptcha = false) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
let captcha: Locator = {} as Locator;
if (getCaptcha) {
Expand Down Expand Up @@ -113,15 +115,11 @@ export class FaucetTests {
if (!env) {
throw new Error("No env vars in project");
}
const captchaProvider = env.PUBLIC_CAPTCHA_PROVIDER;
if (!captchaProvider) {

if (!env.PUBLIC_CAPTCHA_PROVIDER) {
throw new Error(`No env var value found for PUBLIC_CAPTCHA_PROVIDER`);
}
if (!["recaptcha", "procaptcha"].includes(captchaProvider)) {
throw new Error(`Invalid captcha provider: ${captchaProvider}`);
}

return captchaProvider as CaptchaProvider;
return getCaptchaProviderTyped(env.PUBLIC_CAPTCHA_PROVIDER);
};

runTests(): void {
Expand Down
24 changes: 3 additions & 21 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1077,13 +1077,6 @@ magic-string@^0.30.3, magic-string@^0.30.4:
dependencies:
"@jridgewell/sourcemap-codec" "^1.4.15"

magic-string@^0.30.5:
version "0.30.10"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.10.tgz#123d9c41a0cb5640c892b041d4cfb3bd0aa4b39e"
integrity sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==
dependencies:
"@jridgewell/sourcemap-codec" "^1.4.15"

marked@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/marked/-/marked-5.1.2.tgz#62b5ccfc75adf72ca3b64b2879b551d89e77677f"
Expand Down Expand Up @@ -1528,17 +1521,6 @@ svelte-preprocess@^5.1.0:
sorcery "^0.11.0"
strip-indent "^3.0.0"

svelte-preprocess@^5.1.1:
version "5.1.4"
resolved "https://registry.yarnpkg.com/svelte-preprocess/-/svelte-preprocess-5.1.4.tgz#14ada075c94bbd2b71c5ec70ff72f8ebe1c95b91"
integrity sha512-IvnbQ6D6Ao3Gg6ftiM5tdbR6aAETwjhHV+UKGf5bHGYR69RQvF1ho0JKPcbUON4vy4R7zom13jPjgdOWCQ5hDA==
dependencies:
"@types/pug" "^2.0.6"
detect-indent "^6.1.0"
magic-string "^0.30.5"
sorcery "^0.11.0"
strip-indent "^3.0.0"

svelte@^4.2.7:
version "4.2.7"
resolved "https://registry.yarnpkg.com/svelte/-/svelte-4.2.7.tgz#8594fad998d11d4dd179f5a91e67d1fc04d8f6e3"
Expand Down Expand Up @@ -1682,6 +1664,6 @@ wrappy@1:
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==

yaml@^2.3.4:
version "2.4.1"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.1.tgz#2e57e0b5e995292c25c75d2658f0664765210eed"
integrity sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg==
version "2.4.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.2.tgz#7a2b30f2243a5fc299e1f14ca58d475ed4bc5362"
integrity sha512-B3VqDZ+JAg1nZpaEmWtTXUlBneoGx6CPM9b0TENK6aoSu5t73dItudwdgmi6tHlIZZId4dZ9skcAQ2UbcyAeVA==
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"pre-commit": "yarn lint-staged"
},
"dependencies": {
"@eng-automation/js": "^1.0.0",
"@eng-automation/js": "^1.0.3",
"@polkadot-api/cli": "^0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
"@polkadot-api/client": "^0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
"@polkadot-api/node-polkadot-provider": "^0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
Expand Down
9 changes: 2 additions & 7 deletions src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import { convertAmountToBn, convertBnAmountToNumber, formatAmount } from "../dri
import { isDripSuccessResponse } from "../guards";
import { logger } from "../logger";
import { getNetworkData } from "../networkData";
import { CaptchaProvider } from "../types";
import { isAccountPrivileged } from "../utils";
import { getCaptchaProvider, isAccountPrivileged } from "../utils";

const captchaProvider = config.Get("CAPTCHA_PROVIDER") as CaptchaProvider;

if (!Object.keys(CaptchaProvider).includes(captchaProvider)) {
throw new Error(`⭕ - Invalid captcha provider: ${captchaProvider}`);
}
const captchaProvider = getCaptchaProvider(config.Get("CAPTCHA_PROVIDER"));

const dripRequestHandler = getDripRequestHandlerInstance(polkadotActions, captchaProvider);

Expand Down
8 changes: 3 additions & 5 deletions src/dripper/DripRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ type HandleRequestOpts =
| ({ external: false; sender: string } & Omit<DripRequestType, "captchaResponse">);

export class DripRequestHandler {
constructor(
private actions: PolkadotActions,
private captchaService: Procaptcha | Recaptcha,
) {}
// eslint-disable-next-line
constructor(private actions: PolkadotActions, private captchaService: Procaptcha | Recaptcha) {}

async handleRequest(opts: HandleRequestOpts): Promise<DripResponse> {
const { external, address: addr, parachain_id, amount } = opts;
counters.totalRequests.inc();

if (external) {
const captchaValidate = await this.captchaService.validate(opts.captchaResponse);
console.log("Captcha validate response", JSON.stringify(captchaValidate));
logger.debug(`Captcha validate response: ${JSON.stringify(captchaValidate)}`);
if (!captchaValidate)
return { error: `Captcha validation was unsuccessful. Captcha response was: ${opts.captchaResponse}` };
}
Expand Down
6 changes: 3 additions & 3 deletions src/dripper/Procaptcha.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ const PROSOPO_SITE_KEY = "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM";
// This is a mock of the @prosopo/server function isVerified that prevents calling out to a contract. A call to a test
// provider API is still made.
const mockValidationFn = async (payload: ProcaptchaOutput) => {
const { dapp, user, providerUrl, commitmentId } = payload;
const { dapp, user, providerUrl, commitmentId, blockNumber } = payload;
if (!providerUrl) {
throw new Error("No providerUrl provided");
}
const params = { dapp, user, commitmentId };
const params = { dapp, user, commitmentId, blockNumber };
const url = new URL(ApiPaths.VerifyCaptchaSolution, providerUrl).href;
const result = await axios.post(url, params);
return result.data.solutionApproved;
return result.data.verified;
};

describe("Prosopo Procaptcha", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jest.mock("../../config", () => {
config: {
Get: mockConfig.mockImplementation(
(key: string) =>
// eslint-disable-next-line security/detect-object-injection
({ NETWORK: "rococo" })[key], // minimal viable config on the initial import
// eslint-disable-next-line
({ NETWORK: "rococo" }[key]), // minimal viable config on the initial import
),
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/test/setupE2EProcaptcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class ProcaptchaSetup {
const method = get(contract.nativeContract.query, methodName)
const extrinsic = method(txPair.address, options, ...args)
const secondResult = await extrinsic
const message = contract.getContractMethod(methodName )
const message = contract.getContractMethod(methodName)
if (secondResult.result.isErr) {
const error = secondResult.result.asErr
const mod = error.asModule
Expand Down
Loading

0 comments on commit 81a777a

Please sign in to comment.