From 2cd20f1b629f8646c7b2c61a095884a35a2ffa0b Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Wed, 10 Apr 2024 00:00:29 -0600 Subject: [PATCH] test(fw): add empty account tests (#490) Co-authored-by: danceratopz --- src/ethereum_test_tools/common/types.py | 2 +- src/ethereum_test_tools/tests/test_types.py | 51 +++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/ethereum_test_tools/common/types.py b/src/ethereum_test_tools/common/types.py index b2f7bd4525..5fcbedf879 100644 --- a/src/ethereum_test_tools/common/types.py +++ b/src/ethereum_test_tools/common/types.py @@ -243,7 +243,7 @@ def __ne__(self, other) -> bool: def __bool__(self) -> bool: """Returns True if the storage is not empty""" - return any(v != 0 for _, v in self.root.items()) + return any(v for v in self.root.values()) def keys(self) -> set[StorageKeyValueType]: """Returns the keys of the storage""" diff --git a/src/ethereum_test_tools/tests/test_types.py b/src/ethereum_test_tools/tests/test_types.py index 7e78e41e34..8d76fc5765 100644 --- a/src/ethereum_test_tools/tests/test_types.py +++ b/src/ethereum_test_tools/tests/test_types.py @@ -99,6 +99,57 @@ def test_storage(): } +@pytest.mark.parametrize( + ["account"], + [ + pytest.param( + Account(), + id="no_fields", + ), + pytest.param( + Account( + nonce=0, + ), + id="zero_nonce", + ), + pytest.param( + Account( + balance=0, + ), + id="zero_balance", + ), + pytest.param( + Account( + code="", + ), + id="empty_code", + ), + pytest.param( + Account( + storage={}, + ), + id="empty_storage", + ), + pytest.param( + Account( + nonce=0, + balance=0, + code="", + storage={ + 1: 0, + }, + ), + id="only_zero_storage_values", + ), + ], +) +def test_empty_accounts(account: Account): + """ + Test `ethereum_test.types.account` parsing. + """ + assert not bool(account) + + @pytest.mark.parametrize( ["account", "alloc_dict", "should_pass"], [