From 6a3dc4feb14e142c63c82b244a1b5e5d3e3c9fce Mon Sep 17 00:00:00 2001 From: Juan Rigada <62958725+Jrigada@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:11:28 -0300 Subject: [PATCH] test: Added testing of multiple deploy of same contract (#555) * Added testing of multiple deploy of same contract * Change low level call to zkvm * use low level --------- Co-authored-by: Jrigada --- 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 084d6b085..c9bf37f79 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;