refactor: adapt isContext
cheatcode
#674
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Foundry has an
isContext
cheatcode that tells you whichforge
command was used to execute the Solidity code (e.g.forge test
orforge coverage
orforge script
).I adapted the
isContext
cheatcode for EDR by renaming the context enum fromForgeContext
toExecutionContext
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 previousForgeContext
and inlined its logic in the cheatcode as thePartialEq
implementation wasn't symmetric (Test == TestGroup
, butTestGroup != Test
) which can be a source of subtle bugs.