Skip to content

Commit

Permalink
tools(fix): Fix Storage iterator (ethereum#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz authored Jan 5, 2024
1 parent 5ce00e7 commit f71a615
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- 🔀 Rename test fixtures names to match the corresponding pytest node ID as generated using `fill` ([#342](https://github.com/ethereum/execution-spec-tests/pull/342)).
- 💥 Replace "=" with "_" in pytest node ids and test fixture names ([#342](https://github.com/ethereum/execution-spec-tests/pull/342)).
- ✨ Fork objects used to write tests can now be compared using the `>`, `>=`, `<`, `<=` operators, to check for a fork being newer than, newer than or equal, older than, older than or equal, respectively when compared against other fork ([#367](https://github.com/ethereum/execution-spec-tests/pull/367))
- 🐞 Storage type iterator is now fixed ([#369](https://github.com/ethereum/execution-spec-tests/pull/369))

### 🔧 EVM Tools

Expand Down
6 changes: 5 additions & 1 deletion src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def key_value_to_string(value: int) -> str:
hex_str = "0" + hex_str
return "0x" + hex_str

def __init__(self, input: StorageDictType = {}, start_slot: int = 0):
def __init__(self, input: StorageDictType | "Storage" = {}, start_slot: int = 0):
"""
Initializes the storage using a given mapping which can have
keys and values either as string or int.
Expand All @@ -420,6 +420,10 @@ def __len__(self) -> int:
"""Returns number of elements in the storage"""
return len(self.data)

def __iter__(self) -> Iterator[int]:
"""Returns iterator of the storage"""
return iter(self.data)

def __contains__(self, key: str | int | bytes) -> bool:
"""Checks for an item in the storage"""
key = Storage.parse_key_value(key)
Expand Down
4 changes: 4 additions & 0 deletions src/ethereum_test_tools/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def test_storage():
assert 10 in s.data
assert s.data[10] == 10

iter_s = iter(Storage({10: 20, "11": "21"}))
assert next(iter_s) == 10
assert next(iter_s) == 11

s["10"] = "0x10"
s["0x10"] = "10"
assert s.data[10] == 16
Expand Down

0 comments on commit f71a615

Please sign in to comment.