Skip to content
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 .vyz inputs #4370

Merged
merged 44 commits into from
Jan 3, 2025
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4b84b26
handle storage layout for json
tserg Nov 23, 2024
da1c476
add json test
tserg Nov 23, 2024
8154230
handle json round trip
tserg Nov 24, 2024
cdf62b7
add json round trip test
tserg Nov 24, 2024
df36dd5
fix layout override test
tserg Nov 24, 2024
c893919
fix layout output via json
tserg Nov 24, 2024
2808db6
Merge branch 'master' of https://github.com/vyperlang/vyper into tool…
tserg Nov 24, 2024
08f0396
include transient storage overrides
tserg Nov 24, 2024
1f24a50
handle layout override for zip
tserg Nov 24, 2024
fda0e1e
Revert "include transient storage overrides"
tserg Nov 24, 2024
6e184cc
more reverts
tserg Nov 24, 2024
a3c18d7
fix tests
tserg Nov 24, 2024
73f650e
fix test
tserg Nov 24, 2024
c552876
check for storage layout in zip
tserg Nov 24, 2024
a16d67e
fix more tests
tserg Nov 24, 2024
2f59780
apply bts suggestions
tserg Nov 26, 2024
a93c0b9
pass storage layout
tserg Nov 26, 2024
9def387
Merge branch 'master' of https://github.com/vyperlang/vyper into tool…
tserg Nov 27, 2024
05f0786
apply bts suggestion
tserg Nov 27, 2024
5e8122c
add layout to dict for tests
tserg Nov 27, 2024
7aac6f3
fix solc json round trip test
tserg Nov 27, 2024
49fdd97
remove content key
tserg Nov 27, 2024
8d15e39
fix typo in docs
tserg Nov 27, 2024
c8f42e1
update docs
tserg Nov 27, 2024
4036b67
undo passing down of storage layout
tserg Dec 10, 2024
43f5643
apply cc suggestion on refactoring integrity hash
tserg Dec 10, 2024
49986e5
remove dup test
tserg Dec 10, 2024
42eb3e9
Merge branch 'master' of https://github.com/vyperlang/vyper into tool…
tserg Dec 10, 2024
58c3064
fix integrity sum check and small refactor
charles-cooper Dec 10, 2024
e00be88
add tests
tserg Dec 11, 2024
eea76e2
refactor tests
tserg Dec 12, 2024
848ea34
add round trip layout tests
tserg Dec 12, 2024
5d3c946
change to slot 5
tserg Dec 12, 2024
4183a23
add json layout assertion
tserg Dec 12, 2024
2cdff96
make layout output in json not a string
charles-cooper Dec 13, 2024
bd3af72
fix a test
charles-cooper Dec 13, 2024
9fbe4ba
add unknown path test
tserg Dec 16, 2024
196bbc8
fix test
tserg Dec 16, 2024
5018c5f
Merge branch 'master' of https://github.com/vyperlang/vyper into tool…
tserg Dec 16, 2024
b693b5c
fix storage layout slot
tserg Dec 16, 2024
f640b3e
add multiple layouts for json input
tserg Dec 18, 2024
7265a43
Merge branch 'master' of https://github.com/vyperlang/vyper into tool…
tserg Dec 18, 2024
a6786bc
Merge branch 'master' of https://github.com/vyperlang/vyper into tool…
tserg Dec 31, 2024
d465568
fix merge conflict
tserg Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests
tserg committed Nov 24, 2024
commit a3c18d7c569767b58ad6ce315b260700c71588d4
27 changes: 27 additions & 0 deletions tests/unit/cli/storage_layout/test_storage_layout_overrides.py
Original file line number Diff line number Diff line change
@@ -55,6 +55,33 @@ def test_storage_layout_overrides_json():
)


def test_storage_layout_overrides_output():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a 1:1 copy of test_storage_layout_overrides_json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops yes, it looks like a dup. I will delete this.

code = """
a: uint256
b: uint256"""

storage_layout_overrides = {
"a": {"type": "uint256", "slot": 1, "n_slots": 1},
"b": {"type": "uint256", "slot": 0, "n_slots": 1},
}

input_json = {
"language": "Vyper",
"sources": {"contracts/foo.vy": {"content": code}},
"storage_layout_overrides": {
"contracts/foo.vy": {"content": {"storage_layout": storage_layout_overrides}}
},
"settings": {"outputSelection": {"*": ["*"]}},
}

out = compile_code(
code, output_formats=["layout"], storage_layout_override=storage_layout_overrides
)
assert compile_json(input_json)["contracts"]["contracts/foo.vy"]["foo"]["layout"] == json.dumps(
out["layout"]
)


def test_storage_layout_for_more_complex():
code = """
foo: HashMap[address, uint256]
12 changes: 5 additions & 7 deletions tests/unit/cli/vyper_compile/test_compile_files.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a test that storage layout is output correctly for archive + solc_json files (and ideally that it round-trips)?

Original file line number Diff line number Diff line change
@@ -310,10 +310,8 @@ def bar(x: uint256) -> uint256:
return extcall jsonabi(msg.sender).test_json(x)
"""
storage_layout_overrides = {
"storage_layout": {
"a": {"type": "uint256", "n_slots": 1, "slot": 0},
"b": {"type": "uint256", "n_slots": 1, "slot": 1},
}
"a": {"type": "uint256", "n_slots": 1, "slot": 0},
"b": {"type": "uint256", "n_slots": 1, "slot": 1},
}

tmpdir = tmp_path_factory.mktemp("fake-package")
@@ -342,10 +340,10 @@ def test_import_sys_path(input_files):


def test_archive_output(input_files):
tmpdir, _, _, _, contract_file = input_files
tmpdir, _, _, storage_layout_path, contract_file = input_files
search_paths = [".", tmpdir]

s = compile_files([contract_file], ["archive"], paths=search_paths)
s = compile_files([contract_file], ["archive"], paths=search_paths, storage_layout_paths=[storage_layout_path])
archive_bytes = s[contract_file]["archive"]

archive_path = Path("foo.zip")
@@ -355,7 +353,7 @@ def test_archive_output(input_files):
assert zipfile.is_zipfile(archive_path)

# compare compiling the two input bundles
out = compile_files([contract_file], ["integrity", "bytecode"], paths=search_paths)
out = compile_files([contract_file], ["integrity", "bytecode"], paths=search_paths, storage_layout_paths=[storage_layout_path])
out2 = compile_files([archive_path], ["integrity", "bytecode"])
assert out[contract_file] == out2[archive_path]