Skip to content

Commit

Permalink
fix(fw): fix Address padding options (#1113)
Browse files Browse the repository at this point in the history
Co-authored-by: danceratopz <[email protected]>
  • Loading branch information
chfast and danceratopz authored Jan 23, 2025
1 parent 4412007 commit 4891ac7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ethereum_test_base_types/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,14 @@ class Address(FixedSizeBytes[20]): # type: ignore
label: str | None = None

def __new__(
cls, input_bytes: "FixedSizeBytesConvertible | Address", *, label: str | None = None
cls,
input_bytes: "FixedSizeBytesConvertible | Address",
*args,
label: str | None = None,
**kwargs,
):
"""Create a new Address object with an optional label."""
instance = super(Address, cls).__new__(cls, input_bytes)
instance = super(Address, cls).__new__(cls, input_bytes, *args, **kwargs)
if isinstance(input_bytes, Address) and label is None:
instance.label = input_bytes.label
else:
Expand Down
20 changes: 20 additions & 0 deletions src/ethereum_test_base_types/tests/test_base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ def test_comparisons(a: Any, b: Any, equal: bool):
assert not a == b


def test_hash_padding():
"""Test Hash objects are padded correctly."""
assert Hash(b"\x01", left_padding=True) == (
"0x0000000000000000000000000000000000000000000000000000000000000001"
)
assert Hash(b"\x02", right_padding=True) == (
"0x0200000000000000000000000000000000000000000000000000000000000000"
)


def test_address_padding():
"""Test that addresses are padded correctly."""
assert Address(b"\x01", left_padding=True) == Address(
"0x0000000000000000000000000000000000000001"
)
assert Address(b"\x80", right_padding=True) == Address(
"0x8000000000000000000000000000000000000000"
)


@pytest.mark.parametrize(
"s, expected",
[
Expand Down

0 comments on commit 4891ac7

Please sign in to comment.