Skip to content

Commit e7390e0

Browse files
authored
chore: Move zk tests to different files (#775)
* Add zkout to gitignore template when in zksync forge init mode * Add test for forge init --zksync * Move zk test to a different file to avoid merge conflicts * Move aave test outside the file
1 parent 4a81422 commit e7390e0

File tree

12 files changed

+400
-372
lines changed

12 files changed

+400
-372
lines changed

crates/cast/tests/cli/main.rs

Lines changed: 1 addition & 137 deletions
Large diffs are not rendered by default.

crates/cast/tests/cli/zk.rs

Lines changed: 137 additions & 0 deletions
Large diffs are not rendered by default.

crates/forge/tests/cli/build.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::utils::generate_large_contract;
22
use foundry_config::Config;
3-
use foundry_test_utils::{forgetest, snapbox::IntoData, str, util::OutputExt};
3+
use foundry_test_utils::{forgetest, snapbox::IntoData, str};
44
use globset::Glob;
5-
use regex::Regex;
65

76
forgetest_init!(can_parse_build_filters, |prj, cmd| {
87
prj.clear();
@@ -166,17 +165,6 @@ forgetest_init!(build_sizes_no_forge_std, |prj, cmd| {
166165
);
167166
});
168167

169-
// tests build output is as expected in zksync mode
170-
forgetest_init!(test_zk_build_sizes, |prj, cmd| {
171-
cmd.args(["build", "--sizes", "--zksync", "--evm-version", "shanghai"]);
172-
let stdout = cmd.assert_success().get_output().stdout_lossy();
173-
let pattern =
174-
Regex::new(r"\|\s*Counter\s*\|\s*800\s*\|\s*800\s*\|\s*450,199\s*\|\s*450,199\s*\|")
175-
.unwrap();
176-
177-
assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}");
178-
});
179-
180168
// tests that skip key in config can be used to skip non-compilable contract
181169
forgetest_init!(test_can_skip_contract, |prj, cmd| {
182170
prj.add_source(

crates/forge/tests/cli/cmd.rs

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,78 +2676,6 @@ Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
26762676
);
26772677
});
26782678

2679-
forgetest!(zk_gas_report, |prj, cmd| {
2680-
prj.insert_ds_test();
2681-
prj.add_source(
2682-
"Contracts.sol",
2683-
r#"
2684-
//SPDX-license-identifier: MIT
2685-
2686-
import "./test.sol";
2687-
2688-
contract ContractOne {
2689-
int public i;
2690-
2691-
constructor() {
2692-
i = 0;
2693-
}
2694-
2695-
function foo() public{
2696-
while(i<5){
2697-
i++;
2698-
}
2699-
}
2700-
}
2701-
2702-
contract ContractOneTest is DSTest {
2703-
ContractOne c1;
2704-
2705-
function setUp() public {
2706-
c1 = new ContractOne();
2707-
}
2708-
2709-
function testFoo() public {
2710-
c1.foo();
2711-
}
2712-
}
2713-
"#,
2714-
)
2715-
.unwrap();
2716-
2717-
prj.write_config(Config {
2718-
gas_reports: (vec!["*".to_string()]),
2719-
gas_reports_ignore: (vec![]),
2720-
..Default::default()
2721-
});
2722-
let out = cmd.arg("test").arg("--gas-report").assert_success().get_output().stdout_lossy();
2723-
cmd.forge_fuse();
2724-
let out_zk = cmd
2725-
.arg("test")
2726-
.arg("--gas-report")
2727-
.arg("--zksync")
2728-
.assert_success()
2729-
.get_output()
2730-
.stdout_lossy();
2731-
2732-
let mut cells = out.split('|');
2733-
let deployment_cost: u64 = cells.nth(22).unwrap().trim().parse().unwrap();
2734-
let deployment_size: u64 = cells.next().unwrap().trim().parse().unwrap();
2735-
let function = cells.nth(12).unwrap().trim();
2736-
let gas: u64 = cells.next().unwrap().trim().parse().unwrap();
2737-
2738-
let mut cells_zk = out_zk.split('|');
2739-
let deployment_cost_zk: u64 = cells_zk.nth(22).unwrap().trim().parse().unwrap();
2740-
let deployment_size_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap();
2741-
let function_zk = cells_zk.nth(12).unwrap().trim();
2742-
let gas_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap();
2743-
2744-
assert!(deployment_cost_zk > deployment_cost);
2745-
assert!(deployment_size_zk > deployment_size);
2746-
assert!(gas_zk > gas);
2747-
assert_eq!(function, "foo");
2748-
assert_eq!(function_zk, "foo");
2749-
});
2750-
27512679
forgetest_init!(can_use_absolute_imports, |prj, cmd| {
27522680
let remapping = prj.paths().libraries[0].join("myDependency");
27532681
let config = Config {

crates/forge/tests/cli/ext_integration.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,3 @@ fn convex_shutdown_simulation() {
146146
.fork_block(14445961)
147147
.run();
148148
}
149-
150-
#[test]
151-
fn test_zk_aave_di() {
152-
ExtTester::new("Moonsong-Labs", "aave-delivery-infrastructure", "ci")
153-
.args(["--zksync", "--skip", "\"*/PayloadScripts.t.sol\""])
154-
.run()
155-
}

crates/forge/tests/cli/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ mod verify;
2626
mod verify_bytecode;
2727

2828
mod ext_integration;
29+
mod zk_build;
30+
mod zk_cmd;
31+
mod zk_ext_integration;
32+
mod zk_script;

crates/forge/tests/cli/script.rs

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use anvil::{spawn, NodeConfig};
66
use forge_script_sequence::ScriptSequence;
77
use foundry_test_utils::{
88
rpc,
9-
util::{OutputExt, OTHER_SOLC_VERSION, SOLC_VERSION},
9+
util::{OTHER_SOLC_VERSION, SOLC_VERSION},
1010
ScriptOutcome, ScriptTester,
1111
};
1212
use regex::Regex;
@@ -2037,114 +2037,6 @@ forgetest_async!(can_deploy_library_create2_different_sender, |prj, cmd| {
20372037
.await;
20382038
});
20392039

2040-
forgetest_async!(test_zk_can_execute_script_with_arguments, |prj, cmd| {
2041-
#[derive(serde::Deserialize, Debug)]
2042-
#[allow(dead_code)]
2043-
struct ZkTransactions {
2044-
transactions: Vec<ZkTransaction>,
2045-
}
2046-
2047-
#[derive(serde::Deserialize, Debug)]
2048-
#[allow(dead_code)]
2049-
struct ZkTransaction {
2050-
zk: Zk,
2051-
}
2052-
2053-
#[derive(serde::Deserialize, Debug)]
2054-
#[serde(rename_all = "camelCase")]
2055-
#[allow(dead_code)]
2056-
struct Zk {
2057-
#[serde(default)]
2058-
factory_deps: Vec<Vec<u8>>,
2059-
}
2060-
2061-
let node = foundry_test_utils::ZkSyncNode::start();
2062-
2063-
cmd.args(["init", "--force"]).arg(prj.root());
2064-
cmd.assert_success();
2065-
cmd.forge_fuse();
2066-
2067-
prj.add_script(
2068-
"Deploy.s.sol",
2069-
r#"
2070-
pragma solidity ^0.8.18;
2071-
2072-
import {Script} from "forge-std/Script.sol";
2073-
2074-
contract Greeter {
2075-
string name;
2076-
uint256 age;
2077-
2078-
event Greet(string greet);
2079-
2080-
function greeting(string memory _name) public returns (string memory) {
2081-
name = _name;
2082-
string memory greet = string(abi.encodePacked("Hello ", _name));
2083-
emit Greet(greet);
2084-
return greet;
2085-
}
2086-
2087-
function setAge(uint256 _age) public {
2088-
age = _age;
2089-
}
2090-
2091-
function getAge() public view returns (uint256) {
2092-
return age;
2093-
}
2094-
}
2095-
2096-
contract DeployScript is Script {
2097-
Greeter greeter;
2098-
string greeting;
2099-
2100-
function run() external {
2101-
// test is using old Vm.sol interface, so we call manually
2102-
address(vm).call(abi.encodeWithSignature("zkVm(bool)", true));
2103-
2104-
vm.startBroadcast();
2105-
greeter = new Greeter();
2106-
greeter.greeting("john");
2107-
greeter.setAge(123);
2108-
vm.stopBroadcast();
2109-
}
2110-
}
2111-
"#,
2112-
)
2113-
.unwrap();
2114-
2115-
cmd.arg("script").args([
2116-
"--zksync",
2117-
"DeployScript",
2118-
"--broadcast",
2119-
"--private-key",
2120-
"0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e",
2121-
"--chain",
2122-
"260",
2123-
"--gas-estimate-multiplier",
2124-
"310",
2125-
"--rpc-url",
2126-
node.url().as_str(),
2127-
"--slow",
2128-
"--evm-version",
2129-
"shanghai",
2130-
]);
2131-
2132-
cmd.assert_success()
2133-
.get_output()
2134-
.stdout_lossy()
2135-
.contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL");
2136-
2137-
let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast").as_path())
2138-
.find(|file| file.ends_with("run-latest.json"))
2139-
.expect("No broadcast artifacts");
2140-
2141-
let content = foundry_common::fs::read_to_string(run_latest).unwrap();
2142-
2143-
let transactions: ZkTransactions = serde_json::from_str(&content).unwrap();
2144-
let transactions = transactions.transactions;
2145-
assert_eq!(transactions.len(), 3);
2146-
});
2147-
21482040
// <https://github.com/foundry-rs/foundry/issues/8993>
21492041
forgetest_async!(test_broadcast_raw_create2_deployer, |prj, cmd| {
21502042
let (_api, handle) =

crates/forge/tests/cli/test_cmd.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,40 +1339,6 @@ Traces:
13391339
]]);
13401340
});
13411341

1342-
// Related to: https://github.com/matter-labs/foundry-zksync/issues/478
1343-
forgetest_async!(test_zk_can_detect_call_to_empty_contract, |prj, cmd| {
1344-
foundry_test_utils::util::initialize(prj.root());
1345-
1346-
prj.add_test(
1347-
"CallEmptyCode.t.sol",
1348-
r#"
1349-
import "forge-std/Test.sol";
1350-
1351-
// https://github.com/matter-labs/foundry-zksync/issues/478
1352-
contract CallEmptyCode is Test {
1353-
// This test should make our EraVM tracer print out an ERROR trace
1354-
function testFailDetectEmptyCodeContracts() external {
1355-
address mockMe = address(123456789);
1356-
1357-
vm.mockCall(mockMe, abi.encodeWithSignature("foo()"), abi.encode(42));
1358-
1359-
(bool success, bytes memory ret) = mockMe.call(abi.encodeWithSignature("bar()"));
1360-
1361-
require(success, "callMethod failed");
1362-
require(keccak256(ret) == keccak256(abi.encode(42)), "return not as expected");
1363-
}
1364-
}
1365-
"#,
1366-
)
1367-
.unwrap();
1368-
cmd.args(["test", "--zksync", "--evm-version", "shanghai", "--mc", "CallEmptyCode"]);
1369-
1370-
cmd.assert_success()
1371-
.get_output()
1372-
.stdout_lossy()
1373-
.contains("call may fail or behave unexpectedly due to empty code");
1374-
});
1375-
13761342
// tests that `forge test` with a seed produces deterministic random values for uint and addresses.
13771343
forgetest_init!(deterministic_randomness_with_seed, |prj, cmd| {
13781344
prj.wipe_contracts();

crates/forge/tests/cli/zk_build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use foundry_test_utils::util::OutputExt;
2+
use regex::Regex;
3+
4+
// tests build output is as expected in zksync mode
5+
forgetest_init!(test_zk_build_sizes, |prj, cmd| {
6+
cmd.args(["build", "--sizes", "--zksync", "--evm-version", "shanghai"]);
7+
let stdout = cmd.assert_success().get_output().stdout_lossy();
8+
let pattern =
9+
Regex::new(r"\|\s*Counter\s*\|\s*800\s*\|\s*800\s*\|\s*450,199\s*\|\s*450,199\s*\|")
10+
.unwrap();
11+
12+
assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}");
13+
});

0 commit comments

Comments
 (0)