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

refactor: adapt isContext cheatcode #674

Open
wants to merge 1 commit into
base: feat/solidity-tests
Choose a base branch
from

Conversation

agostbiro
Copy link
Member

Foundry has an isContext cheatcode that tells you which forge command was used to execute the Solidity code (e.g. forge test or forge coverage or forge script).

I adapted the isContext cheatcode for EDR by renaming the context enum from ForgeContext to ExecutionContext and removed the scripting related variants.

The Foundry code assumes that Solidity code is ran via the forge CLI and that the execution context is set based on the subcommand once per process. This doesn't make sense for us, since EDR provides Solidity tests as a library, so I changed this to getting the execution context as a config value in the cheatcode implementation.

I changed the representation of the execution context in the Rust code. I split the previous ForgeContext enum into two enums as it was previously used as both as an argument from Solidity where it can have five variants and as a config value where it can only have four variants (TestGroup doesn't make sense as a config value).

I also removed the PartialEq implementation for the previous ForgeContext and inlined its logic in the cheatcode as the PartialEq implementation wasn't symmetric (Test == TestGroup, but TestGroup != Test) which can be a source of subtle bugs.

@agostbiro agostbiro added the no changeset needed This PR doesn't require a changeset label Sep 20, 2024
@agostbiro agostbiro added this to the Solidity tests, phase 2 milestone Sep 20, 2024
@agostbiro agostbiro requested a review from a team September 20, 2024 15:56
@agostbiro agostbiro self-assigned this Sep 20, 2024
Copy link

changeset-bot bot commented Sep 20, 2024

⚠️ No Changeset found

Latest commit: 855af72

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@agostbiro agostbiro temporarily deployed to github-action-benchmark September 20, 2024 15:56 — with GitHub Actions Inactive
@agostbiro agostbiro temporarily deployed to github-action-benchmark September 20, 2024 15:56 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changeset needed This PR doesn't require a changeset
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant