From ce745f037c4bcf8681984fd2a75b9ddc0177cf5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7?= Date: Tue, 15 Oct 2024 10:03:15 +0200 Subject: [PATCH 1/6] Add new metrocs to monitor memory --- scripts/test.canisters.sh | 31 +++++++++++++++++++++++ src/archive/src/main.rs | 1 + src/internet_identity/src/http/metrics.rs | 2 ++ 3 files changed, 34 insertions(+) create mode 100755 scripts/test.canisters.sh diff --git a/scripts/test.canisters.sh b/scripts/test.canisters.sh new file mode 100755 index 0000000000..254199052f --- /dev/null +++ b/scripts/test.canisters.sh @@ -0,0 +1,31 @@ +POCKET_IC_SERVER_VERSION=6.0.0 +POCKET_IC_SERVER_PATH="pocket-ic" + +if [[ $OSTYPE == "linux-gnu"* ]] || [[ $RUNNER_OS == "Linux" ]]; then + PLATFORM=linux +elif [[ $OSTYPE == "darwin"* ]] || [[ $RUNNER_OS == "macOS" ]]; then + PLATFORM=darwin +else + echo "OS not supported: ${OSTYPE:-$RUNNER_OS}" + exit 1 +fi + +if [ ! -f "$POCKET_IC_SERVER_PATH" ]; then + echo "Downloading PocketIC." + curl -sSL https://github.com/dfinity/pocketic/releases/download/${POCKET_IC_SERVER_VERSION}/pocket-ic-x86_64-${PLATFORM}.gz -o ${POCKET_IC_SERVER_PATH}.gz + gunzip ${POCKET_IC_SERVER_PATH}.gz + chmod +x ${POCKET_IC_SERVER_PATH} +else + echo "PocketIC server already exists, skipping download." +fi + +# Build II +II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 ./scripts/build --internet-identity + +# Build archive +./scripts/build --archive + +# Run tests + +echo "Running signer integration tests." +cargo test "${@}" \ No newline at end of file diff --git a/src/archive/src/main.rs b/src/archive/src/main.rs index 9de5778ae1..469abd5319 100644 --- a/src/archive/src/main.rs +++ b/src/archive/src/main.rs @@ -575,6 +575,7 @@ fn http_request(req: HttpRequest) -> HttpResponse { } fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { + const WASM_PAGE_SIZE_IN_BYTES: f64 = 65536.0; with_config(|config| { w.encode_gauge( "ii_archive_last_upgrade_timestamp_seconds", diff --git a/src/internet_identity/src/http/metrics.rs b/src/internet_identity/src/http/metrics.rs index 3b166e242d..0711417566 100644 --- a/src/internet_identity/src/http/metrics.rs +++ b/src/internet_identity/src/http/metrics.rs @@ -21,6 +21,8 @@ pub fn metrics() -> Result, std::io::Error> { } fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { + const WASM_PAGE_SIZE_IN_BYTES: f64 = 65536.0; + state::storage_borrow(|storage| { w.encode_gauge( "internet_identity_user_count", From c7a563799c028aef163d6443f53a764fef20f759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7?= Date: Tue, 15 Oct 2024 10:04:35 +0200 Subject: [PATCH 2/6] Remove file --- scripts/test.canisters.sh | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100755 scripts/test.canisters.sh diff --git a/scripts/test.canisters.sh b/scripts/test.canisters.sh deleted file mode 100755 index 254199052f..0000000000 --- a/scripts/test.canisters.sh +++ /dev/null @@ -1,31 +0,0 @@ -POCKET_IC_SERVER_VERSION=6.0.0 -POCKET_IC_SERVER_PATH="pocket-ic" - -if [[ $OSTYPE == "linux-gnu"* ]] || [[ $RUNNER_OS == "Linux" ]]; then - PLATFORM=linux -elif [[ $OSTYPE == "darwin"* ]] || [[ $RUNNER_OS == "macOS" ]]; then - PLATFORM=darwin -else - echo "OS not supported: ${OSTYPE:-$RUNNER_OS}" - exit 1 -fi - -if [ ! -f "$POCKET_IC_SERVER_PATH" ]; then - echo "Downloading PocketIC." - curl -sSL https://github.com/dfinity/pocketic/releases/download/${POCKET_IC_SERVER_VERSION}/pocket-ic-x86_64-${PLATFORM}.gz -o ${POCKET_IC_SERVER_PATH}.gz - gunzip ${POCKET_IC_SERVER_PATH}.gz - chmod +x ${POCKET_IC_SERVER_PATH} -else - echo "PocketIC server already exists, skipping download." -fi - -# Build II -II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 ./scripts/build --internet-identity - -# Build archive -./scripts/build --archive - -# Run tests - -echo "Running signer integration tests." -cargo test "${@}" \ No newline at end of file From 54d49e2e2b6bdddb99c6b74dfb3e5ddb8f323838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7?= Date: Tue, 15 Oct 2024 12:08:33 +0200 Subject: [PATCH 3/6] Import page size constant and multiply integers --- src/archive/src/main.rs | 1 - src/internet_identity/src/http/metrics.rs | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/archive/src/main.rs b/src/archive/src/main.rs index 469abd5319..9de5778ae1 100644 --- a/src/archive/src/main.rs +++ b/src/archive/src/main.rs @@ -575,7 +575,6 @@ fn http_request(req: HttpRequest) -> HttpResponse { } fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { - const WASM_PAGE_SIZE_IN_BYTES: f64 = 65536.0; with_config(|config| { w.encode_gauge( "ii_archive_last_upgrade_timestamp_seconds", diff --git a/src/internet_identity/src/http/metrics.rs b/src/internet_identity/src/http/metrics.rs index 0711417566..3b166e242d 100644 --- a/src/internet_identity/src/http/metrics.rs +++ b/src/internet_identity/src/http/metrics.rs @@ -21,8 +21,6 @@ pub fn metrics() -> Result, std::io::Error> { } fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { - const WASM_PAGE_SIZE_IN_BYTES: f64 = 65536.0; - state::storage_borrow(|storage| { w.encode_gauge( "internet_identity_user_count", From 22926be1855f6375e19d369fbe08799f388a50a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7?= Date: Tue, 15 Oct 2024 13:19:10 +0200 Subject: [PATCH 4/6] Create script to run canisters tests --- HACKING.md | 33 ++++++++++++------ scripts/test.canisters.sh | 49 +++++++++++++++++++++++++++ src/internet_identity/tests/README.md | 17 ++-------- 3 files changed, 74 insertions(+), 25 deletions(-) create mode 100755 scripts/test.canisters.sh diff --git a/HACKING.md b/HACKING.md index d1266f7981..90a6860ce0 100644 --- a/HACKING.md +++ b/HACKING.md @@ -10,11 +10,11 @@ This document explains how to build the Wasm module of the Internet Identity can The build requires the following dependencies: -* [`dfx`](https://github.com/dfinity/sdk/releases/latest) version 0.10.0 or later -* Rustup with target `wasm32-unknown-unknown` (see [rustup instructions](https://rust-lang.github.io/rustup/cross-compilation.html)), which can be installed by running [./scripts/bootstrap](./scripts/bootstrap) -* CMake -* [`ic-wasm`](https://github.com/dfinity/ic-wasm), which can be installed by running [./scripts/bootstrap](./scripts/bootstrap) -* Node.js v16+ +- [`dfx`](https://github.com/dfinity/sdk/releases/latest) version 0.10.0 or later +- Rustup with target `wasm32-unknown-unknown` (see [rustup instructions](https://rust-lang.github.io/rustup/cross-compilation.html)), which can be installed by running [./scripts/bootstrap](./scripts/bootstrap) +- CMake +- [`ic-wasm`](https://github.com/dfinity/ic-wasm), which can be installed by running [./scripts/bootstrap](./scripts/bootstrap) +- Node.js v16+ > NOTE! If you're only going to hack on the HTML and CSS code, see the [showcase](#showcase) section. @@ -38,7 +38,6 @@ dfx deploy internet_identity --no-wallet > `II_DUMMY_CAPTCHA` to `0`:\ > `II_DUMMY_CAPTCHA=0 dfx deploy internet_identity --no-wallet` - Then the canister can be used as ```bash @@ -56,7 +55,7 @@ The `dfx` executable can proxy queries to the canister. To view it, run the foll echo "http://$(dfx canister id internet_identity).localhost:4943" ``` -*Note: The URL doesn't work for safari.* +_Note: The URL doesn't work for safari._ ### Building the frontend @@ -95,6 +94,7 @@ into the following issues: #### Test suites We have a set of Selenium tests that run through the various flows. To set up a local deployment follow these steps: + 1. Start a local replica with `dfx start` 1. Deploy II and the other test canisters with `dfx deploy --no-wallet` 1. Start the vite dev server with TLS enabled: `TLS_DEV_SERVER=1 npm run dev` @@ -112,6 +112,15 @@ If you open a PR that isn't formatted according to `prettier`, CI will automatic We use `eslint` to check the frontend code. You can run it with `npm run lint`. +#### Canisters tests + +There are plenty of unit and integration tests that cover the different canisters of this repository which cover all the functionality that Internet Identity offer. + +To run the canister tests, run the following command from the root directory: + +```bash +./scripts.test.canisters.sh +``` ### Building the backend @@ -138,21 +147,26 @@ This will produce `./internet_identity.wasm.gz`. ## Attribute Sharing / Verifiable Credentials To experiment with Attribute Sharing / Verifiable Credentials feature, one can start a demo VC-issuer by running + ```bash dfx deploy issuer ``` + This will deploy also `internet_identity`, and provision the issuer for the testing environment. See [VC issuer documentation](./demos/vc_issuer/README.md) for details. Our [`test-app`](./demos/test-app) offers a simple relying party functionality and can be deployed using + ```bash dfx deploy test_app ``` Afterward one can serve the frontends locally via: + ```bash npm run dev ``` + and access the issuer FE at http://issuer.localhost:5173/, and the test-app at http://test_app.localhost:5173/ (the relying party is functionality is at the bottom of the page). @@ -160,18 +174,17 @@ and access the issuer FE at http://issuer.localhost:5173/, and the test-app at h The simplest way to make visual changes (HTML & CSS, and non-flow JS) is to start the showcase: -``` bash +```bash npm run showcase ``` This will start a webserver showcasing most II pages & components. The showcase can also be built: -``` bash +```bash npm run build:showcase [--base 'some-base/'] npm run preview:showcase [--base 'some-base/'] ``` - [releases]: https://github.com/dfinity/internet-identity/releases [docker-build]: ./README.md#building-with-docker [features-and-flavors]: ./README.md#build-features-and-flavors diff --git a/scripts/test.canisters.sh b/scripts/test.canisters.sh new file mode 100755 index 0000000000..bf578e90de --- /dev/null +++ b/scripts/test.canisters.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +POCKET_IC_SERVER_VERSION=6.0.0 +POCKET_IC_SERVER_PATH="pocket-ic" +PREVIOUS_II_WASM_PATH="internet_identity_previous.wasm.gz" +PREVIOUS_ARCHIVE_WASM_PATH="archive_previous.wasm.gz" + +if [[ $OSTYPE == "linux-gnu"* ]] || [[ $RUNNER_OS == "Linux" ]]; then + PLATFORM=linux +elif [[ $OSTYPE == "darwin"* ]] || [[ $RUNNER_OS == "macOS" ]]; then + PLATFORM=darwin +else + echo "OS not supported: ${OSTYPE:-$RUNNER_OS}" + exit 1 +fi + +if [ -f "./$PREVIOUS_II_WASM_PATH" ]; then + echo "Using previous II wasm." +else + echo "Downloading previous II wasm." +curl -sSL https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_test.wasm.gz -o ${PREVIOUS_II_WASM_PATH} +fi + +if [ -f "./$PREVIOUS_ARCHIVE_WASM_PATH" ]; then + echo "Using previous Archive wasm." +else + echo "Downloading previous Archive wasm." + curl -sSL https://github.com/dfinity/internet-identity/releases/latest/download/archive.wasm.gz -o ${PREVIOUS_ARCHIVE_WASM_PATH} +fi + +if [ ! -f "$POCKET_IC_SERVER_PATH" ]; then + echo "Downloading PocketIC." + curl -sSL https://github.com/dfinity/pocketic/releases/download/${POCKET_IC_SERVER_VERSION}/pocket-ic-x86_64-${PLATFORM}.gz -o ${POCKET_IC_SERVER_PATH}.gz + gunzip ${POCKET_IC_SERVER_PATH}.gz + chmod +x ${POCKET_IC_SERVER_PATH} +else + echo "PocketIC server already exists, skipping download." +fi + +# Build II +II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 ./scripts/build --internet-identity + +# Build Archive +./scripts/build --archive + +# Run tests + +echo "Running integration tests." +cargo test "${@}" \ No newline at end of file diff --git a/src/internet_identity/tests/README.md b/src/internet_identity/tests/README.md index b5cf8cfcaf..d6e380d988 100644 --- a/src/internet_identity/tests/README.md +++ b/src/internet_identity/tests/README.md @@ -2,21 +2,8 @@ This is a test suite for the Internet Identity canister. To run the tests: -``` bash -# Make sure II is built with the "test" flavor -II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 ./scripts/build - -# Build the archive canister -./scripts/build --archive - -# Make sure you have a copy of the latest release of II -curl -SL https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_test.wasm -o internet_identity_previous.wasm - -# Make sure you have a copy of the latest release of the archive -curl -SL https://github.com/dfinity/internet-identity/releases/latest/download/archive.wasm -o archive_previous.wasm - -# Run the tests -cargo test -p internet_identity +```bash +./scripts.test.canisters.sh -p internet_identity ``` _NOTE: you can also run the tests with `cargo test -p internet_identity --release` which takes much longer to build, but the tests are then orders of magnitude faster._ From caf0046563e747cb02c1554cd670774b61be7283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7?= Date: Tue, 15 Oct 2024 14:53:37 +0200 Subject: [PATCH 5/6] CR changes --- HACKING.md | 2 +- scripts/{test.canisters.sh => test-canisters.sh} | 11 ++++++++++- src/internet_identity/tests/README.md | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) rename scripts/{test.canisters.sh => test-canisters.sh} (83%) diff --git a/HACKING.md b/HACKING.md index 90a6860ce0..bc39137b7a 100644 --- a/HACKING.md +++ b/HACKING.md @@ -119,7 +119,7 @@ There are plenty of unit and integration tests that cover the different canister To run the canister tests, run the following command from the root directory: ```bash -./scripts.test.canisters.sh +./scripts.test-canisters.sh ``` ### Building the backend diff --git a/scripts/test.canisters.sh b/scripts/test-canisters.sh similarity index 83% rename from scripts/test.canisters.sh rename to scripts/test-canisters.sh index bf578e90de..31d653e8aa 100755 --- a/scripts/test.canisters.sh +++ b/scripts/test-canisters.sh @@ -1,10 +1,19 @@ #!/bin/bash +set -euo pipefail POCKET_IC_SERVER_VERSION=6.0.0 POCKET_IC_SERVER_PATH="pocket-ic" PREVIOUS_II_WASM_PATH="internet_identity_previous.wasm.gz" PREVIOUS_ARCHIVE_WASM_PATH="archive_previous.wasm.gz" +# Check if the script is run from the root of the project +project_root=$(git rev-parse --show-toplevel 2>/dev/null) +if [ "$project_root" != "$(pwd)" ]; then + echo "Please run this script from the root of the project." + exit 1 +fi + +RUNNER_OS=${RUNNER_OS:-} if [[ $OSTYPE == "linux-gnu"* ]] || [[ $RUNNER_OS == "Linux" ]]; then PLATFORM=linux elif [[ $OSTYPE == "darwin"* ]] || [[ $RUNNER_OS == "macOS" ]]; then @@ -46,4 +55,4 @@ II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 ./scripts/build --internet-identity # Run tests echo "Running integration tests." -cargo test "${@}" \ No newline at end of file +cargo test "${@}" diff --git a/src/internet_identity/tests/README.md b/src/internet_identity/tests/README.md index d6e380d988..20bf06f010 100644 --- a/src/internet_identity/tests/README.md +++ b/src/internet_identity/tests/README.md @@ -3,7 +3,7 @@ This is a test suite for the Internet Identity canister. To run the tests: ```bash -./scripts.test.canisters.sh -p internet_identity +./scripts.test-canisters.sh -p internet_identity ``` _NOTE: you can also run the tests with `cargo test -p internet_identity --release` which takes much longer to build, but the tests are then orders of magnitude faster._ From 744eac6e322e0a5728d532624b91223a015dab13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7?= Date: Tue, 15 Oct 2024 15:12:17 +0200 Subject: [PATCH 6/6] CR changes --- scripts/test-canisters.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/test-canisters.sh b/scripts/test-canisters.sh index 31d653e8aa..1b912d74b0 100755 --- a/scripts/test-canisters.sh +++ b/scripts/test-canisters.sh @@ -6,12 +6,9 @@ POCKET_IC_SERVER_PATH="pocket-ic" PREVIOUS_II_WASM_PATH="internet_identity_previous.wasm.gz" PREVIOUS_ARCHIVE_WASM_PATH="archive_previous.wasm.gz" -# Check if the script is run from the root of the project -project_root=$(git rev-parse --show-toplevel 2>/dev/null) -if [ "$project_root" != "$(pwd)" ]; then - echo "Please run this script from the root of the project." - exit 1 -fi +# Run the script from the main directory +SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$SCRIPTS_DIR/.." RUNNER_OS=${RUNNER_OS:-} if [[ $OSTYPE == "linux-gnu"* ]] || [[ $RUNNER_OS == "Linux" ]]; then