Skip to content

Commit

Permalink
Handle case when struct abis don't match up exactly. Version bump to …
Browse files Browse the repository at this point in the history
…v0.0.46 (#146)
  • Loading branch information
slundqui authored Oct 23, 2024
1 parent ab3d0bc commit 54bca18
Show file tree
Hide file tree
Showing 72 changed files with 93 additions and 87 deletions.
2 changes: 1 addition & 1 deletion example/types/Example/ExampleContract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the Example contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
2 changes: 1 addition & 1 deletion example/types/Example/ExampleTypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataclasses for all structs in the Example contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# super() call methods are generic, while our version adds values & types
Expand Down
2 changes: 1 addition & 1 deletion example/types/Example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion example/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion example/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
22 changes: 15 additions & 7 deletions pypechain/render/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,22 @@ def _add_structs(contract_infos: dict[str, ContractInfo], structs: StructInfo |
contract_name = struct.contract_name
info = contract_infos.get(contract_name)
if info:
# Sanity check, if this structure already exists, we compare the two and ensure
# it's the same structure
# If this structure already exists, we merge the two, ensuring
# that fields that exist in both are the same.
if struct.name in info.structs:
assert info.structs[struct.name] == struct, (
"Existing structure for contract "
f"{struct.contract_name}:{struct.name} {info.structs[struct.name]} "
f"does not match defined structure {struct}."
)
existing_struct = info.structs[struct.name]
assert existing_struct.name == struct.name
assert existing_struct.contract_name == struct.contract_name
for struct_key, struct_value in struct.values.items():
if struct_key in existing_struct.values:
assert existing_struct.values[struct_key] == struct_value, (
"Existing value for struct "
f"{struct.contract_name}.{struct.name}.{struct_key} does not match. "
f"Existing value: {existing_struct.values[struct_key]} "
f"New value: {struct_value}"
)
else:
info.structs[struct.name].values[struct_key] = struct_value
else:
info.structs[struct.name] = struct
else:
Expand Down
2 changes: 1 addition & 1 deletion pypechain/render/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def render_types_file(contract_info: ContractInfo) -> str | None:
types_files_imported = []
# Iterate through all structs and look at the contract_name of each struct value
for struct in structs:
for struct_value in struct.values:
for struct_value in struct.values.values():
# Add an import if it's a struct
if struct_value.is_struct:
if struct_value.contract_name is not None:
Expand Down
2 changes: 1 addition & 1 deletion pypechain/templates/types.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class {{event.capitalized_name}}Event(BaseEvent):
@dataclass
class {{struct.name}}:
"""{{struct.name}} struct."""
{% for struct_value in struct.values %}
{% for struct_value in struct.values.values() %}
{{struct_value.name}}: {{struct_value.python_type}}
{%- endfor %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the Contract contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/deploy_linking/types/Contract/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the MyLibrary contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/deploy_linking/types/MyLibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/deploy_linking/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/deploy_linking/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the ConstructorNoArgs contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the ConstructorWithArgs contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the ConstructorWithStructArgs contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataclasses for all structs in the ConstructorWithStructArgs contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# super() call methods are generic, while our version adds values & types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the NoConstructor contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/deployment/types/NoConstructor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/deployment/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/deployment/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
2 changes: 1 addition & 1 deletion pypechain/test/errors/types/Errors/ErrorsContract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the Errors contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/errors/types/Errors/ErrorsTypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataclasses for all structs in the Errors contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# super() call methods are generic, while our version adds values & types
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/errors/types/Errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/errors/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/errors/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
2 changes: 1 addition & 1 deletion pypechain/test/events/types/Events/EventsContract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the Events contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/events/types/Events/EventsTypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataclasses for all structs in the Events contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# super() call methods are generic, while our version adds values & types
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/events/types/Events/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/events/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/events/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the OverloadedMethods contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataclasses for all structs in the OverloadedMethods contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# super() call methods are generic, while our version adds values & types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/overloading/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/overloading/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the ReturnTypes contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataclasses for all structs in the ReturnTypes contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# super() call methods are generic, while our version adds values & types
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/return_types/types/ReturnTypes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/return_types/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/return_types/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A web3.py Contract class for the Transact contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# contracts have PascalCase names
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataclasses for all structs in the Transact contract.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# super() call methods are generic, while our version adds values & types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/sign_and_transact/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Export all types from generated files.
DO NOT EDIT. This file was generated by pypechain v0.0.44.
DO NOT EDIT. This file was generated by pypechain v0.0.46.
See documentation at https://github.com/delvtech/pypechain """

# The module name reflects that of the solidity contract,
Expand Down
2 changes: 1 addition & 1 deletion pypechain/test/sign_and_transact/types/pypechain.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pypechain == 0.0.44
pypechain == 0.0.46
Loading

0 comments on commit 54bca18

Please sign in to comment.