Commit c419100
feat(forge): specify compilation profile in vm.getCode (foundry-rs#13191)
* feat(forge): specify compilation profile in vm.getCode
Add support for specifying a compilation profile in artifact path parsing for
vm.getCode, vm.getDeployedCode, and vm.deployCode cheatcodes.
This allows users with multiple compilation profiles in foundry.toml to select
specific artifact versions. For example:
- `vm.getCode("Contract.sol:v1")`
- `vm.getCode("Contract.sol:ContractName:optimized")`
The feature distinguishes between semver versions (like 0.8.23) and profile
names (like v1, optimized) by attempting to parse the suffix as a version
first.
Closes foundry-rs#12821
* fix: address clippy warnings
- Combine duplicate if branches for version detection
- Remove needless ref borrow in profile comparison
* test: add unit tests for artifact path parsing and profile support
- Refactor parsing logic into reusable parse_artifact_path function
- Add 11 unit tests covering all artifact path formats:
- file only, file+contract, file+contract+version, file+contract+profile
- file+version, contract only, contract+version, contract+profile
- Various profile name patterns (v1, v2, paris, optimized, etc.)
- Add Solidity integration test for profile-based getCode
* test: add multi-profile test demonstrating different bytecode per profile
Add comprehensive tests showing that vm.getCode correctly retrieves
different bytecode for different compilation profiles:
- Create testdata/multi-profile/ with Counter contract compiled using
'default', 'optimized' (10000 runs), and 'unoptimized' (no optimizer) profiles
- Add tests verifying:
- Different profiles produce different bytecode
- vm.getCode('Contract:profile') works correctly
- vm.getCode('path/to/Contract.sol:Contract:profile') works correctly
- vm.deployCode with profile works
- vm.getDeployedCode with profile works
- Non-existent profiles fail appropriately
* style: fix rustfmt formatting
* style: fix forge fmt formatting in Solidity test
* fix: simplify multi-profile tests to verify parsing behavior
- Remove invalid 'profiles' field from compilation_restrictions
- Use assertTrue instead of assertNotEq (not available in DSTest)
- Simplify tests to verify profile parsing works with default profile
- Test that non-existent profiles fail appropriately
* fix: restore multi-profile compilation restriction in foundry.toml
* fix: rename Counter to ProfileCounter to avoid artifact name collision
The multi-version tests use a contract named Counter, causing conflicts
when my multi-profile tests also used Counter.
* fix: remove multi-profile Solidity test to avoid breaking existing tests
The additional_compiler_profiles cause all contracts to be compiled with
multiple profiles, which breaks the existing multi-version tests that
rely on version-based disambiguation.
The unit tests for artifact path parsing adequately test the profile
feature at the parsing level. End-to-end testing of profile-based
selection requires a more complex test setup.
* test: add profile-based getCode test using existing paris profile
Add test demonstrating vm.getCode with profile selection using the existing
paris compilation profile. Tests:
- vm.getCode("path:Contract:paris") format
- vm.getCode("Contract:paris") format
- vm.getDeployedCode and vm.deployCode with profile
- Error when using non-existent profile
- Error when requesting wrong profile for a contract
This test uses the existing paris profile which is already scoped to
paris/** files, avoiding conflicts with other multi-version tests.
Amp-Thread-ID: https://ampcode.com/threads/T-019bea01-185e-7079-990e-f33585663be2
Co-authored-by: Amp <amp@ampcode.com>
* test: add multi-profile test with proper disambiguation fix
Fix the artifact disambiguation logic to not filter by running_artifact's
version/profile when user has explicitly specified those criteria. This
allows adding global additional_compiler_profiles without breaking
existing tests.
Changes:
- Fix disambiguation: only use running_artifact's version for filtering
when user did NOT specify a version in the artifact path
- Same fix for profile filtering
- Add 'optimized' and 'unoptimized' profiles to testdata/foundry.toml
- Add GetCodeMultiProfile.t.sol demonstrating that different profiles
produce different bytecode and can be selected via vm.getCode
The test verifies:
- vm.getCode("Contract:optimized") returns different bytecode than
vm.getCode("Contract:unoptimized")
- vm.deployCode and vm.getDeployedCode work with profile selection
- Non-existent profiles fail appropriately
Amp-Thread-ID: https://ampcode.com/threads/T-019bea01-185e-7079-990e-f33585663be2
Co-authored-by: Amp <amp@ampcode.com>
* fix: use require instead of assertNotEq for bytes32 comparison
assertNotEq doesn't have an overload for bytes32, use require with != instead
* fix: resolve CI failures for profile-based artifact selection
Changes:
- Remove GetCodeMultiProfile.t.sol test that expected artifacts compiled
with 'optimized' and 'unoptimized' profiles without corresponding
compilation_restrictions
- Remove unused 'optimized' and 'unoptimized' profiles from foundry.toml
(the paris profile remains as it has proper restrictions)
- Update multi-version tests to use full paths (multi-version/Counter.sol)
to avoid ambiguity with other Counter contracts in testdata that would
cause 'multiple matching artifacts found' error
Amp-Thread-ID: https://ampcode.com/threads/T-019bea8a-abde-7172-9b50-efb0569a8222
Co-authored-by: Amp <amp@ampcode.com>
* fix fmt
* fix getCode file profile lookup
* fix: prefer contract name for ambiguous getCode artifact paths
---------
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: zerosnacks <zerosnacks@protonmail.com>
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-authored-by: Derek <256792747+decofe@users.noreply.github.com>
Co-authored-by: Centaur AI <ai@centaur.local>
Co-authored-by: Mablr <59505383+mablr@users.noreply.github.com>
Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>1 parent 6255cde commit c419100
7 files changed
Lines changed: 424 additions & 90 deletions
File tree
- crates/cheatcodes
- assets
- spec/src
- src
- testdata
- multi-version/cheats
- paris/cheats
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1998 | 1998 | | |
1999 | 1999 | | |
2000 | 2000 | | |
2001 | | - | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
2002 | 2004 | | |
2003 | 2005 | | |
2004 | 2006 | | |
2005 | 2007 | | |
2006 | | - | |
| 2008 | + | |
| 2009 | + | |
2007 | 2010 | | |
2008 | 2011 | | |
2009 | 2012 | | |
2010 | 2013 | | |
2011 | 2014 | | |
2012 | | - | |
| 2015 | + | |
| 2016 | + | |
2013 | 2017 | | |
2014 | 2018 | | |
2015 | 2019 | | |
2016 | 2020 | | |
2017 | 2021 | | |
2018 | 2022 | | |
2019 | 2023 | | |
2020 | | - | |
| 2024 | + | |
| 2025 | + | |
2021 | 2026 | | |
2022 | 2027 | | |
2023 | 2028 | | |
2024 | 2029 | | |
2025 | 2030 | | |
2026 | 2031 | | |
2027 | 2032 | | |
2028 | | - | |
| 2033 | + | |
| 2034 | + | |
2029 | 2035 | | |
2030 | 2036 | | |
2031 | 2037 | | |
2032 | 2038 | | |
2033 | 2039 | | |
2034 | 2040 | | |
2035 | 2041 | | |
2036 | | - | |
| 2042 | + | |
| 2043 | + | |
2037 | 2044 | | |
2038 | 2045 | | |
2039 | 2046 | | |
2040 | 2047 | | |
2041 | 2048 | | |
2042 | | - | |
| 2049 | + | |
| 2050 | + | |
2043 | 2051 | | |
2044 | 2052 | | |
2045 | 2053 | | |
2046 | 2054 | | |
2047 | 2055 | | |
2048 | 2056 | | |
2049 | 2057 | | |
2050 | | - | |
| 2058 | + | |
| 2059 | + | |
2051 | 2060 | | |
2052 | 2061 | | |
2053 | 2062 | | |
2054 | 2063 | | |
2055 | 2064 | | |
2056 | 2065 | | |
2057 | 2066 | | |
2058 | | - | |
| 2067 | + | |
| 2068 | + | |
2059 | 2069 | | |
2060 | 2070 | | |
2061 | 2071 | | |
2062 | 2072 | | |
2063 | 2073 | | |
2064 | 2074 | | |
2065 | 2075 | | |
2066 | | - | |
| 2076 | + | |
| 2077 | + | |
2067 | 2078 | | |
2068 | 2079 | | |
2069 | 2080 | | |
| |||
0 commit comments