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[test]: add more transient storage tests #3883

Merged
merged 39 commits into from
Apr 4, 2024

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Mar 23, 2024

What I did

Follow tests for immutables and replicate where relevant.

How I did it

How to verify it

Commit message

this commit adds dedicated tests for basic operations in the transient
storage location. it mostly follows the dedicated tests for immutables
and copies them where relevant.

it also adds a `requires_evm_version` marker, which can be used in
future to test language features which should be blocked in certain EVM
versions.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.93%. Comparing base (45a225c) to head (2f1b4f4).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3883      +/-   ##
==========================================
- Coverage   90.89%   88.93%   -1.96%     
==========================================
  Files          95       95              
  Lines       14388    14388              
  Branches     3186     3186              
==========================================
- Hits        13078    12796     -282     
- Misses        908     1130     +222     
- Partials      402      462      +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@charles-cooper charles-cooper changed the title tests: add tests for transient storage tests: add more transient storage tests Mar 23, 2024
Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

this looks fine to me. to test that it's really transient, we could add additional tests that the variables are wiped between transactions.

also, we can improve on the test setup -- we don't need that branch in every single test. maybe we can add something to get_contract which expects failure for transient storage compilation exceptions?

**kwargs,
):
settings = Settings()
settings.optimize = override_opt_level or optimize

if has_transient_storage and not version_check(begin="cancun"):
Copy link
Member

Choose a reason for hiding this comment

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

instead of passing a parameter, let's either check the error message, or have a more specific exception type for transient storage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

how about this?

class UnsupportedTransientStorageException(EvmVersionException):
    """Transient storage is not supported for the active EVM ruleset."""

Copy link
Member

Choose a reason for hiding this comment

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

sure, but let's do a bit shorter: TransientStorageException(EvmVersionException)

if not version_check(begin="cancun"):
with pytest.raises(TransientStorageException):
compiler.compile_code(source_code)
return
Copy link
Member

Choose a reason for hiding this comment

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

we could even do pytest.skip so we can avoid those annoying version checks after get_contract()

Copy link
Member

Choose a reason for hiding this comment

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

the alternative might be to use something like pytest.mark.transient, and then we can modify the test collector to skip those for pre-cancun

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the alternative might be to use something like pytest.mark.transient, and then we can modify the test collector to skip those for pre-cancun

does this mean we would not check for the same contracts that pre-cancun contracts using transient throws the correct exception?

Copy link
Member

Choose a reason for hiding this comment

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

uhm, i think pytest.skip() raises some pytest internal exception. so it would check for the raise, and then skip.

@tserg tserg changed the title tests: add more transient storage tests chore[test]: add more transient storage tests Mar 23, 2024
tests/conftest.py Outdated Show resolved Hide resolved
setup.cfg Outdated
@@ -34,6 +34,7 @@ python_files = test_*.py
testpaths = tests
markers =
fuzzing: Run Hypothesis fuzz test suite (deselect with '-m "not fuzzing"')
transient: Mark tests using transient storage for differentiation based on EVM version
Copy link
Member

Choose a reason for hiding this comment

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

this seems like it needs to be updated .. not sure why tests are not failing otherwise

Copy link
Member

Choose a reason for hiding this comment

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

ah, we don't have --strict-markers enabled (see note here https://docs.pytest.org/en/latest/example/markers.html#registering-markers)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do we want to enable --strict-markers?

Copy link
Member

Choose a reason for hiding this comment

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

yes, probably, i have an open PR which touches setup.cfg though so we should wait until that is merged to avoid conflicts

x: transient(uint256)

@external
@pure
Copy link
Member

Choose a reason for hiding this comment

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

this should go under pure tests tbh

Copy link
Member

Choose a reason for hiding this comment

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

it would be good to have one for view as well

tests/conftest.py Fixed Show fixed Hide fixed
@cyberthirst
Copy link
Collaborator

Maybe let's add some tests with stateful modules?

@cyberthirst
Copy link
Collaborator

Also, I don't see HashMap being tested outside the compiles test. Can we please add some tests for it too?


c = get_contract(code)
assert c.get_my_list(*values) == list(values)
with pytest.raises(TransactionFailed):
Copy link
Member

Choose a reason for hiding this comment

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

is this on purpose instead of tx_failed()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope, I was not aware of that! I will change to tx_failed().

@charles-cooper charles-cooper changed the title chore[test]: add more transient storage tests feat[test]: add more transient storage tests Apr 4, 2024
@charles-cooper charles-cooper enabled auto-merge (squash) April 4, 2024 12:22
@charles-cooper charles-cooper merged commit f87628c into vyperlang:master Apr 4, 2024
149 checks passed
electriclilies pushed a commit to electriclilies/vyper that referenced this pull request Apr 27, 2024
this commit adds dedicated tests for basic operations in the transient
storage location. it mostly follows the dedicated tests for immutables
and copies them where relevant.

it also adds a `requires_evm_version` marker, which can be used in
future to test language features which should be blocked in certain EVM
versions.

---------

Co-authored-by: cyberthirst <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants