Skip to content

Commit

Permalink
Issue/75 update captcha to latest version of contract with provider c…
Browse files Browse the repository at this point in the history
…ommit (#84)

* Create test runner in dev package and load all workspace tests. Run via dev cli

* Fix env dependencies

* build the cli package

* remove old commands. try to run tests from workspace root

* run stuff from dev package

* build all packages in one commadn

* fix import

* remove debug

* Update polkadot dependencies and abi JSON

* finish updating typescript

* make sure all packages have typescript as a dev dependency

* Update demo dependencies

* Don't import api-augment in provider. Should be included in contract

* Upgrade extension dependencies

* Single eslint config. New contract sources generated by typechain. Types updated everywhere. Build scripts added.

* revert to relative imports

* Add command for importing contract to contract package

* Create contract import script in dev

* Fix contract importer

* fixup procaptcha, procaptcha-react and provider tests

* Most tests passing

* Fix type

* lint fix

* linting

* fix log level

* Use correct log in dev CLI. Update polkadot dependency for aura image

* See how many tests failed

* Update docker image files. Update tests so that commitments have signatures. Error on contract errors. Update provider workflow to use contracts node because aura node not working with signature method

* Create env.test template file

* remove extra slash

* Use proper logger in protocol deploy

* Update contract sources in contract package

* Fix tests

* remove debug

* add debug

* Add some debug

* Use test docker file in workflow

* Use docker files in monorepo

* Add mongo to test docker image

* cat right file

* down right docker file

* cd correct dir

* Update package-lock.json

* Add types for api urls and api params to ensure things don't go out of sync. Save user signature as single string

* Fix tests

* Add types for API parameter names

* Fix provider API methods

* Fix login in client-example-server and fix Typography descendent issue
  • Loading branch information
forgetso authored Jun 6, 2023
1 parent 7d594c3 commit ca0ac40
Show file tree
Hide file tree
Showing 179 changed files with 10,505 additions and 9,616 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/artifacts/*
packages/**/dist/*
**/.eslintrc.js
**/dist/*
demos/**/dist/*
demos/**/scripts/*
demos/**/next.config.js
**/*bundle*.js
15 changes: 9 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['unused-imports', '@typescript-eslint', "sort-imports-es6-autofix", 'prettier'],
plugins: ['unused-imports', '@typescript-eslint', 'sort-imports-es6-autofix', 'prettier'],
rules: {
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
Expand All @@ -32,11 +32,14 @@ module.exports = {
allowSeparatedGroups: false,
},
],
"sort-imports-es6-autofix/sort-imports-es6": [2, {
"ignoreCase": false,
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
}],
'sort-imports-es6-autofix/sort-imports-es6': [
2,
{
ignoreCase: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
},
],
'prettier/prettier': ['error'],
},
}
42 changes: 16 additions & 26 deletions .github/workflows/tests_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,18 @@ jobs:
path: captcha
submodules: recursive

- name: Clone scripts repository
uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
repository: prosopo/scripts
path: scripts
#ssh-key: ${{ secrets.SSH_KEY }}
#ssh-strict: false

- name: Checkout correct scripts branch
run: |
cd scripts
git fetch
git checkout ${{ github.head_ref }} || git checkout ${{ github.base_ref }} || git checkout develop
git pull
- run: mkdir -p ~/image-cache

- id: image-cache
uses: actions/cache@v3
with:
path: ~/image-cache
key: image-cache-docker-${{ runner.os }}
key: image-cache-docker-${{ runner.os }}-${{ hashFiles('./captcha/docker/docker-compose.test.yml') }}

- if: steps.image-cache.outputs.cache-hit != 'true'
run: |
docker pull prosopo/substrate:dev-aura-aadbbed50ede27817158c7517f13f6f61c9cf000
docker save -o ~/image-cache/prosopo.tar prosopo/substrate:dev-aura-aadbbed50ede27817158c7517f13f6f61c9cf000
docker pull prosopo/substrate-contracts-node:v0.25
docker save -o ~/image-cache/prosopo.tar prosopo/substrate-contracts-node:v0.25
docker pull mongo:5.0.4
docker save -o ~/image-cache/mongo.tar mongo:5.0.4
Expand All @@ -75,8 +59,9 @@ jobs:
- name: Start the docker images
run: |
cd scripts
docker compose --file ./docker/docker-compose.development.yml up -d
cd captcha
docker compose --file ./docker/docker-compose.test.yml up -d
docker container ls
- id: node-cache
uses: actions/cache@v3
Expand All @@ -103,20 +88,25 @@ jobs:
cd captcha
echo $(npx tsc --version)
cd dev && echo $(pwd) && echo $(git rev-parse HEAD) && npm run build
cp env.development .env.test
echo "NODE_ENV=test" >> $GITHUB_ENV
echo $NODE_ENV
- name: Setup the environment and run the unit tests
- name: Deploy the contracts and run the unit tests
run: |
cd captcha
npm run deploy_protocol
npm run deploy_dapp
git status | head -n 1
cd dev
cp env.development .env.development
git status | head -n 1
docker container ls
cat .env.development
cat .env.test
npm run test
- name: Remove the docker containers
run: |
cd scripts
docker compose --file ./docker/docker-compose.development.yml down
cd captcha
docker compose --file ./docker/docker-compose.test.yml down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ node_modules
mongodb
dist
**/dist/**
*.iml

# Below is Github's node gitignore template,
# ignoring the node_modules part, as it'd ignore every node_modules, and we have some for testing
Expand Down
1 change: 1 addition & 0 deletions demos/client-example-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@prosopo/api": "^0.1.11",
"@prosopo/contract": "^0.1.11",
"@prosopo/server": "^0.1.11",
"@prosopo/types": "^0.1.11",
"axios": "^0.27.2",
"bcryptjs": "^2.4.3",
"jsonwebtoken": "^9.0.0",
Expand Down
1 change: 0 additions & 1 deletion demos/client-example-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ async function main() {
if (!process.env.REACT_APP_SERVER_MNEMONIC) {
throw new Error('No mnemonic found')
}
console.log(process.env)

const config = prosopoConfig()

Expand Down
31 changes: 17 additions & 14 deletions demos/client-example-server/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import bcrypt from 'bcryptjs'

import jwt from 'jsonwebtoken'

import { ApiParams } from '@prosopo/types'
import { Connection } from 'mongoose'
import { ProsopoServer } from '@prosopo/server'
import { UserInterface } from '../models/user'
Expand All @@ -20,16 +21,17 @@ const signup = async (mongoose: Connection, prosopoServer: ProsopoServer, req, r
req.body.email &&
req.body.password &&
req.body.prosopo &&
req.body.prosopo.userAccountAddress &&
req.body.prosopo.blockNumber
req.body.prosopo[ApiParams.user] &&
req.body.prosopo[ApiParams.dapp] &&
req.body.prosopo[ApiParams.blockNumber]
) {
console.log(req.body)
if (
await prosopoServer.isVerified(
req.body.prosopo.userAccountAddress,
req.body.prosopo.providerUrl,
req.body.prosopo.commitmentId,
req.body.prosopo.blockNumber
req.body.prosopo[ApiParams.user],
req.body.prosopo[ApiParams.providerUrl],
req.body.prosopo[ApiParams.dapp],
req.body.prosopo[ApiParams.commitmentId],
req.body.prosopo[ApiParams.blockNumber]
)
) {
// password hash
Expand Down Expand Up @@ -82,16 +84,17 @@ const login = async (mongoose: Connection, prosopoServer: ProsopoServer, req, re
req.body.email &&
req.body.password &&
req.body.prosopo &&
req.body.prosopo.userAccountAddress &&
req.body.prosopo.blockNumber
req.body.prosopo[ApiParams.user] &&
req.body.prosopo[ApiParams.dapp] &&
req.body.prosopo[ApiParams.blockNumber]
) {
console.log(req.body)
if (
await prosopoServer.isVerified(
req.body.prosopo.userAccountAddress,
req.body.prosopo.providerUrl,
req.body.prosopo.commitmentId,
req.body.prosopo.blockNumber
req.body.prosopo[ApiParams.user],
req.body.prosopo[ApiParams.providerUrl],
req.body.prosopo[ApiParams.dapp],
req.body.prosopo[ApiParams.commitmentId],
req.body.prosopo[ApiParams.blockNumber]
)
) {
// password hash
Expand Down
13 changes: 11 additions & 2 deletions demos/client-example-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"rootDir": "./src",
"outDir": "./dist",
Expand All @@ -28,5 +27,15 @@
"./src/**/*.js"
],
"exclude": ["node_modules", "dist"],

"references": [
{
"path": "../../packages/api"
},
{
"path": "../../packages/contract"
},
{
"path": "../../packages/server"
}
]
}
8 changes: 6 additions & 2 deletions demos/client-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Alert, Box, Button, FormControl, FormGroup, Stack, TextField, Typography } from '@mui/material'
import { useState } from 'react'

import { ProcaptchaOutput } from '@prosopo/procaptcha'
import { ExtensionAccountSelect, Procaptcha } from '@prosopo/procaptcha-react'

import { ExtensionAccountSelect } from '@prosopo/procaptcha-react/dist/components'
import { Procaptcha } from '@prosopo/procaptcha-react/dist/components'

import './App.css'

function App() {
Expand Down Expand Up @@ -137,7 +141,7 @@ function App() {
<div>
<Box className={'App'} sx={{ display: 'flex' }}>
<Box>
<Typography>{message ? getMessage() : null}</Typography>
<Typography component={'span'}>{message ? getMessage() : null}</Typography>
{!config.web2 ? (
<ExtensionAccountSelect dappName={config.dappName} value={account} onChange={setAccount} />
) : (
Expand Down
1 change: 0 additions & 1 deletion demos/client-example/src/react-app-env.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion demos/client-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"references": [
{
"path": "../packages/procaptcha-react"
"path": "../../packages/procaptcha-react"
}
]
}
7 changes: 5 additions & 2 deletions dev/env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
WASM_PATH=../../../protocol/contracts/target/ink/prosopo.wasm
ABI_PATH=../../../protocol/contracts/target/ink/prosopo.json
CAPTCHA_WASM_PATH=./src/contract/sources/captcha/48321f627ee7320c69287dcc94e4071f474a5983/captcha.wasm
CAPTCHA_ABI_PATH=./src/contract/sources/captcha/48321f627ee7320c69287dcc94e4071f474a5983/captcha.json
DAPP_WASM_PATH=./src/contract/sources/dapp/411053b7ec79cc77f5ec9f5eb18610b24daaaaf0/dapp.wasm
DAPP_ABI_PATH=./src/contract/sources/dapp/411053b7ec79cc77f5ec9f5eb18610b24daaaaf0/dapp.json
DAPP_CONTRACT_ADDRESS=5Fh6SXrofhT9tgPJwUDbpWEGSiSom3mkgFt2rAVdDpek2hGc
PROTOCOL_CONTRACT_ADDRESS=5GpseHvrNBARmkgAVFyn4tV8eAMvHy1iF8RkaPedKNVmKTxH
DATABASE_PASSWORD=root
Expand All @@ -15,3 +17,4 @@ SS58_FORMAT=42
PROVIDER_ADDRESS=5EjTA28bKSbFPPyMbUjNtArxyqjwq38r1BapVmLZShaqEedV
PROVIDER_MNEMONIC=puppy cream effort carbon despair leg pyramid cotton endorse immense drill peasant
NODE_ENV=development
LOG_LEVEL=Debug
20 changes: 20 additions & 0 deletions dev/env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CAPTCHA_WASM_PATH=./src/contract/sources/captcha/48321f627ee7320c69287dcc94e4071f474a5983/captcha.wasm
CAPTCHA_ABI_PATH=./src/contract/sources/captcha/48321f627ee7320c69287dcc94e4071f474a5983/captcha.json
DAPP_WASM_PATH=./src/contract/sources/dapp/411053b7ec79cc77f5ec9f5eb18610b24daaaaf0/dapp.wasm
DAPP_ABI_PATH=./src/contract/sources/dapp/411053b7ec79cc77f5ec9f5eb18610b24daaaaf0/dapp.json
DAPP_CONTRACT_ADDRESS=5Fh6SXrofhT9tgPJwUDbpWEGSiSom3mkgFt2rAVdDpek2hGc
PROTOCOL_CONTRACT_ADDRESS=5GpseHvrNBARmkgAVFyn4tV8eAMvHy1iF8RkaPedKNVmKTxH
DATABASE_PASSWORD=root
DATABASE_USERNAME=root
DATABASE_NAME=prosopo
DATABASE_HOST=127.0.0.1
DATABASE_PORT=27017
SUBSTRATE_NODE_URL=ws://localhost:9944
API_BASE_URL=http://localhost:8282
API_PORT=8282
PAIR_TYPE=sr25519
SS58_FORMAT=42
PROVIDER_ADDRESS=5EjTA28bKSbFPPyMbUjNtArxyqjwq38r1BapVmLZShaqEedV
PROVIDER_MNEMONIC=puppy cream effort carbon despair leg pyramid cotton endorse immense drill peasant
NODE_ENV=test
LOG_LEVEL=Info
15 changes: 9 additions & 6 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
"scripts": {
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"test": "ts-node src/cli/index.ts test",
"test": "tsc --build --verbose && node dist/cli/index.js test",
"deploy": "node dist/deploy/protocol.js",
"cli": "node dist/cli/index.js",
"setup": "node dist/cli/index.js setup"
},
"author": "Prosopo Limited",
"license": "Apache-2.0",
"dependencies": {
"@polkadot/api": "9.13.6",
"@polkadot/api-contract": "9.13.6",
"@polkadot/types": "9.13.6",
"@polkadot/util-crypto": "10.3.1",
"@polkadot/api": "10.8.1",
"@polkadot/api-contract": "10.8.1",
"@polkadot/types": "10.8.1",
"@polkadot/util-crypto": "12.2.2",
"@prosopo/cli": "^0.1.11",
"@prosopo/common": "^0.1.11",
"@prosopo/contract": "^0.1.11",
"@prosopo/env": "^0.1.11",
"@prosopo/provider": "^0.1.11",
"@prosopo/types": "^0.1.11",
Expand All @@ -28,10 +29,12 @@
"consola": "^2.15.3",
"dotenv": "^16.0.3",
"glob": "^10.0.0",
"mocha": "^10.2.0",
"yargs": "^17.5.1",
"yargs-parser": "^21.0.1"
},
"devDependencies": {
"@types/mocha": "^10.0.1"
"@types/mocha": "^10.0.1",
"typescript": "^4.9.4"
}
}
Loading

0 comments on commit ca0ac40

Please sign in to comment.