-
-
Notifications
You must be signed in to change notification settings - Fork 870
feat: Storage Layout Overrides #2593
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
f93625a
feat: Add --storage-layout-file flag to compiler
abdullathedruid 5b652eb
feat: get storage layouts from file
abdullathedruid 3306bcc
fix: use contractpath as key for storage layout
abdullathedruid d12d75e
feat: pass overrides to data positions function
abdullathedruid 9ca5b00
feat: use storage file for overrides
abdullathedruid ea4e4cc
feat: Add some basic collision checking
abdullathedruid 8f428c5
doc: Add some comments to data_position
abdullathedruid f8bf5b5
test: add simple test
abdullathedruid c776707
fix: reused re-entrant key should not collide
abdullathedruid a87180b
fix: test had accidental collision
abdullathedruid 1722bd1
test: add some failing cases
abdullathedruid 90a543d
linter: lint
abdullathedruid 9777db9
lint: fixed
abdullathedruid a1223f1
fix: return types
abdullathedruid d17c701
fix: zip ensures both iterators same length
abdullathedruid c3cd769
fix: storagecollision as member variable
abdullathedruid d017197
refactor: remove StorageLayoutForContracts type
abdullathedruid 39b6e0f
refactor: Update StorageAllocator to use set
abdullathedruid e6f2f93
refactor:adjust functions to get slot availability
abdullathedruid 5337b04
refactor: reuse override object in test
abdullathedruid 998b7a0
fix: rename private functions
abdullathedruid 907505b
refactor: improve clarity
abdullathedruid 1d5ecce
fix: forgot to rename functions
abdullathedruid 004f111
feat: ensure storage slot in bounds
abdullathedruid 9250353
refactor: raise StorageLayoutException
abdullathedruid 5c53b3c
test: update tests to check new exception
abdullathedruid 81dfac2
feat: add node to storagelayoutexception
abdullathedruid 770b1f4
feat: update error message
abdullathedruid f205961
fix: keep node in error
abdullathedruid 02b1b20
Merge branch 'master' into abdullathedruid/master
charles-cooper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import pytest | ||
|
|
||
| from vyper.compiler import compile_code | ||
| from vyper.exceptions import StorageLayoutException | ||
|
|
||
|
|
||
| def test_storage_layout_overrides(): | ||
| code = """ | ||
| a: uint256 | ||
| b: uint256""" | ||
|
|
||
| storage_layout_overrides = { | ||
| "a": {"type": "uint256", "location": "storage", "slot": 1}, | ||
| "b": {"type": "uint256", "location": "storage", "slot": 0}, | ||
| } | ||
|
|
||
| out = compile_code( | ||
| code, output_formats=["layout"], storage_layout_override=storage_layout_overrides | ||
| ) | ||
|
|
||
| assert out["layout"] == storage_layout_overrides | ||
|
|
||
|
|
||
| def test_storage_layout_for_more_complex(): | ||
| code = """ | ||
| foo: HashMap[address, uint256] | ||
|
|
||
| @external | ||
| @nonreentrant("foo") | ||
| def public_foo1(): | ||
| pass | ||
|
|
||
| @external | ||
| @nonreentrant("foo") | ||
| def public_foo2(): | ||
| pass | ||
|
|
||
|
|
||
| @internal | ||
| @nonreentrant("bar") | ||
| def _bar(): | ||
| pass | ||
|
|
||
| # mix it up a little | ||
| baz: Bytes[65] | ||
| bar: uint256 | ||
|
|
||
| @external | ||
| @nonreentrant("bar") | ||
| def public_bar(): | ||
| pass | ||
|
|
||
| @external | ||
| @nonreentrant("foo") | ||
| def public_foo3(): | ||
| pass | ||
| """ | ||
|
|
||
| storage_layout_override = { | ||
| "nonreentrant.foo": {"type": "nonreentrant lock", "location": "storage", "slot": 8}, | ||
| "nonreentrant.bar": {"type": "nonreentrant lock", "location": "storage", "slot": 7}, | ||
| "foo": { | ||
| "type": "HashMap[address, uint256]", | ||
| "location": "storage", | ||
| "slot": 1, | ||
| }, | ||
| "baz": {"type": "Bytes[65]", "location": "storage", "slot": 2}, | ||
| "bar": {"type": "uint256", "location": "storage", "slot": 6}, | ||
| } | ||
|
|
||
| out = compile_code( | ||
| code, output_formats=["layout"], storage_layout_override=storage_layout_override | ||
| ) | ||
|
|
||
| assert out["layout"] == storage_layout_override | ||
|
|
||
|
|
||
| def test_simple_collision(): | ||
| code = """ | ||
| name: public(String[64]) | ||
| symbol: public(String[32])""" | ||
|
|
||
| storage_layout_override = { | ||
| "name": {"location": "storage", "slot": 0, "type": "String[64]"}, | ||
| "symbol": {"location": "storage", "slot": 1, "type": "String[32]"}, | ||
| } | ||
|
|
||
| with pytest.raises( | ||
| StorageLayoutException, | ||
| match="Storage collision! Tried to assign 'symbol' to slot 1" | ||
| " but it has already been reserved by 'name'", | ||
| ): | ||
| compile_code( | ||
| code, output_formats=["layout"], storage_layout_override=storage_layout_override | ||
| ) | ||
|
|
||
|
|
||
| def test_incomplete_overrides(): | ||
| code = """ | ||
| name: public(String[64]) | ||
| symbol: public(String[32])""" | ||
|
|
||
| storage_layout_override = { | ||
| "name": {"location": "storage", "slot": 0, "type": "String[64]"}, | ||
| } | ||
|
|
||
| with pytest.raises( | ||
| StorageLayoutException, | ||
| match="Could not find storage_slot for symbol. " | ||
| "Have you used the correct storage layout file?", | ||
| ): | ||
| compile_code( | ||
| code, output_formats=["layout"], storage_layout_override=storage_layout_override | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.