foundry
foundry copied to clipboard
Environment variable, ETH_RPC_URL, is not being picked up by forge script
Component
Forge
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
What version of Foundry are you on?
forge 0.2.0 (63fff35 2024-04-22T00:25:29.889454000Z)
What command(s) is the bug in?
forge script
Operating System
macOS (Apple Silicon)
Describe the bug
In previous versions of forge, ETH_RPC_URL
could be set in the terminal via export and forge script
would pick it up. When it was not set at all, it would default to the local anvil instance. These no longer happen. rpc-url
has to be explicitly on the command now, even for local anvil instance at 127.0.0.1:8545
.
--rpc-url
in cast commands is coming from RpcOpts
: https://github.com/foundry-rs/foundry/blob/e971af109b8240b8de694b23bf6d1f96ed10ae71/crates/cli/src/opts/ethereum.rs#L21-L22
and for forge we are using EvmArgs::fork_url
: https://github.com/foundry-rs/foundry/blob/e971af109b8240b8de694b23bf6d1f96ed10ae71/crates/common/src/evm.rs#L47-L49
the latter does not have a env = "ETH_RPC_URL"
and I don't think it had it at some point before
I don't think we should enable this now as this would cause people's forge test
commands to run in forked environment if they have a ETH_RPC_URL
variable set which will slow down tests a lot
cc @mattsse @DaniPopes @zerosnacks
if they have a ETH_RPC_URL variable set which will slow down tests a lot
yeah, if --fork-url is provided all test launch in forking mode
this can cause issues if the same var is used as smth like mainnet = ${ETH_RPC_URL}
in foundry.toml.
Can you help us understand why the previous versions of foundry handled this case differently? In the past we did not have to specify this in every command because it automatically picked up on the environment variable. Did the most recent version change how it handles environment variables or specifically this argument? The puzzling behavior is the need to specify it for a local anvil instance now.
Marking as not planned
per the comments
@jjbailey-io because of how environment variables overrule any configuration you can easily get into a situation like every test being ran as a fork test, this has significant overhead. There is a meta-ticket here: https://github.com/foundry-rs/foundry/issues/7322 tracking proposed improvements around prioritisation in the CLI