Skip to content

Commit

Permalink
test: Added testing of multiple deploy of same contract (#555)
Browse files Browse the repository at this point in the history
* Added testing of multiple deploy of same contract

* Change low level call to zkvm

* use low level

---------

Co-authored-by: Jrigada <[email protected]>
  • Loading branch information
Jrigada and Jrigada authored Sep 4, 2024
1 parent 71ae07e commit 6a3dc4f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/forge/tests/fixtures/zk/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
31 changes: 31 additions & 0 deletions crates/forge/tests/it/zk/deploy.rs
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions crates/forge/tests/it/zk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod basic;
mod cheats;
mod contracts;
mod create;
mod deploy;
mod factory;
mod factory_deps;
mod fork;
Expand Down

0 comments on commit 6a3dc4f

Please sign in to comment.