Skip to content

Commit

Permalink
test: add didcomm test (#1427)
Browse files Browse the repository at this point in the history
Signed-off-by: Allain Magyar <allain.magyar@iohk.io>
Signed-off-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent 05fdf26 commit 01f0eb7
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 4 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ on:
defaults:
run:
shell: bash
working-directory: "tests/integration-tests"

permissions:
checks: write
Expand Down Expand Up @@ -58,12 +57,10 @@ jobs:
- name: Build local version of Cloud Agent
id: build_local_cloud_agent
env:
CLOUD_AGENT_PATH: "../.."
ENV_FILE: "infrastructure/local/.env"
GITHUB_ACTOR: hyperledger-bot
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd "${CLOUD_AGENT_PATH}" || exit 129
sbt docker:publishLocal
echo "agent_version=$(cut -d'=' -f2 version.sbt | tr -d '" ')" >> "${GITHUB_OUTPUT}"
echo "prism_node_version=$(grep PRISM_NODE_VERSION infrastructure/local/.env | cut -d'=' -f2 | tr -d ' ')" >> "${GITHUB_OUTPUT}"
Expand All @@ -74,6 +71,7 @@ jobs:
java-version: "19"

- name: Run integration tests
working-directory: "tests/integration-tests"
env:
PRISM_NODE_VERSION: ${{ steps.build_local_cloud_agent.outputs.prism_node_version }}
AGENT_VERSION: ${{ steps.build_local_cloud_agent.outputs.agent_version }}
Expand All @@ -84,6 +82,7 @@ jobs:
./gradlew test --tests "IntegrationTestsRunner"
- name: Make report of integration tests
working-directory: "tests/integration-tests"
if: always()
env:
PRISM_NODE_VERSION: ${{ steps.build_local_cloud_agent.outputs.prism_node_version }}
Expand All @@ -94,6 +93,7 @@ jobs:
./gradlew reports
- name: Extract test results
working-directory: "tests/integration-tests"
id: analyze_test_results
if: github.ref_name == 'main' && always()
run: |
Expand Down Expand Up @@ -161,3 +161,17 @@ jobs:
SLACK_TITLE: "Identus Cloud Agent Integration Tests: ${{ steps.analyze_test_results.outputs.conclusion }}"
SLACK_USERNAME: circleci
SLACK_WEBHOOK: ${{ secrets.E2E_TESTS_SLACK_WEBHOOK }}

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Run didcomm tests
working-directory: "tests/didcomm-tests"
env:
AGENT_VERSION: ${{ steps.build_local_cloud_agent.outputs.agent_version }}
run: |
./docker/run.sh "$AGENT_VERSION"
npm i
npm test
./docker/stop.sh
4 changes: 3 additions & 1 deletion .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ SQL_SQL_LINT_ARGUMENTS: -d postgres --ignore-errors=postgres-invalid-alter-optio
YAML_YAMLLINT_FILTER_REGEX_EXCLUDE: "infrastructure/charts/agent/*|cloud-agent/service/api/http/*|examples/*"
YAML_PRETTIER_FILTER_REGEX_EXCLUDE: "infrastructure/charts/agent/*|cloud-agent/service/api/http/*|examples/*"
YAML_V8R_FILTER_REGEX_EXCLUDE: "infrastructure/charts/agent/*"
JAVASCRIPT_STANDARD_FILTER_REGEX_EXCLUDE: "tests/performance-tests/agent-performance-tests-k6/src/k6chaijs.js"
JAVASCRIPT_STANDARD_FILTER_REGEX_EXCLUDE:
"tests/performance-tests/agent-performance-tests-k6/src/k6chaijs.js\
|tests/didcomm-tests/docker/initdb.js"
BASH_SHELLCHECK_FILTER_REGEX_EXCLUDE: "infrastructure/*"
128 changes: 128 additions & 0 deletions tests/didcomm-tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
services:
##########################
# Database
##########################
db:
image: postgres:13
environment:
POSTGRES_MULTIPLE_DATABASES: "castor,pollux,connect,agent,node_db"
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./postgres/init-script.sh:/docker-entrypoint-initdb.d/init-script.sh
- ./postgres/max_conns.sql:/docker-entrypoint-initdb.d/max_conns.sql
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres", "-d", "agent"]
interval: 10s
timeout: 5s
retries: 5

##########################
# Mediator
##########################
mongo:
image: mongo:6.0
command: ["--auth"]
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
- MONGO_INITDB_DATABASE=mediator
volumes:
- ./initdb.js:/docker-entrypoint-initdb.d/initdb.js

mediator:
network_mode: "container:didcomm-stack"
image: ghcr.io/hyperledger/identus-mediator:1.0.0
environment:
# Creates the identity:
- KEY_AGREEMENT_D=Z6D8LduZgZ6LnrOHPrMTS6uU2u5Btsrk1SGs4fn8M7c
- KEY_AGREEMENT_X=Sr4SkIskjN_VdKTn0zkjYbhGTWArdUNE4j_DmUpnQGw
- KEY_AUTHENTICATION_D=INXCnxFEl0atLIIQYruHzGd5sUivMRyQOzu87qVerug
- KEY_AUTHENTICATION_X=MBjnXZxkMcoQVVL21hahWAw43RuAG-i64ipbeKKqwoA
- SERVICE_ENDPOINTS=http://localhost:8080;ws://localhost:8080/ws
- MONGODB_USER=admin
- MONGODB_PASSWORD=admin
- MONGODB_PROTOCOL=mongodb
- MONGODB_HOST=mongo
- MONGODB_PORT=27017
- MONGODB_DB_NAME=mediator
depends_on:
- "mongo"
- "agent"

##########################
# Building-blocks
##########################
prism-node:
image: ghcr.io/input-output-hk/prism-node:2.5.0
environment:
NODE_PSQL_HOST: db:5432
depends_on:
db:
condition: service_healthy

agent:
container_name: didcomm-stack
image: ghcr.io/hyperledger/identus-cloud-agent:${CLOUD_AGENT_VERSION}
ports:
- "8080:8080"
- "8090:8090"
- "8091:8091"
environment:
CASTOR_DB_HOST: db
CASTOR_DB_PORT: 5432
CASTOR_DB_NAME: castor
CASTOR_DB_USER: postgres
CASTOR_DB_PASSWORD: postgres
POLLUX_DB_HOST: db
POLLUX_DB_PORT: 5432
POLLUX_DB_NAME: pollux
POLLUX_DB_USER: postgres
POLLUX_DB_PASSWORD: postgres
CONNECT_DB_HOST: db
CONNECT_DB_PORT: 5432
CONNECT_DB_NAME: connect
CONNECT_DB_USER: postgres
CONNECT_DB_PASSWORD: postgres
AGENT_DB_HOST: db
AGENT_DB_PORT: 5432
AGENT_DB_NAME: agent
AGENT_DB_USER: postgres
AGENT_DB_PASSWORD: postgres
AGENT_HTTP_PORT: 8090
REST_SERVICE_URL: http://localhost:8090
AGENT_DIDCOMM_PORT: 8091
DIDCOMM_SERVICE_URL: http://localhost:8091
PRISM_NODE_HOST: prism-node
PRISM_NODE_PORT: 50053
SECRET_STORAGE_BACKEND: postgres
DEV_MODE: true
DEFAULT_WALLET_ENABLED:
DEFAULT_WALLET_SEED:
DEFAULT_WALLET_WEBHOOK_URL:
DEFAULT_WALLET_WEBHOOK_API_KEY:
DEFAULT_WALLET_AUTH_API_KEY:
GLOBAL_WEBHOOK_URL:
GLOBAL_WEBHOOK_API_KEY:
WEBHOOK_PARALLELISM:
ADMIN_TOKEN:
API_KEY_SALT:
API_KEY_ENABLED: false
API_KEY_AUTHENTICATE_AS_DEFAULT_USER:
API_KEY_AUTO_PROVISIONING:
NODE_REFRESH_AND_SUBMIT_PERIOD:
NODE_MOVE_SCHEDULED_TO_PENDING_PERIOD:
NODE_WALLET_MAX_TPS:
depends_on:
db:
condition: service_healthy
prism-node:
condition: service_started
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8090/_system/health"]
interval: 10s
timeout: 10s
retries: 5
extra_hosts:
- "host.docker.internal:host-gateway"
26 changes: 26 additions & 0 deletions tests/didcomm-tests/docker/initdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
db.createUser({
user: 'admin',
pwd: 'admin',
roles: [
{ role: 'readWrite', db: 'mediator' }
]
})

const database = 'mediator'
const collectionDidAccount = 'user.account'
const collectionMessages = 'messages'
const collectionMessagesSend = 'messages.outbound'

// The current database to use.
use(database)

// Create collections.
db.createCollection(collectionDidAccount)
db.createCollection(collectionMessages)
db.createCollection(collectionMessagesSend)

// create index
db.getCollection(collectionDidAccount).createIndex({ did: 1 }, { unique: true })
// Only enforce uniqueness on non-empty arrays
db.getCollection(collectionDidAccount).createIndex({ alias: 1 }, { unique: true, partialFilterExpression: { 'alias.0': { $exists: true } } })
db.getCollection(collectionDidAccount).createIndex({ 'messagesRef.hash': 1, 'messagesRef.recipient': 1 })
24 changes: 24 additions & 0 deletions tests/didcomm-tests/docker/postgres/init-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e
set -u

function create_user_and_database() {
local database=$1
local app_user=${database}-application-user
echo " Creating user and database '$database'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER "$app_user" WITH PASSWORD 'password';
CREATE DATABASE $database;
\c $database
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "$app_user";
EOSQL
}

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
for db in $(echo "$POSTGRES_MULTIPLE_DATABASES" | tr ',' ' '); do
create_user_and_database "$db"
done
echo "Multiple databases created"
fi
2 changes: 2 additions & 0 deletions tests/didcomm-tests/docker/postgres/max_conns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

ALTER SYSTEM SET max_connections = 500;
11 changes: 11 additions & 0 deletions tests/didcomm-tests/docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

CLOUD_AGENT_VERSION=$1

PORT="$PRISM_PORT" \
CLOUD_AGENT_VERSION="$CLOUD_AGENT_VERSION" \
docker compose \
-f "docker/docker-compose.yml" \
up -d --wait
8 changes: 8 additions & 0 deletions tests/didcomm-tests/docker/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

CLOUD_AGENT_VERSION="$CLOUD_AGENT_VERSION" \
docker compose \
-f "./docker/docker-compose.yml" \
down -v
14 changes: 14 additions & 0 deletions tests/didcomm-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "didcomm-tests",
"version": "1.0.0",
"description": "Test suite for executing didcomm tests",
"main": "index.js",
"scripts": {
"test": "node node_modules/@amagyar-iohk/didcomm-test/dist/suite.spec.js"
},
"author": "Allain Magyar",
"license": "ISC",
"dependencies": {
"@amagyar-iohk/didcomm-test": "^1.0.4"
}
}

0 comments on commit 01f0eb7

Please sign in to comment.