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

Add script test canisters #2652

Merged
merged 6 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
33 changes: 23 additions & 10 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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`
Expand All @@ -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

Expand All @@ -138,40 +147,44 @@ 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).

## Showcase

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
58 changes: 58 additions & 0 deletions scripts/test-canisters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally just switch to the appropriate directory:

SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPTS_DIR/.."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, changed!

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
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 "${@}"
17 changes: 2 additions & 15 deletions src/internet_identity/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._