diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 40506046d7..8e0309516c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 diff --git a/src/ethereum_test_tools/common/types.py b/src/ethereum_test_tools/common/types.py index 344b9be37e..6a106d3ce6 100644 --- a/src/ethereum_test_tools/common/types.py +++ b/src/ethereum_test_tools/common/types.py @@ -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. @@ -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) diff --git a/src/ethereum_test_tools/tests/test_types.py b/src/ethereum_test_tools/tests/test_types.py index d725354d8d..d2b684bd8d 100644 --- a/src/ethereum_test_tools/tests/test_types.py +++ b/src/ethereum_test_tools/tests/test_types.py @@ -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