-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into tests/invariant-handler
- Loading branch information
Showing
13 changed files
with
293 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.