Skip to content

Commit

Permalink
test: add more complex test
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 3, 2024
1 parent c997f94 commit d829f76
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_hex.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

import pytest
from eth_utils import to_hex
from hexbytes import HexBytes as BaseHexBytes
Expand Down Expand Up @@ -69,6 +71,22 @@ def test_hexbytes_model_dump_json(bytes32str):
assert actual == expected


def test_hexbytes_used_in_dict_any(bytes32str):
class MyModel(BaseModel):
my_map: dict[str, Any] = {}

data = {"my_map": {"some_bytes": [bytes32str]}}
model = MyModel.model_validate(data)

# NOTE: There was a concern with using this type in Any.
actual = model.model_dump_json()
expected = (
'{"my_map":{"some_bytes":'
'["0x9B70BD98CCB5B6434C2EAD14D68D15F392435A06FF469F8D1F8CF38B2AE0B0E2"]}}'
)
assert actual == expected


@pytest.mark.parametrize("value", ("0xa", 10, HexBytes(10)))
def test_hexstr(value):
actual = StrModel(value=value)
Expand Down

0 comments on commit d829f76

Please sign in to comment.