Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Aug 21, 2024
1 parent e122257 commit 07e60c0
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 0 deletions.
17 changes: 17 additions & 0 deletions integration-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.12
WORKDIR /usr/src/app/

ENV POETRY_VERSION=1.8.3
ENV POETRY_HOME=/opt/poetry
RUN curl -sSL https://install.python-poetry.org | python -

ENV PATH="/opt/poetry/bin:$PATH"
RUN poetry config virtualenvs.in-project true

# Setup project
COPY pyproject.toml poetry.lock README.md ./
RUN poetry install

COPY tests/ tests/

ENTRYPOINT ["poetry", "run"]
Empty file added integration-tests/README.md
Empty file.
91 changes: 91 additions & 0 deletions integration-tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This docker-compose file is used for tests only
version: "3"
services:
alice:
image: acapy-test
ports:
- "3001:3001"
command: >
start
--label Alice
--inbound-transport http 0.0.0.0 3000
--outbound-transport http
--endpoint http://alice:3000
--admin 0.0.0.0 3001
--admin-insecure-mode
--tails-server-base-url http://tails:6543
--genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
--wallet-type askar
--wallet-name alice
--wallet-key insecure
--auto-provision
--log-level debug
--debug-webhooks
healthcheck:
test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null
start_period: 30s
interval: 7s
timeout: 5s
retries: 5
depends_on:
tails:
condition: service_started

bob:
image: acapy-test
ports:
- "3002:3001"
command: >
start
--label Bob
--inbound-transport http 0.0.0.0 3000
--outbound-transport http
--endpoint http://bob:3000
--admin 0.0.0.0 3001
--admin-insecure-mode
--tails-server-base-url http://tails:6543
--genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
--wallet-type askar
--wallet-name bob
--wallet-key insecure
--auto-provision
--log-level debug
--debug-webhooks
--monitor-revocation-notification
healthcheck:
test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null
start_period: 30s
interval: 7s
timeout: 5s
retries: 5

tails:
image: ghcr.io/bcgov/tails-server:latest
ports:
- 6543:6543
environment:
- GENESIS_URL=https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
command: >
tails-server
--host 0.0.0.0
--port 6543
--storage-path /tmp/tails-files
--log-level INFO
tests:
container_name: juggernaut
build:
context: .
args:
install_flags: ""
environment:
- ALICE=http://alice:3001
- BOB=http://bob:3001
volumes:
- ./tests:/usr/src/app/tests:z
entrypoint: "poetry run pytest"
depends_on:
alice:
condition: service_healthy
bob:
condition: service_healthy
17 changes: 17 additions & 0 deletions integration-tests/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "integration-tests"
version = "0.1.0"
description = ""
authors = ["jamshale <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
acapy-controller = {git = "https://github.com/indicio-tech/acapy-minimal-example.git", python = ">=3.10,<4.0"}
pytest = "^8.3.2"
pytest-asyncio = "^0.23.8"
pydantic = "^2.8.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file.
198 changes: 198 additions & 0 deletions integration-tests/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import asyncio
from os import getenv
from typing import Tuple

import pytest
import pytest_asyncio
from acapy_controller.controller import Controller
from acapy_controller.protocols import (
ConnRecord,
CredDefResult,
SchemaResult,
V10CredentialExchange,
didexchange,
indy_anoncred_credential_artifacts,
indy_anoncred_onboard,
indy_issue_credential_v1,
indy_issue_credential_v2,
indy_present_proof_v1,
indy_present_proof_v2,
)
from pytest_asyncio import is_async_test


def getenv_or_raise(var: str) -> str:
value = getenv(var)
if value is None:
raise ValueError(f"Missing environmnet variable: {var}")

return value


@pytest.fixture(scope="session")
def event_loop():
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close()


def pytest_collection_modifyitems(items):
pytest_asyncio_tests = (item for item in items if is_async_test(item))
session_scope_marker = pytest.mark.asyncio(scope="session")
for async_test in pytest_asyncio_tests:
async_test.add_marker(session_scope_marker, append=False)


@pytest_asyncio.fixture(scope="session")
async def alice():
controller = await Controller(getenv_or_raise("ALICE")).setup()
yield controller
await controller.shutdown()


@pytest_asyncio.fixture(scope="session")
async def bob():
controller = await Controller(getenv_or_raise("BOB")).setup()
yield controller
await controller.shutdown()


@pytest_asyncio.fixture(scope="session")
async def did_exchange(alice: Controller, bob: Controller):
"""Testing that dids are exchanged successfully."""
alice_conn, bob_conn = await didexchange(alice, bob)
assert alice_conn
assert bob_conn
yield alice_conn, bob_conn


@pytest.fixture(scope="session")
def alice_conn(did_exchange: Tuple[ConnRecord, ConnRecord]):
alice_conn, _ = did_exchange
yield alice_conn


@pytest.fixture(scope="session")
def bob_conn(did_exchange: Tuple[ConnRecord, ConnRecord]):
_, bob_conn = did_exchange
yield bob_conn


@pytest_asyncio.fixture(scope="session")
async def public_did(alice: Controller):
"""Onboard public DID."""
public_did = await indy_anoncred_onboard(alice)
assert public_did
yield public_did


@pytest_asyncio.fixture(scope="session")
async def cred_artifacts(alice: Controller):
"""Testing the preparation of credential artifacts for indy anoncreds."""
schema, cred_def = await indy_anoncred_credential_artifacts(
alice,
["firstname", "lastname"],
support_revocation=True,
)
assert schema
assert cred_def
yield schema, cred_def


@pytest_asyncio.fixture(scope="session")
async def cred_def(cred_artifacts: Tuple[SchemaResult, CredDefResult]):
_, cred_def = cred_artifacts
yield cred_def


@pytest_asyncio.fixture(scope="session")
async def alice_cred_ex(
alice: Controller,
bob: Controller,
alice_conn: ConnRecord,
bob_conn: ConnRecord,
cred_def: CredDefResult,
):
"""Testing issuing an indy credential using issue-credential/1.0.
Issuer and holder should already be connected.
"""
alice_cred_ex, bob_cred_ex = await indy_issue_credential_v1(
alice,
bob,
alice_conn.connection_id,
bob_conn.connection_id,
cred_def.credential_definition_id,
{"firstname": "Bob", "lastname": "Builder"},
)

assert alice_cred_ex
assert bob_cred_ex
yield alice_cred_ex


@pytest_asyncio.fixture(scope="session")
async def alice_cred_ex_v2(
alice: Controller,
bob: Controller,
alice_conn: ConnRecord,
bob_conn: ConnRecord,
cred_def: CredDefResult,
):
"""Testing issuing an indy credential using issue-credential/2.0.
Issuer and holder should already be connected.
"""
alice_cred_ex_v2, bob_cred_ex_v2 = await indy_issue_credential_v2(
alice,
bob,
alice_conn.connection_id,
bob_conn.connection_id,
cred_def.credential_definition_id,
{"firstname": "Bob", "lastname": "Builder"},
)

assert alice_cred_ex_v2
assert bob_cred_ex_v2
yield alice_cred_ex_v2


@pytest_asyncio.fixture(scope="session")
async def alice_pres_ex(
alice: Controller,
bob: Controller,
alice_conn: ConnRecord,
bob_conn: ConnRecord,
alice_cred_ex: V10CredentialExchange,
):
"""Testing presenting an Indy credential using present proof v1."""
bob_pres_ex, alice_pres_ex = await indy_present_proof_v1(
bob,
alice,
bob_conn.connection_id,
alice_conn.connection_id,
requested_attributes=[{"name": "firstname"}],
)
assert bob_pres_ex
assert alice_pres_ex
yield alice_pres_ex


@pytest_asyncio.fixture(scope="session")
async def alice_pres_ex_v2(
alice: Controller,
bob: Controller,
alice_conn: ConnRecord,
bob_conn: ConnRecord,
alice_cred_ex: V10CredentialExchange,
):
"""Testing presenting an Indy credential using present proof v2."""
bob_pres_ex_v2, alice_pres_ex_v2 = await indy_present_proof_v2(
bob,
alice,
bob_conn.connection_id,
alice_conn.connection_id,
requested_attributes=[{"name": "firstname"}],
)
assert bob_pres_ex_v2
assert alice_pres_ex_v2
yield alice_pres_ex_v2
13 changes: 13 additions & 0 deletions integration-tests/tests/test_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Tuple

from acapy_controller.controller import Minimal


def test_simple(did_exchange: Tuple[Minimal, Minimal]):
from acapy_controller.models import ConnRecord

alice, bob = did_exchange
alice_conn = alice.into(ConnRecord)
bob_conn = bob.into(ConnRecord)
assert bob_conn.connection_protocol
assert alice_conn.invitation_mode

0 comments on commit 07e60c0

Please sign in to comment.