From 99f6f3437fd8111d9245c04fd241c58dfd2a5815 Mon Sep 17 00:00:00 2001 From: m-r-g-t Date: Tue, 29 Aug 2023 15:05:45 +0100 Subject: [PATCH] fix: refactor tests for mypy --- mev_inspect/schemas/blocks.py | 4 ++-- mev_inspect/schemas/receipts.py | 2 +- tests/utils.py | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mev_inspect/schemas/blocks.py b/mev_inspect/schemas/blocks.py index c3dd3d75..228d0908 100644 --- a/mev_inspect/schemas/blocks.py +++ b/mev_inspect/schemas/blocks.py @@ -13,7 +13,7 @@ class CallResult(CamelModel): gas_used: int @validator("gas_used", pre=True) - def maybe_hex_to_int(v): + def maybe_hex_to_int(cls, v): if isinstance(v, str): return hex_to_int(v) return v @@ -27,7 +27,7 @@ class CallAction(Web3Model): gas: int @validator("value", "gas", pre=True) - def maybe_hex_to_int(v): + def maybe_hex_to_int(cls, v): if isinstance(v, str): return hex_to_int(v) return v diff --git a/mev_inspect/schemas/receipts.py b/mev_inspect/schemas/receipts.py index a5772b03..40814703 100644 --- a/mev_inspect/schemas/receipts.py +++ b/mev_inspect/schemas/receipts.py @@ -24,7 +24,7 @@ class Receipt(CamelModel): "cumulative_gas_used", pre=True, ) - def maybe_hex_to_int(v): + def maybe_hex_to_int(cls, v): if isinstance(v, str): return hex_to_int(v) return v diff --git a/tests/utils.py b/tests/utils.py index ec843d59..4ba537d3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,8 +2,6 @@ import os from typing import Dict, List -from pydantic import parse_file_as - from mev_inspect.schemas.blocks import Block from mev_inspect.schemas.sandwiches import Sandwich @@ -14,7 +12,10 @@ def load_test_sandwiches(block_number: int) -> List[Sandwich]: sandwiches_path = f"{TEST_SANDWICHES_DIRECTORY}/{block_number}.json" - return parse_file_as(List[Sandwich], sandwiches_path) + + with open(sandwiches_path, "r") as file: + sandwiches_data = json.load(file) + return [Sandwich(**sandwich) for sandwich in sandwiches_data] def load_test_block(block_number: int) -> Block: