Skip to content

Commit

Permalink
fix: issue with camelCase contract types
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Nov 2, 2023
1 parent 5908929 commit 915cfce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 8 additions & 2 deletions ethpm_types/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,15 @@ def check_both_version_and_name(cls, values):
@root_validator
def check_contract_source_ids(cls, values):
sources = values.get("sources", {}) or {}
contract_types = values.get("contract_types", {}) or {}
if "contractTypes" in values:
values["contract_types"] = values.pop("contractTypes")
# Have to call this because otherwise validator is missed
# and Pydantic won't allow alias as trigger.
cls.add_name_to_contract_type(values["contract_types"])

contract_types = values.get("contractTypes") or {}
for alias in contract_types:
source_id = values["contract_types"][alias].source_id
source_id = contract_types[alias].source_id
if source_id and (source_id not in sources):
raise ValueError(f"'{source_id}' missing from `sources`.")

Expand Down
19 changes: 18 additions & 1 deletion tests/test_package_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,27 @@ def test_update_compilers():
assert len(manifest.compilers) == 2


def test_none_contract_types():
def test_contract_types():
"""
Tests against a bug where validators would fail because
they tried iterating None.
"""
manifest = PackageManifest(contractTypes=None)
assert manifest.contract_types is None

# Even though snakeCase is the documented way,
# Ape tools had been using snake_case in some instances,
# so we must continue ensuring both work.
manifest = PackageManifest(contract_types=None)
assert manifest.contract_types is None

contract_types = {
"foobar": ContractType(contractName="foobar", abi=[]),
"testtest": ContractType(contractName="testtest", abi=[]),
}

manifest = PackageManifest(contractTypes=contract_types)
assert manifest.contract_types == contract_types
#
# manifest = PackageManifest(contract_types=contract_types)
# assert manifest.contract_types == contract_types

0 comments on commit 915cfce

Please sign in to comment.