Skip to content

Commit

Permalink
Merge branch 'main' into debug-cron-for-aave
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrigada authored Dec 13, 2024
2 parents b01b49c + e7390e0 commit 2a7a195
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 399 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,18 @@ jobs:
run: cp ./install-foundry-zksync ./foundryup-zksync/* /tmp/ && cd /tmp && ./install-foundry-zksync
- name: Verify installation
run: forge --version

check-ci-install-anvil:
name: CI install anvil-zksync
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Install foundry-zksync
run: |
cp ./install-foundry-zksync ./foundryup-zksync/* /tmp/
cd /tmp
./install-foundry-zksync
- name: Verify anvil-zksync installation
run: anvil-zksync --version
138 changes: 1 addition & 137 deletions crates/cast/tests/cli/main.rs

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions crates/cast/tests/cli/zk.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,9 @@ where
)
.map_err(|_| ContractDeploymentError::TransactionBuildError)?;

// NOTE(zk): We need to prepare the tx for submission to set the tx type to EIP712
tx.prep_for_submission();

Ok(ZkDeployer {
client: self.client.clone(),
abi: self.abi,
Expand Down
14 changes: 1 addition & 13 deletions crates/forge/tests/cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::utils::generate_large_contract;
use foundry_config::Config;
use foundry_test_utils::{forgetest, snapbox::IntoData, str, util::OutputExt};
use foundry_test_utils::{forgetest, snapbox::IntoData, str};
use globset::Glob;
use regex::Regex;

forgetest_init!(can_parse_build_filters, |prj, cmd| {
prj.clear();
Expand Down Expand Up @@ -166,17 +165,6 @@ forgetest_init!(build_sizes_no_forge_std, |prj, cmd| {
);
});

// tests build output is as expected in zksync mode
forgetest_init!(test_zk_build_sizes, |prj, cmd| {
cmd.args(["build", "--sizes", "--zksync", "--evm-version", "shanghai"]);
let stdout = cmd.assert_success().get_output().stdout_lossy();
let pattern =
Regex::new(r"\|\s*Counter\s*\|\s*800\s*\|\s*800\s*\|\s*450,199\s*\|\s*450,199\s*\|")
.unwrap();

assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}");
});

// tests that skip key in config can be used to skip non-compilable contract
forgetest_init!(test_can_skip_contract, |prj, cmd| {
prj.add_source(
Expand Down
72 changes: 0 additions & 72 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2676,78 +2676,6 @@ Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
);
});

forgetest!(zk_gas_report, |prj, cmd| {
prj.insert_ds_test();
prj.add_source(
"Contracts.sol",
r#"
//SPDX-license-identifier: MIT
import "./test.sol";
contract ContractOne {
int public i;
constructor() {
i = 0;
}
function foo() public{
while(i<5){
i++;
}
}
}
contract ContractOneTest is DSTest {
ContractOne c1;
function setUp() public {
c1 = new ContractOne();
}
function testFoo() public {
c1.foo();
}
}
"#,
)
.unwrap();

prj.write_config(Config {
gas_reports: (vec!["*".to_string()]),
gas_reports_ignore: (vec![]),
..Default::default()
});
let out = cmd.arg("test").arg("--gas-report").assert_success().get_output().stdout_lossy();
cmd.forge_fuse();
let out_zk = cmd
.arg("test")
.arg("--gas-report")
.arg("--zksync")
.assert_success()
.get_output()
.stdout_lossy();

let mut cells = out.split('|');
let deployment_cost: u64 = cells.nth(22).unwrap().trim().parse().unwrap();
let deployment_size: u64 = cells.next().unwrap().trim().parse().unwrap();
let function = cells.nth(12).unwrap().trim();
let gas: u64 = cells.next().unwrap().trim().parse().unwrap();

let mut cells_zk = out_zk.split('|');
let deployment_cost_zk: u64 = cells_zk.nth(22).unwrap().trim().parse().unwrap();
let deployment_size_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap();
let function_zk = cells_zk.nth(12).unwrap().trim();
let gas_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap();

assert!(deployment_cost_zk > deployment_cost);
assert!(deployment_size_zk > deployment_size);
assert!(gas_zk > gas);
assert_eq!(function, "foo");
assert_eq!(function_zk, "foo");
});

forgetest_init!(can_use_absolute_imports, |prj, cmd| {
let remapping = prj.paths().libraries[0].join("myDependency");
let config = Config {
Expand Down
7 changes: 0 additions & 7 deletions crates/forge/tests/cli/ext_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,3 @@ fn convex_shutdown_simulation() {
.fork_block(14445961)
.run();
}

#[test]
fn test_zk_aave_di() {
ExtTester::new("Moonsong-Labs", "aave-delivery-infrastructure", "ci")
.args(["--zksync", "--skip", "\"*/PayloadScripts.t.sol\""])
.run()
}
4 changes: 4 additions & 0 deletions crates/forge/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ mod verify;
mod verify_bytecode;

mod ext_integration;
mod zk_build;
mod zk_cmd;
mod zk_ext_integration;
mod zk_script;
110 changes: 1 addition & 109 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anvil::{spawn, NodeConfig};
use forge_script_sequence::ScriptSequence;
use foundry_test_utils::{
rpc,
util::{OutputExt, OTHER_SOLC_VERSION, SOLC_VERSION},
util::{OTHER_SOLC_VERSION, SOLC_VERSION},
ScriptOutcome, ScriptTester,
};
use regex::Regex;
Expand Down Expand Up @@ -2037,114 +2037,6 @@ forgetest_async!(can_deploy_library_create2_different_sender, |prj, cmd| {
.await;
});

forgetest_async!(test_zk_can_execute_script_with_arguments, |prj, cmd| {
#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ZkTransactions {
transactions: Vec<ZkTransaction>,
}

#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ZkTransaction {
zk: Zk,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
struct Zk {
#[serde(default)]
factory_deps: Vec<Vec<u8>>,
}

let node = foundry_test_utils::ZkSyncNode::start();

cmd.args(["init", "--force"]).arg(prj.root());
cmd.assert_success();
cmd.forge_fuse();

prj.add_script(
"Deploy.s.sol",
r#"
pragma solidity ^0.8.18;
import {Script} from "forge-std/Script.sol";
contract Greeter {
string name;
uint256 age;
event Greet(string greet);
function greeting(string memory _name) public returns (string memory) {
name = _name;
string memory greet = string(abi.encodePacked("Hello ", _name));
emit Greet(greet);
return greet;
}
function setAge(uint256 _age) public {
age = _age;
}
function getAge() public view returns (uint256) {
return age;
}
}
contract DeployScript is Script {
Greeter greeter;
string greeting;
function run() external {
// test is using old Vm.sol interface, so we call manually
address(vm).call(abi.encodeWithSignature("zkVm(bool)", true));
vm.startBroadcast();
greeter = new Greeter();
greeter.greeting("john");
greeter.setAge(123);
vm.stopBroadcast();
}
}
"#,
)
.unwrap();

cmd.arg("script").args([
"--zksync",
"DeployScript",
"--broadcast",
"--private-key",
"0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e",
"--chain",
"260",
"--gas-estimate-multiplier",
"310",
"--rpc-url",
node.url().as_str(),
"--slow",
"--evm-version",
"shanghai",
]);

cmd.assert_success()
.get_output()
.stdout_lossy()
.contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL");

let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast").as_path())
.find(|file| file.ends_with("run-latest.json"))
.expect("No broadcast artifacts");

let content = foundry_common::fs::read_to_string(run_latest).unwrap();

let transactions: ZkTransactions = serde_json::from_str(&content).unwrap();
let transactions = transactions.transactions;
assert_eq!(transactions.len(), 3);
});

// <https://github.com/foundry-rs/foundry/issues/8993>
forgetest_async!(test_broadcast_raw_create2_deployer, |prj, cmd| {
let (_api, handle) =
Expand Down
34 changes: 0 additions & 34 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,40 +1339,6 @@ Traces:
]]);
});

// Related to: https://github.com/matter-labs/foundry-zksync/issues/478
forgetest_async!(test_zk_can_detect_call_to_empty_contract, |prj, cmd| {
foundry_test_utils::util::initialize(prj.root());

prj.add_test(
"CallEmptyCode.t.sol",
r#"
import "forge-std/Test.sol";
// https://github.com/matter-labs/foundry-zksync/issues/478
contract CallEmptyCode is Test {
// This test should make our EraVM tracer print out an ERROR trace
function testFailDetectEmptyCodeContracts() external {
address mockMe = address(123456789);
vm.mockCall(mockMe, abi.encodeWithSignature("foo()"), abi.encode(42));
(bool success, bytes memory ret) = mockMe.call(abi.encodeWithSignature("bar()"));
require(success, "callMethod failed");
require(keccak256(ret) == keccak256(abi.encode(42)), "return not as expected");
}
}
"#,
)
.unwrap();
cmd.args(["test", "--zksync", "--evm-version", "shanghai", "--mc", "CallEmptyCode"]);

cmd.assert_success()
.get_output()
.stdout_lossy()
.contains("call may fail or behave unexpectedly due to empty code");
});

// tests that `forge test` with a seed produces deterministic random values for uint and addresses.
forgetest_init!(deterministic_randomness_with_seed, |prj, cmd| {
prj.wipe_contracts();
Expand Down
13 changes: 13 additions & 0 deletions crates/forge/tests/cli/zk_build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use foundry_test_utils::util::OutputExt;
use regex::Regex;

// tests build output is as expected in zksync mode
forgetest_init!(test_zk_build_sizes, |prj, cmd| {
cmd.args(["build", "--sizes", "--zksync", "--evm-version", "shanghai"]);
let stdout = cmd.assert_success().get_output().stdout_lossy();
let pattern =
Regex::new(r"\|\s*Counter\s*\|\s*800\s*\|\s*800\s*\|\s*450,199\s*\|\s*450,199\s*\|")
.unwrap();

assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}");
});
Loading

0 comments on commit 2a7a195

Please sign in to comment.