From c4548e0df4c73abf57110575b61067c104cbcde1 Mon Sep 17 00:00:00 2001 From: Jrigada Date: Thu, 29 Aug 2024 14:49:10 -0300 Subject: [PATCH 1/3] Added testing of multiple deploy of same contract --- crates/forge/tests/fixtures/zk/Deploy.s.sol | 30 ++++++++++++++++++++ crates/forge/tests/it/zk/deploy.rs | 31 +++++++++++++++++++++ crates/forge/tests/it/zk/mod.rs | 1 + 3 files changed, 62 insertions(+) create mode 100644 crates/forge/tests/fixtures/zk/Deploy.s.sol create mode 100644 crates/forge/tests/it/zk/deploy.rs diff --git a/crates/forge/tests/fixtures/zk/Deploy.s.sol b/crates/forge/tests/fixtures/zk/Deploy.s.sol new file mode 100644 index 000000000..9674514ce --- /dev/null +++ b/crates/forge/tests/fixtures/zk/Deploy.s.sol @@ -0,0 +1,30 @@ +// 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"; + +contract DeployScript is Script { + // Vm constant vm = Vm(HEVM_ADDRESS); + + Greeter greeter; + string greeting; + + function run() external { + // test is using old Vm.sol interface, so we call manually + (bool success,) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", true)); + require(success, "zkVm() call failed"); + vm.startBroadcast(); + + greeter = new Greeter(); + + greeter.setAge(123); + uint256 age = greeter.getAge(); + + greeter.greeting("john"); + + vm.stopBroadcast(); + + assert(age == 123); + } +} diff --git a/crates/forge/tests/it/zk/deploy.rs b/crates/forge/tests/it/zk/deploy.rs new file mode 100644 index 000000000..4af3bb71e --- /dev/null +++ b/crates/forge/tests/it/zk/deploy.rs @@ -0,0 +1,31 @@ +use foundry_test_utils::{forgetest_async, util, TestProject}; + +use crate::test_helpers::run_zk_script_test; + +forgetest_async!(multiple_deployments_of_the_same_contract, |prj, cmd| { + setup_deploy_prj(&mut prj); + run_zk_script_test( + prj.root(), + &mut cmd, + "./script/Deploy.s.sol", + "DeployScript", + None, + 3, + Some(&["-vvvvv"]), + ); + run_zk_script_test( + prj.root(), + &mut cmd, + "./script/Deploy.s.sol", + "DeployScript", + None, + 3, + Some(&["-vvvvv"]), + ); +}); + +fn setup_deploy_prj(prj: &mut TestProject) { + util::initialize(prj.root()); + prj.add_script("Deploy.s.sol", include_str!("../../fixtures/zk/Deploy.s.sol")).unwrap(); + prj.add_source("Greeter.sol", include_str!("../../../../../testdata/zk/Greeter.sol")).unwrap(); +} diff --git a/crates/forge/tests/it/zk/mod.rs b/crates/forge/tests/it/zk/mod.rs index 4149c7dfd..576f53373 100644 --- a/crates/forge/tests/it/zk/mod.rs +++ b/crates/forge/tests/it/zk/mod.rs @@ -3,6 +3,7 @@ mod basic; mod cheats; mod contracts; mod create; +mod deploy; mod factory; mod factory_deps; mod fork; From 100dc576b9bfef52f9c3cd85109b5ff05e189b1f Mon Sep 17 00:00:00 2001 From: Jrigada Date: Tue, 3 Sep 2024 10:27:04 -0300 Subject: [PATCH 2/3] Change low level call to zkvm --- crates/forge/tests/fixtures/zk/Deploy.s.sol | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/forge/tests/fixtures/zk/Deploy.s.sol b/crates/forge/tests/fixtures/zk/Deploy.s.sol index 9674514ce..87745585c 100644 --- a/crates/forge/tests/fixtures/zk/Deploy.s.sol +++ b/crates/forge/tests/fixtures/zk/Deploy.s.sol @@ -5,15 +5,13 @@ import {Script} from "forge-std/Script.sol"; import {Greeter} from "../src/Greeter.sol"; contract DeployScript is Script { - // Vm constant vm = Vm(HEVM_ADDRESS); + Vm constant vm = Vm(HEVM_ADDRESS); Greeter greeter; string greeting; function run() external { - // test is using old Vm.sol interface, so we call manually - (bool success,) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", true)); - require(success, "zkVm() call failed"); + vm.zkVm(true); vm.startBroadcast(); greeter = new Greeter(); From 162e94256596b80a538f8209b941bc9a59204988 Mon Sep 17 00:00:00 2001 From: Jrigada Date: Wed, 4 Sep 2024 11:44:57 -0300 Subject: [PATCH 3/3] use low level --- crates/forge/tests/fixtures/zk/Deploy.s.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/forge/tests/fixtures/zk/Deploy.s.sol b/crates/forge/tests/fixtures/zk/Deploy.s.sol index 87745585c..9674514ce 100644 --- a/crates/forge/tests/fixtures/zk/Deploy.s.sol +++ b/crates/forge/tests/fixtures/zk/Deploy.s.sol @@ -5,13 +5,15 @@ import {Script} from "forge-std/Script.sol"; import {Greeter} from "../src/Greeter.sol"; contract DeployScript is Script { - Vm constant vm = Vm(HEVM_ADDRESS); + // Vm constant vm = Vm(HEVM_ADDRESS); Greeter greeter; string greeting; function run() external { - vm.zkVm(true); + // test is using old Vm.sol interface, so we call manually + (bool success,) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", true)); + require(success, "zkVm() call failed"); vm.startBroadcast(); greeter = new Greeter();