-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Create2Factory on scripts (#577)
* take historical block count from env * fmt * fmt * Handle create2 factory usage in scripts * Add test for create2 deployment in zksync * Cargo clippy * change conditional in address parsing, separate test case and remove create2 factory deps * Apply formatter * Check which deployer we are using to retrieve the code hash * Update crates/cheatcodes/src/inspector.rs Co-authored-by: Nisheeth Barthwal <[email protected]> * Migrate zksync create 2 deployer constant to zksync core * Check for expected address in test and change conditional in utils --------- Co-authored-by: Nisheeth Barthwal <[email protected]> Co-authored-by: Jrigada <[email protected]>
- Loading branch information
1 parent
02346a9
commit bc065c0
Showing
8 changed files
with
143 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.18; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {Greeter} from "../src/Greeter.sol"; | ||
import {Create2Utils} from "../src/Create2Utils.sol"; | ||
|
||
contract Create2Script is Script { | ||
function run() external { | ||
(bool success,) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", true)); | ||
require(success, "zkVm() call failed"); | ||
|
||
vm.startBroadcast(); | ||
|
||
// Deploy Greeter using create2 with a salt | ||
bytes32 greeterSalt = bytes32("12345"); | ||
Greeter greeter = new Greeter{salt: greeterSalt}(); | ||
|
||
// Verify Greeter deployment | ||
require(address(greeter) != address(0), "Greeter deployment failed"); | ||
|
||
// Verify the deployed address matches the expected address | ||
bytes32 bytecodeHash = getBytecodeHash("zkout/Greeter.sol/Greeter.json"); | ||
address expectedAddress = Create2Utils.computeCreate2Address( | ||
address(0x0000000000000000000000000000000000010000), // DEFAULT_CREATE2_DEPLOYER_ZKSYNC | ||
greeterSalt, | ||
bytecodeHash, | ||
keccak256(abi.encode()) | ||
); | ||
|
||
require(address(greeter) == expectedAddress, "Deployed address doesn't match expected address"); | ||
|
||
// Test Greeter functionality | ||
string memory greeting = greeter.greeting("Alice"); | ||
require(bytes(greeting).length > 0, "Greeter greeting failed"); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
|
||
function getBytecodeHash(string memory path) internal returns (bytes32 bytecodeHash) { | ||
string memory artifact = vm.readFile(path); | ||
bytecodeHash = vm.parseJsonBytes32(artifact, ".hash"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use foundry_config::fs_permissions::PathPermission; | ||
use foundry_test_utils::{forgetest_async, util, TestProject}; | ||
|
||
use crate::test_helpers::run_zk_script_test; | ||
|
||
forgetest_async!(can_deploy_via_create2, |prj, cmd| { | ||
setup_create2_prj(&mut prj); | ||
let mut config = cmd.config(); | ||
config.fs_permissions.add(PathPermission::read("./zkout")); | ||
prj.write_config(config); | ||
run_zk_script_test( | ||
prj.root(), | ||
&mut cmd, | ||
"./script/Create2.s.sol", | ||
"Create2Script", | ||
None, | ||
2, | ||
Some(&["-vvvvv"]), | ||
); | ||
}); | ||
|
||
fn setup_create2_prj(prj: &mut TestProject) { | ||
util::initialize(prj.root()); | ||
prj.add_script("Create2.s.sol", include_str!("../../fixtures/zk/Create2.s.sol")).unwrap(); | ||
prj.add_source("Greeter.sol", include_str!("../../../../../testdata/zk/Greeter.sol")).unwrap(); | ||
prj.add_source("Create2Utils.sol", include_str!("../../../../../testdata/zk/Create2Utils.sol")) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters