feat: add test runner support types for compiler-agnostic testing#368
Draft
feat: add test runner support types for compiler-agnostic testing#368
Conversation
Add FuzzLiteral, InlineConfigEntries, and InlineConfigEntry types that compilers can use to provide source-level analysis to Foundry's test runner. This enables non-Solidity compilers to seed the fuzz dictionary and provide per-test config overrides without depending on solar/NatSpec. All types are #[non_exhaustive] for forward compatibility. Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
2 tasks
Add the TestRunnerSupport trait that compilers can implement to provide source-level metadata (fuzz literals, inline config) to Foundry's test runner. Default implementations return empty results, so compilers work out of the box without implementing this trait. Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
…quirement - Remove unused `source: PathBuf` field from InlineConfigEntry - Update docs to clarify config_values should NOT include the forge-config: prefix (bridge adds it automatically) Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Use Self::CompilationError and Self::CompilerContract instead of generic <E, C> params. This makes the trait actually useful for downstream compilers that need to inspect their own output types. Remove #[auto_impl] since the trait has default impls and Compiler already provides auto_impl for wrapper types. Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add types and traits that enable non-Solidity compilers to plug into Foundry's test runner (fuzzing, cheatcodes, invariant testing) without depending on solar/NatSpec internals.
Motivation
Tweet thread from @real_philogy requesting the ability to plug a custom compiler into Foundry and reuse the fuzzing, testing, and cheatcode-augmented EVM runtime. This is the
foundry-compilersside of that work.Changes
New
test_supportmodule with:Types:
FuzzLiteral— enum of literal values (addresses, ints, bytes, strings) a compiler can extract from source to seed the fuzzer dictionary.FixedBytesvariant includes explicitsize: u8for type-safebytesNwidth.InlineConfigEntries/InlineConfigEntry— per-test config overrides (Solidity uses NatSpec/// forge-config:comments; other languages use their own syntax)#[non_exhaustive]for forward compatibilityTrait:
TestRunnerSupport— supertrait ofCompilerwithfuzz_literals()andinline_config()methods. Default implementations return empty results, so compilers work out of the box. Uses#[auto_impl]matching theCompilertrait pattern.Testing
Types + trait with defaults (no complex logic), verified with
cargo checkandcargo clippy.Next steps
TestRunnerSupportforSolcCompiler(move solar literal extraction + NatSpec parsing here)TestRunnerSupportforMultiCompiler(delegate to inner compilers)Prompted by: zerosnacks