Skip to content

Commit 664d75d

Browse files
raxhvlCarsons-Eels
authored andcommitted
✨ feat: Align TransactionHashByResponse to Transaction (ethereum#1755)
* ✨ feat: Align TransactionHashByResponse to Transaction * ✨ feat: Update provider reference to tx model --------- Co-authored-by: raxhvl <raxhvl@users.noreply.github.com>
1 parent c28aa18 commit 664d75d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/cli/gentest/test_context_providers.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from pydantic import BaseModel
2020

2121
from ethereum_test_base_types import Account, Hash
22+
from ethereum_test_rpc.types import TransactionByHashResponse
2223
from ethereum_test_tools import Environment, Transaction
2324

2425
from .request_manager import RPCRequest
@@ -39,7 +40,7 @@ class StateTestProvider(Provider):
3940

4041
transaction_hash: Hash
4142
block: Optional[Environment] = None
42-
transaction: Optional[Transaction] = None
43+
transaction_response: Optional[TransactionByHashResponse] = None
4344
state: Optional[Dict[str, Dict]] = None
4445

4546
def _make_rpc_calls(self):
@@ -48,13 +49,13 @@ def _make_rpc_calls(self):
4849
f"Perform tx request: eth_get_transaction_by_hash({self.transaction_hash})",
4950
file=stderr,
5051
)
51-
self.transaction = request.eth_get_transaction_by_hash(self.transaction_hash)
52+
self.transaction_response = request.eth_get_transaction_by_hash(self.transaction_hash)
5253

5354
print("Perform debug_trace_call", file=stderr)
54-
self.state = request.debug_trace_call(self.transaction)
55+
self.state = request.debug_trace_call(self.transaction_response)
5556

5657
print("Perform eth_get_block_by_number", file=stderr)
57-
self.block = request.eth_get_block_by_number(self.transaction.block_number)
58+
self.block = request.eth_get_block_by_number(self.transaction_response.block_number)
5859

5960
print("Generate py test", file=stderr)
6061

@@ -64,22 +65,23 @@ def _get_environment(self) -> Environment:
6465

6566
def _get_pre_state(self) -> Dict[str, Account]:
6667
assert self.state is not None
67-
assert self.transaction is not None
68+
assert self.transaction_response is not None
6869

6970
pre_state: Dict[str, Account] = {}
7071
for address, account_data in self.state.items():
7172
# TODO: Check if this is required. Ideally,
7273
# the pre-state tracer should have the correct
7374
# values without requiring any additional modifications.
74-
if address == self.transaction.sender:
75-
account_data["nonce"] = self.transaction.nonce
75+
if address == self.transaction_response.sender:
76+
account_data["nonce"] = self.transaction_response.nonce
7677

7778
pre_state[address] = Account(**account_data)
7879
return pre_state
7980

8081
def _get_transaction(self) -> Transaction:
81-
assert self.transaction is not None
82-
return self.transaction
82+
assert self.transaction_response is not None
83+
# Validate the RPC TransactionHashResponse and convert it to a Transaction instance.
84+
return Transaction.model_validate(self.transaction_response.model_dump())
8385

8486
def get_context(self) -> Dict[str, Any]:
8587
"""

src/ethereum_test_rpc/types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
UndefinedException,
2323
)
2424
from ethereum_test_fixtures.blockchain import FixtureExecutionPayload
25-
from ethereum_test_types import Transaction, Withdrawal
25+
from ethereum_test_types import EOA, Transaction, Withdrawal
2626

2727

2828
class JSONRPCError(Exception):
@@ -49,8 +49,10 @@ class TransactionByHashResponse(Transaction):
4949

5050
gas_limit: HexNumber = Field(HexNumber(21_000), alias="gas")
5151
transaction_hash: Hash = Field(..., alias="hash")
52-
from_address: Address = Field(..., alias="from")
53-
to_address: Address | None = Field(..., alias="to")
52+
sender: EOA | None = Field(None, alias="from")
53+
54+
# The to field can have different names in different clients, so we use AliasChoices.
55+
to: Address | None = Field(..., validation_alias=AliasChoices("to_address", "to", "toAddress"))
5456

5557
v: HexNumber = Field(0, validation_alias=AliasChoices("v", "yParity")) # type: ignore
5658

0 commit comments

Comments
 (0)