Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci-lint-cvat-recording-oracle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:
python-version: '3.10'
cache: 'poetry'
cache-dependency-path: ${{ env.WORKING_DIR }}/poetry.lock
- run: poetry install --no-root --only lint
- run: poetry install --no-root --only dev
- run: poetry run pre-commit run --all-files
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-cvat-exchange-oracle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- uses: actions/checkout@v7
- name: CVAT Exchange Oracle tests
working-directory: ./packages/examples/cvat/exchange-oracle
run: docker compose -f docker-compose.test.yml up --attach test --exit-code-from test
run: docker compose -f docker-compose.test.yml -f docker-compose.test.head.yml up --attach test --exit-code-from test
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-cvat-recording-oracle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- uses: actions/checkout@v7
- name: CVAT Recording Oracle tests
working-directory: ./packages/examples/cvat/recording-oracle
run: docker compose -f docker-compose.test.yml up --attach test --exit-code-from test
run: docker compose -f docker-compose.test.yml -f docker-compose.test.head.yml up --attach test --exit-code-from test
2 changes: 1 addition & 1 deletion packages/examples/cvat/exchange-oracle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update -y && \
apt-get install -y jq ffmpeg libsm6 libxext6 && \
rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache poetry
RUN pip install --no-cache 'poetry==1.8.5'

COPY pyproject.toml poetry.lock ./

Expand Down
47 changes: 43 additions & 4 deletions packages/examples/cvat/exchange-oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,47 @@ Available at `/docs` route

### Tests

To run tests
#### "oneshot" run

A single command to build, run, and tear down the test suite:

```sh
docker compose -p "test" \
-f docker-compose.test.yml \
-f docker-compose.test.head.yml \
up --build test --attach test --exit-code-from test; \
docker compose -p "test" \
-f docker-compose.test.yml \
-f docker-compose.test.head.yml \
down
```

Use this option for CI and for clean single time test runs.

#### Running separate elements

Dev builds require faster iteration and some components may require more control. The following
commands allow running just the services, build, tear down, and run the test suite:

```sh
docker compose -p "test" -f docker-compose.test.yml up --build test --attach test --exit-code-from test; \
docker compose -p "test" -f docker-compose.test.yml down
```
# run services
docker compose -p "test" \
-f docker-compose.test.yml \
up -d --build

# run the tests
docker compose -p "test" \
-f docker-compose.test.yml \
-f docker-compose.test.head.yml \
-f docker-compose.test.head.dev.yml \
up --build test --attach test --exit-code-from test

# tear down
docker compose -p "test" \
-f docker-compose.test.yml \
-f docker-compose.test.head.yml \
-f docker-compose.test.head.dev.yml \
down
```

The dev setup mounts the local directory to speed the things up.
10 changes: 6 additions & 4 deletions packages/examples/cvat/exchange-oracle/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
config.set_main_option("sqlalchemy.url", Config.postgres_config.connection_url())

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
fileConfig(
config.config_file_name,
disable_existing_loggers=config.attributes.get("disable_existing_loggers", True),
)

from src.db import Base # noqa: E402

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata

from src.db import Base # noqa: E402

target_metadata = Base.metadata

# other values from the config, defined by the needs of env.py,
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/cvat/exchange-oracle/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ def patched_get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
count=1,
factory_address="",
launcher="",
job_requester_id="",
status="Pending",
token="HMT", # noqa: S106
total_funded_amount=10,
created_at=datetime.datetime(2023, 1, 1, tzinfo=datetime.timezone.utc),
created_at=int(datetime.datetime(2023, 1, 1, tzinfo=datetime.timezone.utc).timestamp()),
manifest=(f"http://{Config.storage_config.endpoint_url}/manifests/{manifest_file}"),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
test:
build:
context: ./
dockerfile: dockerfiles/test.dev.Dockerfile
volumes:
- "./:/app:ro"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
services:
test:
build:
context: ./
dockerfile: dockerfiles/test.ci.Dockerfile
environment:
SQLALCHEMY_SILENCE_UBER_WARNING: 1
ENVIRONMENT: 'test'
PG_PORT: 5432
PG_HOST: 'postgres'
PG_USER: 'test'
PG_PASSWORD: 'test'
PG_DB: 'exchange_oracle_test'
WEB3_HTTP_PROVIDER_URI: 'http://blockchain-node:8545'
STORAGE_ENDPOINT_URL: 'host.docker.internal:9000'
STORAGE_ACCESS_KEY: 'dev'
STORAGE_SECRET_KEY: 'devdevdev'
STORAGE_RESULTS_BUCKET_NAME: 'results'
STORAGE_USE_SSL: 'False'
STORAGE_PROVIDER: 'aws'
ENABLE_CUSTOM_CLOUD_HOST: 'Yes'
REDIS_HOST: 'redis'
depends_on:
postgres:
condition: service_started
redis:
condition: service_started
minio-mc:
condition: service_completed_successfully
# Used to reference localhost since minio:9000 is rejected by the SDK URL validator
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- test-network
tty: true
35 changes: 0 additions & 35 deletions packages/examples/cvat/exchange-oracle/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,6 @@ services:
networks:
- test-network

test:
build:
context: ./
dockerfile: dockerfiles/test.Dockerfile
environment:
SQLALCHEMY_SILENCE_UBER_WARNING: 1
ENVIRONMENT: 'test'
PG_PORT: 5432
PG_HOST: 'postgres'
PG_USER: 'test'
PG_PASSWORD: 'test'
PG_DB: 'exchange_oracle_test'
WEB3_HTTP_PROVIDER_URI: 'http://blockchain-node:8545'
STORAGE_ENDPOINT_URL: 'host.docker.internal:9000'
STORAGE_ACCESS_KEY: 'dev'
STORAGE_SECRET_KEY: 'devdevdev'
STORAGE_RESULTS_BUCKET_NAME: 'results'
STORAGE_USE_SSL: 'False'
STORAGE_PROVIDER: 'aws'
ENABLE_CUSTOM_CLOUD_HOST: 'Yes'
REDIS_HOST: 'redis'
depends_on:
postgres:
condition: service_started
redis:
condition: service_started
minio-mc:
condition: service_completed_successfully
# Used to reference localhost since minio:9000 is rejected by the SDK URL validator
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- test-network
tty: true

networks:
test-network:
driver: bridge
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update -y && \
apt-get install -y jq ffmpeg libsm6 libxext6 && \
rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache poetry
RUN pip install --no-cache 'poetry==1.8.5'

COPY pyproject.toml poetry.lock ./

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Local dev test image: only dependencies are baked in; the source tree is bind-mounted at
# runtime by docker-compose.test.head.dev.yml. Skipping the source COPY keeps rebuilds fast when
# iterating locally. For CI / clean self-contained runs, use test.ci.Dockerfile instead.
FROM python:3.10

WORKDIR /app

RUN apt-get update -y && \
apt-get install -y jq ffmpeg libsm6 libxext6 && \
rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache 'poetry==1.8.5'

COPY pyproject.toml poetry.lock ./

RUN --mount=type=cache,target=/root/.cache \
poetry config virtualenvs.create false && \
poetry install --no-interaction --no-ansi --no-root

RUN python -m pip uninstall -y poetry pip

CMD ["pytest"]
84 changes: 4 additions & 80 deletions packages/examples/cvat/exchange-oracle/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/examples/cvat/exchange-oracle/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ psycopg2 = "^2.9.6"
sqlalchemy-utils = "^0.41.1"
alembic = "^1.11.1"
httpx = "^0.24.1"
pytest = "^7.2.2"
cvat-sdk = "2.37.0"
sqlalchemy = "^2.0.16"
apscheduler = "^3.10.1"
Expand All @@ -35,12 +34,13 @@ starlette = ">=0.40.0" # avoid the vulnerability with multipart/form-data
cryptography = "<44.0.0" # human-protocol-sdk -> pgpy dep requires cryptography < 45
aiocache = {extras = ["msgpack", "redis"], version = "^0.12.3"} # convenient api for redis (async)
cachelib = "^0.13.0" # convenient api for redis (sync)
human-protocol-sdk = "^4.3.0"
human-protocol-sdk = "^7.3.1"


[tool.poetry.group.dev.dependencies]
pre-commit = "^3.0.4"
ruff = "^0.6.0"
pytest = "^7.2.2"
pytest-mock = "^3.14.0"

[tool.ruff]
Expand Down
Loading