Skip to content

Commit

Permalink
fix: issue when using hex-str for accessList storage keys (ApeWorX#1882)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jan 25, 2024
1 parent d5bdd68 commit 6702f2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/ape_ethereum/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ape.contracts import ContractEvent
from ape.exceptions import OutOfGasError, SignatureError, TransactionError
from ape.logging import logger
from ape.types import CallTreeNode, ContractLog, ContractLogContainer, SourceTraceback
from ape.types import AddressType, CallTreeNode, ContractLog, ContractLogContainer, SourceTraceback
from ape.utils import ZERO_ADDRESS


Expand Down Expand Up @@ -50,10 +50,8 @@ class TransactionType(Enum):


class AccessList(BaseModel):
address: str
storage_keys: List[Union[HexBytes, bytes, str, int]] = Field(
default_factory=list, alias="storageKeys"
)
address: AddressType
storage_keys: List[HexBytes] = Field(default_factory=list, alias="storageKeys")


class BaseTransaction(TransactionAPI):
Expand Down
36 changes: 36 additions & 0 deletions tests/functional/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ape.exceptions import SignatureError
from ape_ethereum.transactions import (
AccessList,
AccessListTransaction,
DynamicFeeTransaction,
StaticFeeTransaction,
TransactionType,
Expand Down Expand Up @@ -260,6 +261,23 @@ def test_model_dump_excludes_none_values():
assert "value" not in actual


def test_model_dump_access_list():
# Data directly from eth_createAccessList RPC
access_list = [
{
"address": "0x7ef8e99980da5bcedcf7c10f41e55f759f6a174b",
"storageKeys": [
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000002",
],
}
]
txn = AccessListTransaction(access_list=access_list)
actual = txn.model_dump(exclude_none=True, by_alias=True)
assert actual is not None


def test_str_when_data_is_bytes(ethereum):
"""
Tests against a condition that would cause transactions to
Expand Down Expand Up @@ -322,3 +340,21 @@ def test_serialize_transaction_missing_signature_and_sender(ethereum):
txn = ethereum.create_transaction(data=HexBytes("0x123"))
with pytest.raises(SignatureError, match=expected):
txn.serialize_transaction()


class TestAccessList:
@pytest.mark.parametrize(
"address",
(
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
HexBytes("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"),
),
)
def test_address(self, address):
actual = AccessList(address=address, storageKeys=[])
assert actual.address == "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"

@pytest.mark.parametrize("storage_key", (123, HexBytes(123), "0x0123"))
def test_storage_keys(self, storage_key, zero_address):
actual = AccessList(address=zero_address, storageKeys=[storage_key])
assert actual.storage_keys == [HexBytes(storage_key)]

0 comments on commit 6702f2c

Please sign in to comment.