Skip to content

Commit

Permalink
Merge pull request #81 from kilnfi/fix-finalized
Browse files Browse the repository at this point in the history
fix: conversion of enum to str
  • Loading branch information
aimxhaisse authored Oct 24, 2023
2 parents 9ff418e + 3666e39 commit 1dbdfdc
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 428 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
- name: Set up Poetry
uses: abatilo/actions-poetry@v2
- name: Install package with dev dependencies
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
FROM python:3.9.2-buster as builder
FROM python:3.11.6-bookworm as builder
WORKDIR /app

COPY . /app
RUN pip install --upgrade pip
RUN pip install --no-cache-dir --progress-bar off .

FROM gcr.io/distroless/python3:nonroot
# Use Python 3.11 from Debian 12
FROM gcr.io/distroless/python3-debian12:nonroot

COPY --from=builder /app /app
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin/eth-validator-watcher /usr/local/bin/eth-validator-watcher

COPY liveness_check.py /usr/local/bin/liveness_check.py

ENV PYTHONPATH=/usr/local/lib/python3.9/site-packages
ENV PYTHONPATH=/usr/local/lib/python3.11/site-packages

ENTRYPOINT [ "python", "/usr/local/bin/eth-validator-watcher" ]
8 changes: 4 additions & 4 deletions eth_validator_watcher/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Contains the models for the validator watcher."""

from enum import Enum
from enum import StrEnum
from typing import Optional

from pydantic import BaseModel


class Validators(BaseModel):
class DataItem(BaseModel):
class StatusEnum(str, Enum):
class StatusEnum(StrEnum):
pendingInitialized = "pending_initialized"
pendingQueued = "pending_queued"
activeOngoing = "active_ongoing"
Expand Down Expand Up @@ -129,15 +129,15 @@ class CoinbaseTrade(BaseModel):
side: str


class BeaconType(str, Enum):
class BeaconType(StrEnum):
LIGHTHOUSE = "lighthouse"
NIMBUS = "nimbus"
OLD_PRYSM = "old-prysm"
OLD_TEKU = "old-teku"
OTHER = "other"


class BlockIdentierType(str, Enum):
class BlockIdentierType(StrEnum):
HEAD = "head"
GENESIS = "genesis"
FINALIZED = "finalized"
Expand Down
774 changes: 359 additions & 415 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"
packages = [{include = "eth_validator_watcher"}]

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.11"
more-itertools = "^9.1.0"
prometheus-client = "^0.17.0"
pydantic = "^2.0"
Expand Down
17 changes: 16 additions & 1 deletion tests/beacon/test_get_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

from pytest import raises
from requests import HTTPError, Response, codes
from requests import HTTPError, Response, codes, exceptions
from requests_mock import Mocker

from eth_validator_watcher.beacon import Beacon, NoBlockError
Expand Down Expand Up @@ -38,3 +38,18 @@ def get(url: str, **_) -> Response:

with raises(NoBlockError):
beacon.get_block(42)


def test_get_block_invalid_request() -> None:
def get(url: str, **_) -> Response:
assert url == "http://beacon-node:5052/eth/v2/beacon/blocks/-42"
response = Response()
response.status_code = codes.INTERNAL_SERVER_ERROR

raise HTTPError(response=response)

beacon = Beacon("http://beacon-node:5052")
beacon._Beacon__http.get = get # type: ignore

with raises(exceptions.RequestException):
beacon.get_block(-42)
17 changes: 16 additions & 1 deletion tests/beacon/test_get_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

from pytest import raises
from requests import HTTPError, Response, codes
from requests import HTTPError, Response, codes, exceptions
from requests_mock import Mocker

from eth_validator_watcher.beacon import Beacon, NoBlockError
Expand Down Expand Up @@ -47,3 +47,18 @@ def get(url: str, **_) -> Response:

with raises(NoBlockError):
beacon.get_header(42)


def test_get_header_invalid_query() -> None:
def get(url: str, **_) -> Response:
assert url == "http://beacon-node:5052/eth/v1/beacon/headers/-42"
response = Response()
response.status_code = codes.INTERNAL_SERVER_ERROR

raise HTTPError(response=response)

beacon = Beacon("http://beacon-node:5052")
beacon._Beacon__http.get = get # type: ignore

with raises(exceptions.RequestException):
beacon.get_header(-42)

0 comments on commit 1dbdfdc

Please sign in to comment.