Skip to content

Commit

Permalink
test(fw): add empty account tests (ethereum#490)
Browse files Browse the repository at this point in the history
Co-authored-by: danceratopz <[email protected]>
  • Loading branch information
marioevz and danceratopz authored Apr 10, 2024
1 parent b7499ed commit 2cd20f1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
51 changes: 51 additions & 0 deletions src/ethereum_test_tools/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
[
Expand Down

0 comments on commit 2cd20f1

Please sign in to comment.