-
-
Notifications
You must be signed in to change notification settings - Fork 865
feat[test]: add code writing DSL to test suite #4691
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
base: master
Are you sure you want to change the base?
feat[test]: add code writing DSL to test suite #4691
Conversation
this makes it easier to programmatically generate vyper source code, which will make it easier to write parametrized tests in the test suite.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4691 +/- ##
==========================================
+ Coverage 92.99% 93.00% +0.01%
==========================================
Files 131 131
Lines 19094 19095 +1
Branches 3324 3324
==========================================
+ Hits 17757 17760 +3
+ Misses 899 898 -1
+ Partials 438 437 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
"""Add a transient storage variable.""" | ||
name, typ = self._parse_declaration(declaration) | ||
self._transient_vars.append(f"{name}: transient({typ})") | ||
return VarRef(name, typ, "transient", "public") |
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.
vars will be public by default?
typ = parts[1][type_start:type_end].strip() | ||
|
||
self._constants.append(declaration) | ||
return VarRef(name, typ, "constant", 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.
why does the visibility for constants differ?
def immutable(self, declaration: str) -> VarRef: | ||
"""Add an immutable variable.""" | ||
name, typ = self._parse_declaration(declaration) | ||
self._immutables.append(f"{name}: immutable({typ})") |
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 immutables we don't have to declare with "immutable" but for constants "constant" is required?
the model seems to be missing features like pragmas, interfaces, module-related machinery (imports, initialization,..) |
looks reasonable overall, for parametric tests it could be an improvement over status quo for simple tests, it's a bit hard to read code = """
owner: address
@deploy
def __init__(initial_count: uint256):
self.count = initial_count
self.owner = msg.sender
@external
def increment():
self.count += 1
@external
@view
def get_count() -> uint256:
return self.count
"""" vs model = CodeModel()
count = model.storage_var("count: uint256")
owner = model.storage_var("owner: address")
code = (
model.function("__init__(initial_count: uint256)")
.deploy()
.body(
f"""
{count} = initial_count
{owner} = msg.sender
"""
)
.done()
.function("increment()")
.external()
.body(f"{count} += 1")
.done()
.function("get_count() -> uint256")
.external()
.view()
.body(f"return {count}")
.done()
.build()
) |
What I did
this makes it easier to programmatically generate vyper source code, which will make it easier to write parametrized tests in the test suite.
How I did it
How to verify it
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture