-
-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimentally add support for transient storage via a new `transient` keyword, which works like `immutable` or `constant`, ex.: ```vyper my_transient_variable: transient(uint256) ``` this feature is considered experimental until py-evm adds support (giving us the ability to actually test it). so this commit leaves the default evm version as "shanghai" for now. it blocks the feature on pre-cancun EVM versions, so users can't use it by accident - the only way to use it is to explicitly enable it via `--evm-version=cancun`.
- Loading branch information
1 parent
5b9bca2
commit ed0a654
Showing
16 changed files
with
118 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,61 @@ | ||
import pytest | ||
|
||
from vyper.compiler import compile_code | ||
from vyper.evm.opcodes import EVM_VERSIONS | ||
from vyper.exceptions import StructureException | ||
|
||
post_cancun = {k: v for k, v in EVM_VERSIONS.items() if v >= EVM_VERSIONS["cancun"]} | ||
|
||
|
||
@pytest.mark.parametrize("evm_version", list(EVM_VERSIONS.keys())) | ||
def test_transient_blocked(evm_version): | ||
# test transient is blocked on pre-cancun and compiles post-cancun | ||
code = """ | ||
my_map: transient(HashMap[address, uint256]) | ||
""" | ||
if EVM_VERSIONS[evm_version] >= EVM_VERSIONS["cancun"]: | ||
assert compile_code(code, evm_version=evm_version) is not None | ||
else: | ||
with pytest.raises(StructureException): | ||
compile_code(code, evm_version=evm_version) | ||
|
||
|
||
@pytest.mark.parametrize("evm_version", list(post_cancun.keys())) | ||
def test_transient_compiles(evm_version): | ||
# test transient keyword at least generates TLOAD/TSTORE opcodes | ||
getter_code = """ | ||
my_map: public(transient(HashMap[address, uint256])) | ||
""" | ||
t = compile_code(getter_code, evm_version=evm_version, output_formats=["opcodes_runtime"]) | ||
t = t["opcodes_runtime"].split(" ") | ||
|
||
assert "TLOAD" in t | ||
assert "TSTORE" not in t | ||
|
||
setter_code = """ | ||
my_map: transient(HashMap[address, uint256]) | ||
@external | ||
def setter(k: address, v: uint256): | ||
self.my_map[k] = v | ||
""" | ||
t = compile_code(setter_code, evm_version=evm_version, output_formats=["opcodes_runtime"]) | ||
t = t["opcodes_runtime"].split(" ") | ||
|
||
assert "TLOAD" not in t | ||
assert "TSTORE" in t | ||
|
||
getter_setter_code = """ | ||
my_map: public(transient(HashMap[address, uint256])) | ||
@external | ||
def setter(k: address, v: uint256): | ||
self.my_map[k] = v | ||
""" | ||
t = compile_code( | ||
getter_setter_code, evm_version=evm_version, output_formats=["opcodes_runtime"] | ||
) | ||
t = t["opcodes_runtime"].split(" ") | ||
|
||
assert "TLOAD" in t | ||
assert "TSTORE" in t |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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