You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function test1() public {
address a =computeCreate2Address(0, hashInitCode(type(Counter).creationCode), address(this));
address b =address(new Counter{salt: 0}());
require(a == b, "create2 address mismatch");
}
Run forge test --mt test1 -vvvv, the test passes and deploys to new Counter@0xBE03C2aFB559A5Ce6926b01A813F37584476c95f
Update the default script to run:
function run() public {
vm.broadcast();
new Counter{salt: 0}();
}
Run forge script script/Counter.s.sol -vvvv and you'll see it deploys to new Counter@0xE414be17fD7aa8Ee7194000dc622AdEF3c81aFCd
This shows that scripts (as expected) route create2 deploys through the default create2 deployer. But tests (unexpectedly) deploy directly from the test contract.
I think the two behaviors should be consistent, especially since it's ideal to test scripts, and this behavior means we get different addresses depending on which command you invoke the script with (directly, or indirectly trough a test) which is confusing behavior
For anyone looking for a workaround, by adding vm.broadcast (or vm.startBroadcast) before deploying the contract, it will be deployed with the CREATE2 deployer.
@Evalir Is this one an easy fix? Using deploy scripts for test setups is recommended in the foundry book best practices page, but this issue adds a hurdle/source of confusion to doing that
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (ca67d15 2023-08-02T00:22:03.700607000Z)
What command(s) is the bug in?
forge test
Operating System
None
Describe the bug
forge init
a new repoforge test --mt test1 -vvvv
, the test passes and deploys tonew Counter@0xBE03C2aFB559A5Ce6926b01A813F37584476c95f
forge script script/Counter.s.sol -vvvv
and you'll see it deploys tonew Counter@0xE414be17fD7aa8Ee7194000dc622AdEF3c81aFCd
This shows that scripts (as expected) route create2 deploys through the default create2 deployer. But tests (unexpectedly) deploy directly from the test contract.
I think the two behaviors should be consistent, especially since it's ideal to test scripts, and this behavior means we get different addresses depending on which command you invoke the script with (directly, or indirectly trough a test) which is confusing behavior
cc @zobront
The text was updated successfully, but these errors were encountered: