Skip to content

Commit

Permalink
fix(rpc): Use pydantic's AliasChoice
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Feb 6, 2025
1 parent 50436ae commit 95e2acb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/ethereum_test_rpc/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum_test_types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 95e2acb

Please sign in to comment.