foundry icon indicating copy to clipboard operation
foundry copied to clipboard

support --profile cli argument

Open sakulstra opened this issue 9 months ago • 4 comments

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.

sakulstra avatar May 05 '24 11:05 sakulstra

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

mattsse avatar May 05 '24 11:05 mattsse

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

mds1 avatar May 05 '24 12:05 mds1

@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 avatar May 05 '24 17:05 sakulstra

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.

sakulstra avatar May 07 '24 21:05 sakulstra

Marking as duplicate of https://github.com/foundry-rs/foundry/issues/5479

zerosnacks avatar Jul 04 '24 15:07 zerosnacks