-
-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat[tool]: support storage layouts via json and xyz #4370
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4370 +/- ##
==========================================
- Coverage 91.27% 88.71% -2.57%
==========================================
Files 112 112
Lines 16025 16049 +24
Branches 2696 2702 +6
==========================================
- Hits 14627 14238 -389
- Misses 966 1292 +326
- Partials 432 519 +87 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
…/storage_layout_json
This reverts commit 08f0396.
@charles-cooper requesting a review before I update the docs |
storage_layout_overrides: dict[PurePath, StorageLayout] = {} | ||
|
||
for path, value in input_dict.get("storage_layout_overrides", {}).items(): | ||
if path not in input_dict["sources"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess we can have contracts which do not have corresponding override files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think that's fine, since each key in "sources" is a compilation target.
input_json = { | ||
"language": "Vyper", | ||
"sources": {"contracts/foo.vy": {"content": code}}, | ||
"storage_layout_overrides": {"contracts/foo.vy": {"content": storage_layout_overrides}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we need to hide it inside the "content" key, since it's already a dict.
storage_layout = ( | ||
json.loads(archive.read(storage_layout_path).decode("utf-8")) | ||
if storage_layout_path in archive.namelist() | ||
else None | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style:
storage_layout = ( | |
json.loads(archive.read(storage_layout_path).decode("utf-8")) | |
if storage_layout_path in archive.namelist() | |
else None | |
) | |
storage_layout = None | |
if storage_layout_path in archive.namelist(): | |
storage_layout = json.loads(archive.read(storage_layout_path).decode("utf-8")) |
@@ -347,6 +364,9 @@ def format_to_output_dict(compiler_data: dict) -> dict: | |||
if key in data: | |||
output_contracts[key] = data[key] | |||
|
|||
if data.get("layout"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if data.get("layout"): | |
if "layout" in data: |
@@ -160,6 +166,10 @@ def write(self): | |||
self.write_settings(self.compiler_data.original_settings) | |||
self.write_integrity(self.compiler_data.resolved_imports.integrity_sum) | |||
self.write_sources(self.bundle.compiler_inputs) | |||
if self.compiler_data.storage_layout_override: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use truthy unless you mean it!
if self.compiler_data.storage_layout_override: | |
if self.compiler_data.storage_layout_override is not None: |
@@ -299,6 +314,7 @@ def compile_from_input_dict( | |||
res, warnings_dict = {}, {} | |||
warnings.simplefilter("always") | |||
for contract_path in compilation_targets: | |||
storage_layout_override = storage_layout_overrides.get(contract_path, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storage_layout_override = storage_layout_overrides.get(contract_path, None) | |
storage_layout_override = storage_layout_overrides.get(contract_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks overall pretty good to me. left a few comments. @cyberthirst could you also take a look?
@@ -12,6 +12,7 @@ | |||
from vyper.compiler.settings import Settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for verification, storage layout override can (and should) affect integrity hash.
What I did
Resolves #4367
How I did it
solc_json
and archive outputs, emit the storage layout as output if it was overriden.solc_json
and archive inputs if provided.How to verify it
See tests.
Commit message
Description for the changelog
Cute Animal Picture