Skip to content

Commit

Permalink
Merge branch 'main' into upstream-59f354c-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
elfedy committed Dec 13, 2024
2 parents 4721908 + 68fcb7d commit b8ee6fe
Show file tree
Hide file tree
Showing 15 changed files with 468 additions and 407 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,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.

27 changes: 21 additions & 6 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub struct CreateArgs {
retry: RetryArgs,
}

#[derive(Debug, Default)]
/// Data used to deploy a contract on zksync
pub struct ZkSyncData {
#[allow(dead_code)]
Expand Down Expand Up @@ -1156,12 +1157,8 @@ where
Some(constructor) => constructor.abi_encode_input(&params).unwrap_or_default(),
};

let mut tx: alloy_zksync::network::transaction_request::TransactionRequest =
TransactionRequest::default()
.to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address())
.into();

tx = tx
let tx = alloy_zksync::network::transaction_request::TransactionRequest::default()
.with_to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address())
.with_create_params(
zk_data.bytecode.clone(),
constructor_args,
Expand Down Expand Up @@ -1207,6 +1204,8 @@ impl From<PendingTransactionError> for ContractDeploymentError {
mod tests {
use super::*;
use alloy_primitives::I256;
use alloy_zksync::network::tx_type::TxType;
use utils::get_provider_zksync;

#[test]
fn can_parse_create() {
Expand Down Expand Up @@ -1275,4 +1274,20 @@ mod tests {
let params = args.parse_constructor_args(&constructor, &args.constructor_args).unwrap();
assert_eq!(params, vec![DynSolValue::Int(I256::unchecked_from(-5), 256)]);
}

#[test]
fn test_zk_deployer_builds_eip712_transactions() {
let client = get_provider_zksync(&Default::default()).expect("failed creating client");
let factory =
DeploymentTxFactory::new_zk(Default::default(), Default::default(), client, 0);

let deployer = factory
.deploy_tokens_zk(
Default::default(),
&ZkSyncData { bytecode: [0u8; 32].into(), ..Default::default() },
)
.expect("failed deploying tokens");

assert_eq!(TxType::Eip712, deployer.tx.output_tx_type());
}
}
17 changes: 1 addition & 16 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 @@ -179,20 +178,6 @@ forgetest_init!(build_sizes_no_forge_std, |prj, cmd| {
"#]]
.is_json(),
);
<<<<<<< HEAD
=======
});

// 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}");
>>>>>>> main
});

// tests that skip key in config can be used to skip non-compilable contract
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 @@ -2870,78 +2870,6 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
);
});

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 @@ -147,10 +147,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 @@ -28,3 +28,7 @@ mod verify;
mod verify_bytecode;

mod ext_integration;
mod zk_build;
mod zk_cmd;
mod zk_ext_integration;
mod zk_script;
108 changes: 0 additions & 108 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,114 +2180,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) = spawn(NodeConfig::test().with_disable_default_create2_deployer(true)).await;
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 b8ee6fe

Please sign in to comment.