Skip to content

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Aug 19, 2025

Motivation

teams that automate the setup of multi-chain configs, will benefit from being able to use the chain id rather than the chain name.

Solution

normalize the chain key in fork.<chain> to become the canonical name defined by alloy-chains. This keeps the UX of named chains, and also adds support for ids

@0xrusowsky 0xrusowsky added this to the v1.4.0 milestone Aug 19, 2025
@0xrusowsky 0xrusowsky self-assigned this Aug 19, 2025
@0xrusowsky 0xrusowsky added the C-forge Command: forge label Aug 19, 2025
@0xrusowsky 0xrusowsky requested a review from DaniPopes as a code owner August 19, 2025 07:15
@0xrusowsky 0xrusowsky added the A-cheatcodes Area: cheatcodes label Aug 19, 2025
@0xrusowsky
Copy link
Contributor Author

@grandizzy i made the error more explicit

grandizzy
grandizzy previously approved these changes Aug 19, 2025
@zerosnacks
Copy link
Member

zerosnacks commented Aug 19, 2025

makes sense, not sure how relevant is the is not supported by 'alloy_chains' err here though, maybe we should remove the by 'alloy_chains' ?

i was thinking that it was a way to prompt them to check the supported chains so that they could either:

  • fix a typo (if any)
  • open a PR to add support for that chain

One possible issue is that users may want to also be able to use the foundry.toml driven configuration on private testnets / ephemeral testnets for testing and pushing to alloy-chains is not relevant / not desired.

I would be in favor of merging the current proposal and waiting for community feedback on it and address this then.

zerosnacks
zerosnacks previously approved these changes Aug 19, 2025
@0xrusowsky
Copy link
Contributor Author

@zerosnacks should i not error if the rpc chains are not supported by alloy chains then?

@zerosnacks
Copy link
Member

zerosnacks commented Aug 19, 2025

What would the side effect of not error-ing be?

@0xrusowsky
Copy link
Contributor Author

0xrusowsky commented Aug 19, 2025

i was using alloy-chains to convert between names and ids. If they provide a non-supported chain, it could work as long as the chain key is a uint (the id).

i'd have to adjust the cheatcode impl slightly though, as i was operating on the premise that they would always be alloy chains (not a big deal)

@zerosnacks
Copy link
Member

i was using alloy-chains to convert between names and ids. If they provide a non-supported chain, it could work as long as the chain key is a uint (the id).

i'd have to adjust the cheatcode impl slightly though, as i was operating on the premise that they would always be alloy chains (not a big deal)

Ah nice, I think this would be preferable as an end user and worth implementing

// Determine the canonical key for this entry
let canonical_key = if let Ok(chain_id) = key.parse::<u64>() {
if let Some(named) = alloy_chains::Chain::from_id(chain_id).named() {
named.as_str().to_string()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason we can't fall back to just integers if they are not supported in alloy_chains?

Copy link
Contributor Author

@0xrusowsky 0xrusowsky Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, that's what we were discussing above.

addressed with 7ccb5d9

Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Pending @grandizzy / @onbjerg

Copy link
Collaborator

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@0xrusowsky 0xrusowsky merged commit bdbe379 into master Aug 21, 2025
22 checks passed
@0xrusowsky 0xrusowsky deleted the rusowsky/support-num-keys branch August 21, 2025 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(cheats): add writeFork.. cheats to write vars into fork.<chain> of foundry.toml
4 participants