Skip to content

783 run the cypress tests against the procaptcha bundle #785

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

Merged
merged 64 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
42ecca4
Move cypress tests into shared package
forgetso Nov 10, 2023
71f33ee
sort out deps and references
forgetso Nov 11, 2023
973d76d
Run cypress tests over both demos
forgetso Nov 14, 2023
59a8134
package-lock.json and remove unused commands
forgetso Nov 14, 2023
2aab067
remove build command from demos and just serve them using vite instead
forgetso Nov 14, 2023
fc3902c
Import contracts
forgetso Nov 14, 2023
c938ee7
Fix vite config path
forgetso Nov 14, 2023
a1ef053
Import contracts and fix bundle command in workflow
forgetso Nov 14, 2023
924d60e
fix bundle command
forgetso Nov 14, 2023
d951165
Change cypress selector to work for both demos
forgetso Nov 14, 2023
ac7b0a3
Import contracts
forgetso Nov 14, 2023
73cef23
Try making the array into a selection
forgetso Nov 14, 2023
26eb579
make sure checkbox is checked
forgetso Nov 14, 2023
b49b9e9
Add a replacer for the demo bundle HTML files
forgetso Nov 14, 2023
cdd4237
add some debug
forgetso Nov 14, 2023
7b4c454
- Use vite for cypress tests
forgetso Nov 15, 2023
207578e
Import contracts and lint
forgetso Nov 15, 2023
b4bb8b8
fix up tests
forgetso Nov 15, 2023
8d3d162
deps
forgetso Nov 15, 2023
12da39c
reduce logging
forgetso Nov 15, 2023
6eb27f4
Fix cypress tests for react client-example
forgetso Nov 16, 2023
50183f6
Remove the need for dapp to be a contract in setup scripts
forgetso Nov 16, 2023
03bf38f
Merge branch 'main' into 783-run-the-cypress-tests-against-the-procap…
forgetso Nov 16, 2023
d74f867
Import contracts
forgetso Nov 16, 2023
1900d62
package-lock.json
forgetso Nov 16, 2023
986acd6
Fix dapp setup script
forgetso Nov 16, 2023
2669b37
Get rid of polkadotJS warnings
forgetso Nov 16, 2023
058fc3a
Try changing the order in beforeAll
forgetso Nov 16, 2023
5de035b
Try changing order in tests
forgetso Nov 16, 2023
2a47d5b
Fix client-example vite dev server
forgetso Nov 16, 2023
ff987a8
Turn watch off for cypress and client-example. Reduce log output
forgetso Nov 16, 2023
75d43c9
Import contracts
forgetso Nov 16, 2023
29d33ea
Use tsc build of server instead of bundle
forgetso Nov 16, 2023
8fc87db
remove timeout
forgetso Nov 16, 2023
4bda10d
Try to get client-example running alongside bundle
forgetso Nov 17, 2023
f2e2fc1
try production mode
forgetso Nov 17, 2023
facb899
Use concurrently to serve multiple vite instances at once
forgetso Nov 17, 2023
6735a08
Reduce logging
forgetso Nov 17, 2023
57b8399
fix some ts errors in client-example vite config
forgetso Nov 17, 2023
8dca052
linting and fix concurrently command
forgetso Nov 17, 2023
546e160
Use cypress run instead of open
forgetso Nov 17, 2023
b35b056
import contracts
forgetso Nov 17, 2023
51d58cc
remove noisy logs
forgetso Nov 17, 2023
d0792a8
trigger workflow
forgetso Nov 17, 2023
08dda76
Try adding a sleep before the tests
forgetso Nov 17, 2023
d9f4bc4
Set cypress to listen on all addresses instead of localhost
forgetso Nov 17, 2023
c0e71e9
Increase timeout
forgetso Nov 17, 2023
c7943f7
debug cypress
forgetso Nov 17, 2023
60f0c46
Check that the checkbox is visible on-page
forgetso Nov 17, 2023
6f59765
try hacky solution
forgetso Nov 18, 2023
b60e6ba
Try return
forgetso Nov 20, 2023
3180471
trim vite config
forgetso Nov 20, 2023
2eac100
simplify cypress chain
forgetso Nov 20, 2023
7b35cda
try xvfb-run
forgetso Nov 20, 2023
3a8e793
run headed
forgetso Nov 20, 2023
e0f17e2
Use the same dapp site key in all template env files
forgetso Nov 20, 2023
7f7612f
Update env.development in scripts
forgetso Nov 20, 2023
9d438e9
Use run instead of open
forgetso Nov 20, 2023
a268cb8
Use correct success flag
forgetso Nov 20, 2023
96e0dbf
Test using dev bundle of procaptcha
forgetso Nov 20, 2023
63a8900
Import contracts
forgetso Nov 20, 2023
bc0e029
Import contracts
forgetso Nov 20, 2023
9e730ec
Import contracts
forgetso Nov 20, 2023
0e807dd
lint
forgetso Nov 20, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
project-cache-${{ runner.os }}-${{ runner.arch }}-

- run: npm install
- run: npm run removePolkadotJSWarnings

- name: Clippy
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/contract_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
project-cache-${{ runner.os }}-${{ runner.arch }}-

- run: npm install
- run: npm run removePolkadotJSWarnings

- name: Check contract version matches provider version
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dockerhub_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
echo "Navigating to 'packages/procaptcha-bundle' and building JS bundle..."
cd packages/procaptcha-bundle

NODE_ENV=production npm run build:prod
NODE_ENV=production npm run bundle:prod

# Rename the bundle to include the version number
NEW_BUNDLE_FILENAME="procaptcha.bundle.${{ needs.check_version.outputs.next_version }}.js"
Expand Down Expand Up @@ -132,9 +132,9 @@ jobs:
cp ./dev/scripts/env.rococo ./packages/cli/.env.production

# Navigate to the provider CLI directory and build
echo "Navigating to 'packages/cli' and building..."
echo "Navigating to 'packages/cli' and bundling..."
cd packages/cli
NODE_ENV=production npm run build:prod
NODE_ENV=production npm run bundle:prod

# Navigate back to the project root
echo "Navigating back to project root..."
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ jobs:

- run: npm install -g npm@8.9
- run: npm install
- run: npm run removePolkadotJSWarnings
- run: npm run lint
1 change: 1 addition & 0 deletions .github/workflows/post_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- run: ls -la node_modules || true

- run: npm install
- run: npm run removePolkadotJSWarnings

- name: Rust formatting check
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/provider_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
project-cache-${{ runner.os }}-${{ runner.arch }}-

- run: npm install
- run: npm run removePolkadotJSWarnings

# build the packages
- name: Build packages
Expand All @@ -62,7 +63,7 @@ jobs:
- name: Build cli production bundle
run: |
cp ./dev/scripts/env.rococo ./packages/cli/.env.production
NODE_ENV=production npm run -w @prosopo/cli build:prod
NODE_ENV=production npm run -w @prosopo/cli bundle:prod

# create the provider image
- name: Build provider image
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
project-cache-${{ runner.os }}-${{ runner.arch }}-

- run: npm install
- run: npm run removePolkadotJSWarnings

- name: Rust formatting check
run: |
Expand Down
32 changes: 19 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:

- run: npm install -g npm@8.9
- run: npm install
- run: npm run removePolkadotJSWarnings

# build all packages in workspace
- run: npm run build:all
Expand All @@ -60,6 +61,7 @@ jobs:
cp demos/client-example/env.development demos/client-example/.env.test
cp dev/scripts/env.test dev/scripts/.env.test
cp dev/scripts/env.test packages/cli/.env.test
cp dev/scripts/env.test packages/procaptcha-bundle/.env.test
echo NODE_ENV: $NODE_ENV

- name: Start the docker images
Expand All @@ -68,9 +70,8 @@ jobs:
docker container ls
sleep 10s

# deploy dapp + protocol and run the unit tests
# deploy protocol and run the unit tests
- run: npm run deploy_protocol
- run: npm run deploy_dapp
- run: npm run test -- --watch=false

# restart the docker images to drop any changes made by the unit tests to the contract(s) before running cypress tests
Expand All @@ -82,17 +83,22 @@ jobs:
sleep 10s

# deploy dapp + protocol and run setup to register, stake and load a dataset for a provider
- run: npm run deploy_protocol
- run: npm run deploy_dapp
- run: npm run setup
- run: NODE_ENV=test npm run deploy_protocol
- run: NODE_ENV=test npm run setup

# Build a test version of the procaptcha bundle and run the cypress tests on it and on the React client-example
# Running bundle:dev instead of bundle:prod means the bundle will be built with selectors that can be used
# by the cypress tests to find the elements they need to interact with
- run: NODE_ENV=test npm -w @prosopo/procaptcha-bundle run bundle:dev

# Needs concurrently to avoid vite hanging forever https://github.com/vitejs/vite/discussions/8745
- name: Install concurrently and cypress
run: npm i concurrently cypress

- name: Run the cypress tests on client-example
run: |
npm run start:provider &
sleep 10s
npm run start:server &
sleep 10s
npm run start:demo &
sleep 10s
npm i cypress
npm -w @prosopo/client-example run cypress:run
npx concurrently "npm run start:server" "npm run start:provider" "npm run start:demo" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-example" --success "first" --kill-others

- name: Run the cypress tests on client-bundle-example
run: |
npx concurrently "npm run start:server" "npm run start:provider" "npm run start:bundle" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-bundle-example" --success "first" --kill-others
1 change: 1 addition & 0 deletions .github/workflows/tests_protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
project-cache-${{ runner.os }}-${{ runner.arch }}-

- run: npm install
- run: npm run removePolkadotJSWarnings

- name: Build contracts
id: build
Expand Down
1 change: 1 addition & 0 deletions contracts/captcha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"scripts": {
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix --config ../../.eslintrc.js"
},
Expand Down
2 changes: 1 addition & 1 deletion contracts/captcha/src/captcha.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xb9838a103f7f6f60fc5c2f4f4b7583b4d5b64d17e7a8b40d84101c50631467a8",
"hash": "0xcbf8a2ccb2d44ee4a81b5af2a080f50b5c5353e833737b6456bd155d7531a675",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/captcha/src/contract-info/captcha.ts

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions contracts/captcha/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.cjs.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src", "src/**/*.json"],
"references": []
}
6 changes: 6 additions & 0 deletions contracts/captcha/vite.cjs.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ViteCommonJSConfig } from '@prosopo/config'
import path from 'path'

export default function () {
return ViteCommonJSConfig('captcha-contract', path.resolve('./tsconfig.cjs.json'))
}
2 changes: 1 addition & 1 deletion contracts/common/src/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xff9af5d896229b57a3278afb12a184fd2fc36f3c3367f86508efbc9a767e0f6d",
"hash": "0x3310de2401b8a9309d4769d470411ac3e99f10a6294b4deb990fce67cda37a19",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/common/src/contract-info/common.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contracts/proxy/src/contract-info/proxy.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/proxy/src/proxy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xc42e28d6a7c04e67b95bb8becd47a40afd69f671246841517aaa9ffa68a03cf5",
"hash": "0xc94835e36abfa10f531eae6dc4b73f40949f5eff4707a7ec18e0643ce08077f3",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
2 changes: 1 addition & 1 deletion demos/client-bundle-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"npm": "8.9"
},
"scripts": {
"start": "light-server -s ./src -p 9231 -w \"**/*.html,**/*.css,**/*.js,**/*.gz\"",
"start": "light-server -s ./src -p 9232 -w \"**/*.html,**/*.css,**/*.js,**/*.gz\"",
"clean": "echo 'nothing to clean'"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions demos/client-bundle-example/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div
class="procaptcha"
data-theme="light"
data-sitekey="5HUBceb4Du6dvMA9BiwN5VzUrzUsX9Zp7z7nSR2cC1TCv5jg"
data-sitekey="5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
></div>
<input type="submit" class="mui-btn mui-btn--raised"/>
</form>
Expand All @@ -37,7 +37,7 @@

// Render the CAPTCHA explicitly on a container with id "procaptcha-container"
window.procaptcha.render('procaptcha-container', {
siteKey: '5HUBceb4Du6dvMA9BiwN5VzUrzUsX9Zp7z7nSR2cC1TCv5jg',
siteKey: '5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw',
theme: 'dark',
callback: 'onCaptchaVerified',
})
Expand Down
2 changes: 1 addition & 1 deletion demos/client-example-server/env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REACT_APP_API_PATH_PREFIX=/v1/prosopo
REACT_APP_DAPP_SITE_KEY=
REACT_APP_DAPP_SITE_KEY=5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw
REACT_APP_SUBSTRATE_NODE_URL=ws://localhost:9944
REACT_APP_PROSOPO_CONTRACT_ADDRESS=
REACT_APP_WEB2=true
Expand Down
9 changes: 5 additions & 4 deletions demos/client-example-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
},
"scripts": {
"dev": "vite serve --mode=development --config ./vite.config.ts --host",
"start": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
"build": "npm run build:prod",
"build:prod": "vite build --mode=production --config ./vite.config.ts",
"build:dev": "vite build --mode=development --config ./vite.config.ts",
"start": "node ./dist/app.js",
"start:bundle": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
"build": "tsc --build --verbose",
"bundle:prod": "vite build --mode=production --config ./vite.config.ts",
"bundle:dev": "vite build --mode=development --config ./vite.config.ts",
"clean": "tsc --build --clean",
"test": "echo \"Error: no test specified\" && exit 1",
"lint:fix": "npx eslint . --fix"
Expand Down
4 changes: 2 additions & 2 deletions demos/client-example-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { ProsopoServer, getServerConfig } from '@prosopo/server'
import { getPair } from '@prosopo/contract'
import { getPairAsync } from '@prosopo/contract'
import connectionFactory from './utils/connection.js'
import cors from 'cors'
import dotenv from 'dotenv'
Expand Down Expand Up @@ -62,7 +62,7 @@ async function main() {
const config = getServerConfig()

console.log('config', config)
const pair = await getPair(config.networks[config.defaultNetwork], process.env.REACT_APP_SERVER_MNEMONIC)
const pair = await getPairAsync(config.networks[config.defaultNetwork], process.env.REACT_APP_SERVER_MNEMONIC)
const prosopoServer = new ProsopoServer(config, pair)

app.use(routesFactory(mongoose, prosopoServer))
Expand Down
2 changes: 0 additions & 2 deletions demos/client-example-server/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const signup = async (
const salt = randomAsHex(32)
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
const passwordHash = hashPassword(`${req.body.password}${salt}`)

if (passwordHash) {
return User.create({
email: req.body.email,
Expand Down Expand Up @@ -96,7 +95,6 @@ const login = async (mongoose: Connection, prosopoServer: ProsopoServer, req: Re
res.status(404).json({ message: 'user not found' })
} else {
const payload = SubscribeBodySpec.parse(req.body)

if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
// password hash
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
Expand Down
4 changes: 4 additions & 0 deletions demos/client-example-server/src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const UserSchema = new Schema<UserInterface>({
id: {
type: mongoose.SchemaTypes.Number,
},
salt: {
type: mongoose.SchemaTypes.String,
required: true,
},
})

export default UserSchema
11 changes: 0 additions & 11 deletions demos/client-example-server/tsconfig.webpack.json

This file was deleted.

29 changes: 0 additions & 29 deletions demos/client-example/cypress.config.js

This file was deleted.

Loading