-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(forge): clone verified contracts as a foundry project #7576
Conversation
Forge clone
Test: fix rate limit issue for forge clone tests
Add `clone.toml` metadata to forge clone
Improve clone metadata
Add constructor arguments in the clone metadata
crates/common/src/rpc.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the practice of RPC endpoints in testing, I also added a list of mainnet Etherscan API keys to facilitate integrated tests that require fetching Etherscan data, e.g., forge clone
. The rate limit of Etherscan API with keys should be sufficient to allow tests pass.
e034bb3
to
ee11fbf
Compare
Thanks for your effort @mattsse! We have future addressed some issues in tests. Could you trigger the CI test and see if this PR works? |
ty @Troublor I'll give this a final review tmrw |
There's an unusual CI test failure here, although the CI appears correctly in our repo. |
nice work! I'm unable to push directly to this branch for some reason, then this is g2m |
@mattsse I just merged the latest commit on master branch. Sorry to interrupt the CI that you just triggered. Could you please trigger again? |
tysm for this! |
* feat:support forge clone * feat: update configuration based on metadate from EtherScan 👷 * doc: update the documenation for * add dump_sources function * fix: add existing remapping into remappings.txt * apply remapping on libraries * add tests * feat: update remappings in config file * add two more test cases * fix library remapping bug * test: add e2e test cases for forge clone * test: fix rate limit issue for forge clone tests * feat: disable git by default for forge clone * dump clone.toml metadata in cloned projects * add storage layout to the clone metadata * dump clone metadata in a hidden, readonly, compact json file * add constructor arguments in clone metadata * fix: typo field name * fix: bug in remapping * fix: remapping disorder for verified foundry contracts * fix clippy and fmt warnings * fmt in the foundry way * chore: restore files to be consistent with foundry fmt style * cherry pick bug fixes from tweak branch * fix: remove the dependency of Etherscan in tests * chore: move mockall to dev dependency, only mock in test build * feat: use camelCase in .clone.meta * doc: add comments to explain forge clone * fix: import file not found error * chore: remove uncessary dependency fix: fix a foundry config bug regarding generating project_paths * chore: refactor the test code a bit * Update crates/forge/bin/cmd/clone.rs Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> * Update crates/forge/bin/cmd/clone.rs Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> * chore: change string as address in CloneArg * test: add one basic forgetest for clone * feat: dump remappings into remappings.txt by default chore: break a large function into multiple small one to improve readability * feat: improve UX and make --quiet true quiet * test: add one more forgetest! for clone * fix minor issues suggested in code review * fix: incorrect assertion for project paths * test: add default etherscan api keys and remove sleep in tests * test: add more etherscan api keys * fix: revoke the unnecessary changes in config.rs * feat: bump foundry-compilers to 0.3.16 * chore: refactor code and clean some comments * fix: path disorder on windows * touchups --------- Co-authored-by: Zhuo Zhang <zhan3299@purdue.edu> Co-authored-by: Zhuo Zhang <14835483+ZhangZhuoSJTU@users.noreply.github.com> Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This PR is the first step of integrating on-chain contract tweak feature into foundry, as mentioned in #7575.
We introduce
forge clone
command, which takes the address of an on-chain verified contract and creates a corresponding foundry project in the local filesystem.The foundry configuration
foundry.toml
is well generated so that the project is compilation-ready and guaranteed to generate exactly the same code as the on-chain contract.We also generate a metadata file,
.clone.meta
, which contains the original address of the contract, constructor arguments, storage layout, etc, which may be useful for downstream tasks.