Skip to content

Commit 4891ac7

Browse files
chfastdanceratopz
andauthored
fix(fw): fix Address padding options (#1113)
Co-authored-by: danceratopz <[email protected]>
1 parent 4412007 commit 4891ac7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/ethereum_test_base_types/base_types.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,14 @@ class Address(FixedSizeBytes[20]): # type: ignore
298298
label: str | None = None
299299

300300
def __new__(
301-
cls, input_bytes: "FixedSizeBytesConvertible | Address", *, label: str | None = None
301+
cls,
302+
input_bytes: "FixedSizeBytesConvertible | Address",
303+
*args,
304+
label: str | None = None,
305+
**kwargs,
302306
):
303307
"""Create a new Address object with an optional label."""
304-
instance = super(Address, cls).__new__(cls, input_bytes)
308+
instance = super(Address, cls).__new__(cls, input_bytes, *args, **kwargs)
305309
if isinstance(input_bytes, Address) and label is None:
306310
instance.label = input_bytes.label
307311
else:

src/ethereum_test_base_types/tests/test_base_types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ def test_comparisons(a: Any, b: Any, equal: bool):
135135
assert not a == b
136136

137137

138+
def test_hash_padding():
139+
"""Test Hash objects are padded correctly."""
140+
assert Hash(b"\x01", left_padding=True) == (
141+
"0x0000000000000000000000000000000000000000000000000000000000000001"
142+
)
143+
assert Hash(b"\x02", right_padding=True) == (
144+
"0x0200000000000000000000000000000000000000000000000000000000000000"
145+
)
146+
147+
148+
def test_address_padding():
149+
"""Test that addresses are padded correctly."""
150+
assert Address(b"\x01", left_padding=True) == Address(
151+
"0x0000000000000000000000000000000000000001"
152+
)
153+
assert Address(b"\x80", right_padding=True) == Address(
154+
"0x8000000000000000000000000000000000000000"
155+
)
156+
157+
138158
@pytest.mark.parametrize(
139159
"s, expected",
140160
[

0 commit comments

Comments
 (0)