foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
7.71k stars 1.53k forks source link

support --profile cli argument #7859

Open sakulstra opened 3 weeks ago

sakulstra commented 3 weeks ago

Component

Forge

Describe the feature you would like

It would be good if --profile could be specified as cli argument for forge test and forge script

The original issue I tried to solve is the following:

is there a way to specify evm_version per network (or more broadly, is there a way to specify compiler options per network)? We're currently facing some issues on a multi-chain foundry project were some external contracts use push0, but if we just change https://book.getfoundry.sh/reference/config/solidity-compiler#evm_version to shanghai it will silently start breaking on e.g. metis (which still doesn't support push0).

As i think there currently is no way to do this, my idea was to "work around" the problem by introducing "per chain" profiles(e.g. profile.polygon) and using the correct one based on the chain alias. Setting the profile via FOUNDY_PROFILE env is cumbersome though. It would be nice if it could be just part of the script/test command.

Additional context

I think per chain compiler config would be a quite good(but ofc more complex) feature especially when shipping with reasonable defaults. Currently the evm landscape is quite hard to maneuver due to subtile changes. Having e.g. metis "default" to pre istanbul could make a lot of sense.

mattsse commented 3 weeks ago

I think per chain compiler config would be a quite good(but ofc more complex) feature especially when shipping with reasonable defaults. Currently the evm landscape is quite hard to maneuver due to subtile changes.

investigating and scoping this currently, but yes this is a bit more complex

cc @klkvr

mds1 commented 3 weeks ago

Per chain compiler config related to https://github.com/foundry-rs/foundry/issues/7720. It proposes a UX for different profiles per contract, probably would need to be tweaked for this purpose

sakulstra commented 3 weeks ago

@mds1 yah seems related but quite different as the suggestion it's factually a bit of the opposite.

In practice I want to run the same contract on 12 chains, but on one a few i need paris were on some others i need shanghai. In fact for me would be fine to run paris on all chains, but in this particular case one of the external contracts used, was deployed with shanghai ... so if i use paris the tests will fail with an evm error(as push0 doesn't exist yet in the test environment).

In my naive view a "per network" config would be the perfect solution, but honestly idk if it's even possible to do. As you can do things like vm.createSelectFork(randomStringPotentiallyFromEnv) at any point in your test i guess it's impossible to know the target network at compile time(also, i think while we never do it, it's possible to have a single test fork multiple networks makin "target network" somewhat arbitrary)?

Probably for now, having --profile be a thing would be a good enough workaround

sakulstra commented 3 weeks ago

Actually one related issue here is caching: seems like the cache is currently per file/solc version, but not per evm_version so changing evm_version always forces a complete recompile which on bigger projects is painful.