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

Added startPrank() and stopPrank() cheatcodes to hevm. #495

Merged
merged 2 commits into from
May 30, 2024

Conversation

alecmaly
Copy link
Contributor

Description

Added startPrank() and stopPrank() cheatcodes to hevm.

This should assist in testing smart contracts when using tools that rely on hevm such as Echidna or Medusa.

Auditors are creating complex proxy patterns to do external testing of contracts using tools such as Echidna / Medusa: How to set up Multi Actor Invariant Testing

Note Alex The Entrepenerd's response in Discord stating startPrank() would eliminate the need for this testing pattern: link to discord conversation

Testing

Tested locally with

cabal test --test-options='-p /Cheat-Codes-Pass/'

Look for tests prove_startPrank(address) and prove_startPrank_val()

Checklist

  • tested locally
  • added automated tests
  • updated the docs
  • updated the changelog

Additional Notes

Edge cases such as stacks of startPrank() were not tested/considered.
For example, this code will not work - although I am unsure how this operates in Foundry anyway.

.. code 1 ..
hevm.startPrank(address1);
 .. code 2 ..
hevm.startPrank(address2);
 .. code 3 .. 
hevm.stopPrank();
.. code 4 ..
hevm.stopPrank();
.. code 5 ..

While untested, I would expect:
code 1 to have msg.sender = default
code 2 to have msg.sender = address1
code 3 to have msg.sender = address2
code 4 to have msg.sender = default
code 5 to have msg.sender = default


I have never written code in Haskell before nor do I have experience with this codebase, please let me know if there are edge cases to consider or any other styling I should do to conform to this repo's standards.

Copy link
Collaborator

@arcz arcz left a comment

Choose a reason for hiding this comment

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

LGTM!

@arcz arcz merged commit 02c072f into ethereum:main May 30, 2024
8 checks passed
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.

2 participants