Skip to content

Commit

Permalink
ABI serialization not symmetric #23 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireGuerreGiordano authored Sep 25, 2024
1 parent 67bef4d commit a43f4f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/erc7730/model/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class AbiJsonSchemaItem(BaseLibraryModel):
outputs: Optional[list[AbiParameter]]
stateMutability: Optional[StateMutability] = None
type: Type
constant: Optional[bool] = None
payable: Optional[bool] = None
constant: bool | None = None
payable: bool | None = None


class AbiJsonSchema(RootModel[list[AbiJsonSchemaItem]]):
Expand Down
12 changes: 12 additions & 0 deletions tests/src/erc7730/common/test_datamodel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
from erc7730.common.json import read_json_with_includes
from erc7730.common.pydantic import json_file_from_model
from erc7730.model.context import AbiJsonSchemaItem
from erc7730.model.erc7730_descriptor import ERC7730Descriptor
import pytest
import glob
Expand All @@ -26,3 +27,14 @@ def test_from_erc7730(file: str) -> None:
pytest.fail(f"Invalid schema for serialized data from {file}: {ex}")
print_diff(json_from_model, original_dict_with_includes)
assert json_from_model == original_dict_with_includes


abi_item_json_str = '{"name":"approve","inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"outputs":[{"name":"","type":"bool"}],"type":"function"}'


def test_23_unset_attributes_must_not_be_serialized_as_set() -> None:
abi_item_json = json.loads(abi_item_json_str)
abi_item = AbiJsonSchemaItem.model_validate(abi_item_json, strict=False)
abi_item_json_str_deserialized = json_file_from_model(AbiJsonSchemaItem, abi_item)
print_diff(abi_item_json_str, abi_item_json_str_deserialized)
assert abi_item_json_str == abi_item_json_str_deserialized

0 comments on commit a43f4f5

Please sign in to comment.