Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Migrate to Prosopo Procaptcha #2

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5ba6483
Procaptcha (#1)
forgetso Feb 22, 2024
1c87e42
Merge remote-tracking branch 'upstream/main'
forgetso Feb 22, 2024
b0e0344
Bump the npm_and_yarn group group in /client with 1 update (#374)
dependabot[bot] Feb 26, 2024
c12b078
Merge remote-tracking branch 'upstream/main'
forgetso Feb 27, 2024
5da338c
Updating e2e tests readme (#375)
mutantcornholio Mar 1, 2024
8e08bc6
Fixing e2e readme link
mutantcornholio Mar 5, 2024
ac079a8
Adding runtimeRestarter (#376)
mutantcornholio Mar 6, 2024
b644692
Updating zombinenet verion in e2e docs (#378)
mutantcornholio Mar 6, 2024
3b97c8d
Using PAPI for e2e tests (#379)
mutantcornholio Mar 13, 2024
53d3a49
Bump the npm_and_yarn group across 2 directories with 2 updates (#381)
dependabot[bot] Mar 17, 2024
1eea1f6
removed base url (#382)
Bullrich Mar 20, 2024
baa9be8
Added markup code generation (#383)
Bullrich Mar 25, 2024
bcb24ac
Updated actions to latest and added retention period (#384)
Bullrich Mar 25, 2024
b397ef5
lockfile update (#3)
forgetso Mar 26, 2024
fe890ef
Bump the npm_and_yarn group across 1 directory with 1 update (#385)
dependabot[bot] Apr 3, 2024
ce5517f
Bump the npm_and_yarn group across 1 directory with 1 update (#387)
dependabot[bot] Apr 4, 2024
0a1f485
Update Frequency Faucet URL (#393)
wilwade Apr 17, 2024
2b12c0a
moved tag-client to work in pull_request_target (#394)
Bullrich Apr 17, 2024
93d351a
Merge remote-tracking branch 'upstream/main'
forgetso Apr 17, 2024
f63e98e
Add MIT LICENSE (#395)
mordamax Apr 22, 2024
722c604
Upstream merge (#4)
forgetso Apr 29, 2024
4b6b105
Merge branch 'main' of github.com:prosopo/polkadot-testnet-faucet
forgetso Apr 29, 2024
898bf46
Resolve conflicts
forgetso Apr 29, 2024
5703342
Merge remote-tracking branch 'upstream/main'
forgetso Apr 29, 2024
359f027
lockfile updates
forgetso Apr 29, 2024
dcaf485
lint:fix
forgetso Apr 29, 2024
ade4dc6
link to docs (#5)
forgetso Apr 29, 2024
1054692
Fix toml formatting @Bullrich
forgetso Apr 29, 2024
273056d
Update paseo RPC wss://sys.dotters.network/paseo (#398)
mordamax Apr 29, 2024
1561795
Moved GitLab checks to GitHub's action (#402)
Bullrich Apr 30, 2024
a239854
Bump yaml from 2.4.1 to 2.4.2 in /client in the npm_and_yarn group ac…
dependabot[bot] Apr 30, 2024
944685c
Updates 2 (#6)
forgetso Apr 30, 2024
81a777a
Updates 3 (#7)
forgetso May 1, 2024
0722b8c
Merge remote-tracking branch 'upstream/main'
forgetso May 2, 2024
0e2be89
remove react dep (#8)
forgetso May 2, 2024
1fa8703
Remove async (#10)
forgetso May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
!tsconfig.json
!env.*.config.json
!src

/src/**/*.e2e.ts
/src/**/*.spec.ts
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ SMF_CONFIG_DB_PORT=5432
SMF_CONFIG_DB_USERNAME=postgres
SMF_CONFIG_DB_PASSWORD=postgres
SMF_CONFIG_DB_DATABASE_NAME=faucet

# Captcha provider details
SMF_CONFIG_CAPTCHA_PROVIDER=procaptcha
SMF_CONFIG_PROSOPO_DEFAULT_ENVIRONMENT=production
SMF_CONFIG_PROSOPO_DEFAULT_NETWORK=rococo
SMF_CONFIG_PROSOPO_DAPP_NAME=Polkadot
SMF_CONFIG_PROSOPO_SUBSTRATE_ENDPOINT=wss://rococo-contracts-rpc.polkadot.io:443
SMF_CONFIG_PROSOPO_SITE_KEY=5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
data
build
test
test
28 changes: 22 additions & 6 deletions .github/workflows/E2E.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,42 @@ jobs:
- run: yarn install --frozen-lockfile
- name: Download Polkadot and parachain binaries
run: |
wget --no-verbose https://github.com/paritytech/cumulus/releases/download/v0.9.420/polkadot-parachain
wget --no-verbose https://github.com/paritytech/polkadot/releases/download/v0.9.42/polkadot
wget --no-verbose https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.8.0/polkadot
wget --no-verbose https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.8.0/polkadot-parachain
wget --no-verbose https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.8.0/polkadot-prepare-worker
wget --no-verbose https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-v1.8.0/polkadot-execute-worker
chmod +x ./polkadot*
working-directory: e2e
- name: Run a local relaychain with a parachain using zombienet
run: |
export PATH=$(pwd):$PATH
npx --yes @zombienet/cli@1.3.43 \
--provider native spawn zombienet.native.toml \
npx --yes @zombienet/cli@1.3.93 \
--provider native \
--dir zombienet_logs \
spawn zombienet.native.toml \
> polkadot.txt 2>&1 &
source wait_until.sh 'curl -s "127.0.0.1:9933"'
source wait_until.sh 'curl -s "127.0.0.1:9923"'
source wait_until.sh 'curl -s "127.0.0.1:9934"'
source wait_until.sh 'curl -s "127.0.0.1:9988"'
working-directory: e2e
- name: Build e2e types
run: yarn generate:papi:e2e
- name: Build faucet
run: yarn build:docker
- name: Run the E2E tests
run: yarn test:e2e
- name: Debug Polkadot logs
- name: Debug Zombienet host logs
if: failure()
run: cat e2e/polkadot.txt
- name: Debug Zombienet alice node logs
if: failure()
run: cat e2e/zombienet_logs/alice.log
- name: Debug Zombienet bob node logs
if: failure()
run: cat e2e/zombienet_logs/bob.log
- name: Debug Zombienet alice-1 node logs
if: failure()
run: cat e2e/zombienet_logs/alice-1.log
- name: Debug Matrix logs
if: failure()
run: cat e2e/containter_logs/faucet-test-matrix.log
Expand Down
33 changes: 22 additions & 11 deletions .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,38 @@ jobs:
working-directory: client
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 18
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
run: npx playwright install
run: yarn playwright install --with-deps
- run: yarn run test
- run: yarn run build
env:
PUBLIC_CAPTCHA_KEY: 6LcgFI4nAAAAAATrEMoJ6zBacsx5udc1UhGFXemH
GITHUB_PAGES: "/${{ github.event.repository.name }}"
STATIC: true
BASE: "/polkadot-testnet-faucet"
- uses: actions/upload-artifact@master
- uses: actions/upload-artifact@v4
with:
name: faucet
path: ./client/build
if-no-files-found: error
retention-days: 5
deploy-to-github-pages:
environment:
name: github-pages
Expand All @@ -48,18 +59,18 @@ jobs:
needs: [build-faucet]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Download page
uses: actions/download-artifact@master
uses: actions/download-artifact@v4
with:
name: faucet
path: ./dist
- name: Setup Pages
uses: actions/configure-pages@v2
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: ./dist
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .github/workflows/tag-client-pr.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Label Client PRs

on:
pull_request:
pull_request_target:
paths:
- 'client/**'

Expand Down
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ storage.db
sqlite.db
build
e2e/containter_logs
e2e/zombienet_logs

# Autogenerated
env.*.config.json.d.ts
!.env.example

/data
/src/test/codegen
19 changes: 0 additions & 19 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,6 @@ variables:
--file "$DOCKERFILE" .
- $BUILDAH_COMMAND info

#### stage: test

check-linting:
stage: test
<<: *common-refs
<<: *kubernetes-env
script:
- yarn --frozen-lockfile
- 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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Parity Technologies

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ $ cp example.env .env

## End-to-end tests

Please refer to the [E2E Readme](./E2E/README.md).
Please refer to the [E2E Readme](./e2e/README.md).

Example requests:

```bash
curl -X POST \
localhost:5555/drip/web \
-H "Content-Type: application/json" \
-d '{"address": "xxx", "parachain_id": "1002", "recaptcha": "captcha_token"}'
-d '{"address": "xxx", "parachain_id": "1002", "captchaResponse": "captcha_token"}'
```

In React:
Expand All @@ -76,7 +76,7 @@ const request = async () => {
const body = {
address: "xxx",
parachain_id: "1002",
recaptcha: captcha_token
captchaResponse: captcha_token
}

const fetchResult = await fetch("http://localhost:5555/drip/web", {
Expand All @@ -89,15 +89,26 @@ const request = async () => {
}
```

Where the `captcha_token` is a recaptcha token created with a `sitekey`
is matching the recaptcha secret specified in `SMF_BACKEND_RECAPTCHA_SECRET`.
Where the `captcha_token` is either a

For testing, you can use a public, testing recaptcha secret which will allow any captcha token to pass.
- JSON payload that includes a verified rococo address [procaptcha](https://docs.prosopo.io)

```shell
# Public testing secret, will accept all tokens.
SMF_BACKEND_RECAPTCHA_SECRET="6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
```
or

- a recaptcha token created with a `sitekey` matching the [recaptcha](https://developers.google.com/recaptcha/) secret specified in `SMF_BACKEND_RECAPTCHA_SECRET`.

For testing, you can use

- Alice's address `5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY` with procaptcha

or

- a public, testing captcha secret which will allow any captcha token to pass with recaptcha.

```shell
# Public testing secret, will accept all tokens.
SMF_BACKEND_RECAPTCHA_SECRET="6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
```

### Helm chart

Expand Down
6 changes: 5 additions & 1 deletion client/.env
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
PUBLIC_DEMO_MODE=
PUBLIC_CAPTCHA_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
PUBLIC_RECAPTCHA_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
PUBLIC_PROSOPO_SITE_KEY=5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM

PUBLIC_FAUCET_URL=
# uncomment to direct requests to local instance
# PUBLIC_FAUCET_URL=http://localhost:5555/drip/web/

PUBLIC_ISSUE_LINK=https://github.com/paritytech/polkadot-testnet-faucet/issues/new/choose
PUBLIC_FORUM="https://forum.polkadot.network/t/experiencing-trouble-accessing-our-rococo-faucet-please-post-here/2952"
PUBLIC_CAPTCHA_PROVIDER=procaptcha


6 changes: 4 additions & 2 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Two current options are to [access Matrix and contact a bot](https://wiki.polkad

## Development

To develop you need two env variables:
To develop you need three env variables:

- `PUBLIC_CAPTCHA_KEY`: The [reCaptcha v2 site key](https://www.google.com/u/0/recaptcha/admin).
- `PUBLIC_CAPTCHA_PROVIDER`: The captcha provider. Currently `procaptcha` and `recaptcha` are supported. You will then need one of the following site keys:
- `PUBLIC_PROSOPO_SITE_KEY`: The [Prosopo site key](https://prosopo.io/) which is `5HUBceb4Du6dvMA9BiwN5VzUrzUsX9Zp7z7nSR2cC1TCv5jg`.
- `PUBLIC_RECAPTCHA_KEY`: The [reCaptcha v2 site key](https://www.google.com/u/0/recaptcha/admin).
- `PUBLIC_FAUCET_URL`: The endpoint to contact the faucet backend. Keep unset to run client-side code with production backend.

The reason for which these variables have `PUBLIC_` as a prefix is a security measure to not upload any unnecessary data. [More info here](https://kit.svelte.dev/docs/modules#$env-static-public)
Expand Down
7 changes: 5 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"test": "playwright test",
"test:recaptcha": "playwright test --config playwright.config.recaptcha.ts",
"test:procaptcha": "playwright test --config playwright.config.procaptcha.ts",
"test": "yarn test:recaptcha && yarn test:procaptcha",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@playwright/test": "^1.40.0",
"@polkadot/util": "^12.6.2",
"@sveltejs/adapter-auto": "^2.1.1",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/adapter-static": "^2.0.3",
Expand All @@ -27,7 +30,7 @@
"tailwindcss": "^3.3.5",
"tslib": "^2.6.2",
"typescript": "^5.3.2",
"vite": "^5.0.5"
"vite": "^5.0.13"
},
"type": "module"
}
Loading