Skip to content

Commit

Permalink
test: fixed a lot of tests
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Nov 17, 2023
1 parent dd390fb commit 8f133f5
Show file tree
Hide file tree
Showing 31 changed files with 277 additions and 314 deletions.
18 changes: 0 additions & 18 deletions .devcontainer/Dockerfile

This file was deleted.

4 changes: 1 addition & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"build": {
"dockerfile": "Dockerfile"
},
"image": "node:18",
"runArgs": ["--env-file", ".devcontainer/devcontainer.env"],
"workspaceMount": "source=${localWorkspaceFolder},target=/work,type=bind",
"workspaceFolder": "/work"
Expand Down
14 changes: 0 additions & 14 deletions .github/actions/setup-cheqd/action.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/actions/setup-indy-pool/action.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/actions/setup-libindy/action.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/actions/setup-postgres/action.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ jobs:
# pulls all commits (needed for lerna to correctly version)
fetch-depth: 0

# setup dependencies
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -69,10 +65,6 @@ jobs:
- name: Checkout aries-framework-javascript
uses: actions/checkout@v4

# setup dependencies
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
Expand Down
30 changes: 3 additions & 27 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ on:
workflow_dispatch:

env:
TEST_AGENT_PUBLIC_DID_SEED: 000000000000000000000000Trustee9
ENDORSER_AGENT_PUBLIC_DID_SEED: 00000000000000000000000Endorser9
GENESIS_TXN_PATH: network/genesis/local-genesis.txn
NODE_OPTIONS: --max_old_space_size=6144

# Make sure we're not running multiple release steps at the same time as this can give issues with determining the next npm version to release.
Expand Down Expand Up @@ -52,10 +49,6 @@ jobs:
- name: Checkout aries-framework-javascript
uses: actions/checkout@v4

# setup dependencies
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -90,21 +83,8 @@ jobs:
uses: actions/checkout@v4

# setup dependencies

- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup Indy Pool
uses: ./.github/actions/setup-indy-pool
with:
seed: ${TEST_AGENT_PUBLIC_DID_SEED}
endorserSeed: ${ENDORSER_AGENT_PUBLIC_DID_SEED}

- name: Setup Cheqd
uses: ./.github/actions/setup-cheqd

- name: Setup Postgres
uses: ./.github/actions/setup-postgres
- name: Setup services
run: docker compose up -d

- name: Setup NodeJS
uses: actions/setup-node@v3
Expand All @@ -116,7 +96,7 @@ jobs:
run: yarn install --frozen-lockfile

- name: Run tests
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} ENDORSER_AGENT_PUBLIC_DID_SEED=${ENDORSER_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test --coverage --forceExit --bail
run: yarn test --coverage --forceExit --bail

- uses: codecov/codecov-action@v3
if: always()
Expand All @@ -134,10 +114,6 @@ jobs:
fetch-depth: 0
persist-credentials: false

# setup dependencies
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
Expand Down
105 changes: 17 additions & 88 deletions DEVREADME.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,18 @@ GENESIS_TXN_PATH=/work/network/genesis/local-genesis.txn

Test are executed using jest. Some test require either the **mediator agents** or the **ledger** to be running. When running tests that require a connection to the ledger pool, you need to set the `TEST_AGENT_PUBLIC_DID_SEED`, `ENDORSER_AGENT_PUBLIC_DID_SEED` and `GENESIS_TXN_PATH` environment variables.

### Setting environment variables

If you're using the setup as described in this document, you don't need to provide any environment variables as the default will be sufficient.

- `GENESIS_TXN_PATH`: The path to the genesis transaction that allows us to connect to the indy pool.
- `GENESIS_TXN_PATH=network/genesis/local-genesis.txn` - default. Works with the [ledger setup](#setup-indy-ledger) from the previous step.
- `GENESIS_TXN_PATH=network/genesis/builder-net-genesis.txn` - Sovrin BuilderNet genesis.
- `GENESIS_TXN_PATH=/path/to/any/ledger/you/like`
- `TEST_AGENT_PUBLIC_DID_SEED`: The seed to use for the public DID. This will be used to do public write operations to the ledger. You should use a seed for a DID that is already registered on the ledger.
- If using the local or default genesis, use the same seed you used for the `add-did-from-seed` command from the [ledger setup](#setup-indy-ledger) in the previous step. (default is `000000000000000000000000Trustee9`)
- If using the BuilderNet genesis, make sure your seed is registered on the BuilderNet using [selfserve.sovrin.org](https://selfserve.sovrin.org/) and you have read and accepted the associated [Transaction Author Agreement](https://github.com/sovrin-foundation/sovrin/blob/master/TAA/TAA.md). We are not responsible for any unwanted consequences of using the BuilderNet.
- `ENDORSER_AGENT_PUBLIC_DID_SEED`: The seed to use for the public Endorser DID. This will be used to endorse transactions. You should use a seed for a DID that is already registered on the ledger.
- If using the local or default genesis, use the same seed you used for the `add-did-from-seed` command from the [ledger setup](#setup-indy-ledger) in the previous step. (default is `00000000000000000000000Endorser9`)
- If using the BuilderNet genesis, make sure your seed is registered on the BuilderNet using [selfserve.sovrin.org](https://selfserve.sovrin.org/) and you have read and accepted the associated [Transaction Author Agreement](https://github.com/sovrin-foundation/sovrin/blob/master/TAA/TAA.md). We are not responsible for any unwanted consequences of using the BuilderNet.

### Setup Postgres

> Note: Setup the postgres plugin first by following the [docs](https://aries.js.org/)
```sh
# Get postgres docker image
docker pull postgres

# Run postgres in docker
docker run --name postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres
```

### Setup Indy Ledger

For testing we've added a setup to this repo that allows you to quickly setup an indy ledger.

```sh
# Build indy pool
docker build -f network/indy-pool.dockerfile -t indy-pool . --platform linux/amd64

# NOTE: If you are on an ARM (M1) mac use the `network/indy-pool-arm.dockerfile` instead
# docker build -f network/indy-pool-arm.dockerfile -t indy-pool . --platform linux/arm64/v8

# Start indy pool
docker run -d --rm --name indy-pool -p 9701-9708:9701-9708 indy-pool

# Setup CLI. This creates a wallet, connects to the ledger and sets the Transaction Author Agreement
docker exec indy-pool indy-cli-setup

# DID and Verkey from seed. Set 'ENDORSER' role in order to be able to register public DIDs
docker exec indy-pool add-did-from-seed 00000000000000000000000Endorser9 ENDORSER

# DID and Verkey from seed. Set 'Trustee'
docker exec indy-pool add-did-from-seed 000000000000000000000000Trustee9 TRUSTEE

# If you want to register using the DID/Verkey you can use
# docker exec indy-pool add-did "NkGXDEPgpFGjQKMYmz6SyF" "CrSA1WbYYWLJoHm16Xw1VEeWxFvXtWjtsfEzMsjB5vDT"
```

### Setup Cheqd Ledger
### Quick Setup

In addition, there's also a docker command to run a cheqd test network.
To quickly set up all services needed to run tests (Postgres, Hyperledger Indy Ledger, and Cheqd Ledger), run the following command:

```sh
docker run --rm -d -p 26657:26657 ghcr.io/cheqd/cheqd-testnet:latest
docker compose up -d
```

If you want to run tests without the cheqd ledger, you can use the following ignore pattern:
If you're running on an ARM based machine (such as Apple Silicon), you can use the `docker-compose.arm.yml` file instead:

```sh
yarn test --testPathIgnorePatterns packages/cheqd
docker compose -f docker-compose.arm.yml up -d
```

### Run all tests
Expand All @@ -96,34 +42,17 @@ You can run the tests using the following command.
yarn test
```

If you're not using the ledger setup from above, make sure you pass the correct environment variables from [Setting environment variables](#setting-environment-variables) for connecting to the indy **ledger** pool.

```sh
GENESIS_TXN_PATH=network/genesis/local-genesis.txn TEST_AGENT_PUBLIC_DID_SEED=000000000000000000000000Trustee9 ENDORSER_AGENT_PUBLIC_DID_SEED=00000000000000000000000Endorser9 yarn test
```

Locally, you might want to run the tests without postgres tests. You can do that by ignoring the tests:

```sh
yarn test --testPathIgnorePatterns postgres.e2e.test.ts
```

In case you run into trouble running the tests, e.g. complaining about snapshots not being up-to-date, you can try and remove the data stored for the indy-client or AFJ. Note this removes all wallets and data, so make sure you're okay with all data being removed. On a Unix system with default setup you achieve this by running:

```sh
rm -rf ~/.indy-client ~/.afj
```

## Usage with Docker

If you don't want to install the libindy dependencies yourself, or want a clean environment when running the framework or tests you can use docker.

Make sure you followed the [local ledger setup](#setup-indy-ledger) to setup a local indy pool inside docker.
### Setting environment variables

```sh
# Builds the framework docker image with all dependencies installed
docker build -t aries-framework-javascript .
If you're using the setup as described in this document, you don't need to provide any environment variables as the default will be sufficient.

# Run test with ledger pool
docker run -it --rm --network host aries-framework-javascript yarn test
```
- `GENESIS_TXN_PATH`: The path to the genesis transaction that allows us to connect to the indy pool.
- `GENESIS_TXN_PATH=network/genesis/local-genesis.txn` - default. Works with the [ledger setup](#setup-indy-ledger) from the previous step.
- `GENESIS_TXN_PATH=network/genesis/builder-net-genesis.txn` - Sovrin BuilderNet genesis.
- `GENESIS_TXN_PATH=/path/to/any/ledger/you/like`
- `TEST_AGENT_PUBLIC_DID_SEED`: The seed to use for the public DID. This will be used to do public write operations to the ledger. You should use a seed for a DID that is already registered on the ledger.
- If using the local or default genesis, use the same seed you used for the `add-did-from-seed` command from the [ledger setup](#setup-indy-ledger) in the previous step. (default is `000000000000000000000000Trustee9`)
- If using the BuilderNet genesis, make sure your seed is registered on the BuilderNet using [selfserve.sovrin.org](https://selfserve.sovrin.org/) and you have read and accepted the associated [Transaction Author Agreement](https://github.com/sovrin-foundation/sovrin/blob/master/TAA/TAA.md). We are not responsible for any unwanted consequences of using the BuilderNet.
- `ENDORSER_AGENT_PUBLIC_DID_SEED`: The seed to use for the public Endorser DID. This will be used to endorse transactions. You should use a seed for a DID that is already registered on the ledger.
- If using the local or default genesis, use the same seed you used for the `add-did-from-seed` command from the [ledger setup](#setup-indy-ledger) in the previous step. (default is `00000000000000000000000Endorser9`)
- If using the BuilderNet genesis, make sure your seed is registered on the BuilderNet using [selfserve.sovrin.org](https://selfserve.sovrin.org/) and you have read and accepted the associated [Transaction Author Agreement](https://github.com/sovrin-foundation/sovrin/blob/master/TAA/TAA.md). We are not responsible for any unwanted consequences of using the BuilderNet.
32 changes: 32 additions & 0 deletions docker-compose.arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3'
services:
postgres:
image: postgres:15-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'

indy-pool:
build:
context: .
dockerfile: network/indy-pool-arm.dockerfile
platform: linux/arm64/v8
ports:
- '9701-9708:9701-9708'
# Start supervisord in bg, run commands, bring supervisor to fg
command: >
/bin/bash -c "
/usr/bin/supervisord &
indy-cli-setup &&
add-did-from-seed 00000000000000000000000Endorser9 ENDORSER &&
add-did-from-seed 000000000000000000000000Trustee9 TRUSTEE &&
/usr/bin/supervisord -n
"
cheqd-ledger:
image: ghcr.io/cheqd/cheqd-testnet:latest
platform: linux/amd64
ports:
- '26657:26657'
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3'
services:
postgres:
image: postgres:15-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'

indy-pool:
build:
context: .
dockerfile: network/indy-pool.dockerfile
target: linux/amd64
ports:
- '9701-9708:9701-9708'
# Start supervisord in bg, run commands, bring supervisor to fg
command: >
/bin/bash -c "
/usr/bin/supervisord &
indy-cli-setup &&
add-did-from-seed 00000000000000000000000Endorser9 ENDORSER &&
add-did-from-seed 000000000000000000000000Trustee9 TRUSTEE &&
/usr/bin/supervisord -n
"
cheqd-ledger:
image: ghcr.io/cheqd/cheqd-testnet:latest
platform: linux/amd64
ports:
- '26657:26657'
Loading

0 comments on commit 8f133f5

Please sign in to comment.