From 95e2acb2fa76dc64a4ebb54d9ac79fe0b0608830 Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Thu, 6 Feb 2025 19:26:01 +0000 Subject: [PATCH] fix(rpc): Use pydantic's AliasChoice --- src/ethereum_test_rpc/types.py | 8 +++----- src/ethereum_test_types/types.py | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ethereum_test_rpc/types.py b/src/ethereum_test_rpc/types.py index 864c3e8cd6..8c5ae9f938 100644 --- a/src/ethereum_test_rpc/types.py +++ b/src/ethereum_test_rpc/types.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Any, List -from pydantic import Field, model_validator +from pydantic import AliasChoices, Field, model_validator from ethereum_test_base_types import Address, Bytes, CamelModel, Hash, HexNumber from ethereum_test_fixtures.blockchain import FixtureExecutionPayload @@ -37,6 +37,8 @@ class TransactionByHashResponse(Transaction): from_address: Address = Field(..., alias="from") to_address: Address | None = Field(..., alias="to") + v: HexNumber | None = Field(None, validation_alias=AliasChoices("v", "yParity")) + @model_validator(mode="before") @classmethod def adapt_clients_response(cls, data: Any) -> Any: @@ -48,10 +50,6 @@ def adapt_clients_response(cls, data: Any) -> Any: if "gasPrice" in data and "maxFeePerGas" in data: # Keep only one of the gas price fields. del data["gasPrice"] - if "yParity" in data: - # Rename yParity to v. - data["v"] = data["yParity"] - del data["yParity"] return data def model_post_init(self, __context): diff --git a/src/ethereum_test_types/types.py b/src/ethereum_test_types/types.py index 0853602418..488ee57d93 100644 --- a/src/ethereum_test_types/types.py +++ b/src/ethereum_test_types/types.py @@ -13,6 +13,7 @@ from ethereum.frontier.state import State, set_account, set_storage, state_root from ethereum_types.numeric import U256, Bytes32, Uint from pydantic import ( + AliasChoices, BaseModel, ConfigDict, Field, @@ -436,7 +437,7 @@ class AuthorizationTupleGeneric(CamelModel, Generic[NumberBoundTypeVar]): address: Address nonce: List[NumberBoundTypeVar] | NumberBoundTypeVar = Field(0) # type: ignore - v: NumberBoundTypeVar = Field(0) # type: ignore + v: NumberBoundTypeVar = Field(0, validation_alias=AliasChoices("v", "yParity")) # type: ignore r: NumberBoundTypeVar = Field(0) # type: ignore s: NumberBoundTypeVar = Field(0) # type: ignore