foundry-rs / foundry-rs/foundry
feat(`forge script`): offer convenient way of performing idempotent CREATE2 deployments in scripts and tests
- Dominant language
- Rust
- Stars
- 10.6k
- Forks
- 2.6k
- Avg merge
- 18h 20m
- Merged PRs (30d)
- 510
Description
I'd like to open a discussion regarding a common challenge with `CREATE2` deployments in Foundry scripts and tests.
The core issue is that `CREATE2` deployments are not inherently idempotent. Any attempt to deploy to an address that already contains code will cause the transaction to revert, halting the entire script or test.
This creates significant friction in two key workflows:
1. **Deployment Scripts (`forge script`):** When running a deployment for a multi-contract system, the script fails if it encounters a contract that hasn't changed from a deployed version and already exists on-chain. This makes robust, repeatable deployments difficult without adding cumbersome manual checks.
2. **Fork Testing (`forge test`):** When writing fork tests, the `setUp` function will fail if the contracts it needs to deploy for the test environment already exist on the forked chain. This limits our ability to write tests against many real-world network states.
This leads me to the main questions for this discussion:
* What are the current recommended best practices within the Foundry ecosystem for handling this? Is there an idiomatic, clean way to achieve idempotent deployments that I might be missing?
* If a clean, built-in pattern doesn't currently exist, would the Foundry team be open to exploring infrastructure to make this workflow more robust and ergonomic?
I believe addressing this would be a great quality-of-life improvement for developers building complex, deterministic systems.
Contributor guide
Assessment
This issue has not been assessed yet.