Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept ethlive as a chain name #2268

Merged
merged 4 commits into from Mar 16, 2023
Merged

Conversation

CodeSandwich
Copy link
Contributor

@CodeSandwich CodeSandwich commented Mar 16, 2023

Motivation

I'm coming from Foundry. The result of cast chain for Ethereum mainnet returns ethlive. This value is then rejected as a --chain argument for forge verify-contract, maybe other commands too. The correct value for --chain is mainnet.

Solution

This PR adds support for parsing the ethlive name of a chain. This name was also used in dapptools, maybe also somewhere else, but it doesn't seem to be a bug on Foundry side to use it, it's just a less known value.

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog
  • Breaking changes

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

I'd prefer an alias, and a test for this.

@@ -47,6 +47,7 @@ pub type ParseChainError = TryFromPrimitiveError<Chain>;
#[strum(serialize_all = "kebab-case")]
#[repr(u64)]
pub enum Chain {
#[strum(serialize = "ethlive")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

this will change replace "mainnet" whith ethlive.

imo mainnet is more meaningful.

we could add this as alias, but dunno how with strum tbh.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah it's weird, I learnt this not too long ago: you can have only one "to_string" attr, which is the main one. Then aliases use serialize = ...
I'll open a pr to add that to the comments above

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked cast chain, and the reason we use ethlive is because of eth classic

https://github.com/foundry-rs/foundry/blob/816e00bb8cf564fa3f319d7d68511b05ac3e2b5d/cast/src/lib.rs#L413-L418

@@ -47,6 +47,7 @@ pub type ParseChainError = TryFromPrimitiveError<Chain>;
#[strum(serialize_all = "kebab-case")]
#[repr(u64)]
pub enum Chain {
#[strum(serialize = "ethlive")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

strum is weird and you have to this

Suggested change
#[strum(serialize = "ethlive")]
#[strum(to_string = "mainnet", serialize = "ethlive")]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, the proposed PR breaks the string representation. I've fixed it by adding another serialize parameter, it matches what other enum variants do. I've added tests checking that, but I see that in #2270 you've solved the tests coverage once and for all, so I'll remove them.

@gakonst gakonst merged commit 18d4042 into gakonst:master Mar 16, 2023
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants