Skip to content

Commit

Permalink
Merge branch 'dev' into upstream-62cdea
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrigada authored Jul 26, 2024
2 parents 12f8f94 + 4f2145e commit a552e6b
Show file tree
Hide file tree
Showing 16 changed files with 505 additions and 72 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ jobs:
# - name: Test ZK VM
# run: RUST_LOG=1 cargo test --package forge --test it --jobs=1 -- zk

zk-cargo-test:
name: zk-cargo-test
runs-on: ubuntu-22.04-github-hosted-16core

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-04-28

- name: Run zk tests
env:
RUST_BACKTRACE: full
run: cargo test zk

zk-smoke-test:
name: zk-smoke-test
runs-on: ubuntu-22.04-github-hosted-16core
Expand Down
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ alloy-rlp = "0.3.3"
alloy-trie = "0.4.1"

## zksync
era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "1d72eae6e9400b5b6caed5e60093e7c32eee8abb" }
era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "dd6d2f463eb9697dc2365899a72ae12dae3ec809" }
zksync-web3-rs = {git = "https://github.com/lambdaclass/zksync-web3-rs.git", rev = "fd7adf634c016f40ea01f702e0e05f57aa5ba614"}
zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
Expand Down
4 changes: 2 additions & 2 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl Cheatcodes {
data.env.block.timestamp = U256::from(block_timestamp);

let test_contract = data.db.get_test_contract_address();
for address in data.db.persistent_accounts() {
for address in data.db.persistent_accounts().into_iter().chain([data.env.tx.caller]) {
info!(?address, "importing to evm state");

let zk_address = address.to_h160();
Expand Down Expand Up @@ -648,7 +648,7 @@ impl Cheatcodes {
let mut known_codes_storage: rHashMap<U256, EvmStorageSlot> = Default::default();
let mut deployed_codes: HashMap<Address, AccountInfo> = Default::default();

for address in data.db.persistent_accounts() {
for address in data.db.persistent_accounts().into_iter().chain([data.env.tx.caller]) {
info!(?address, "importing to zk state");

let account = journaled_account(data, address).expect("failed to load account");
Expand Down
5 changes: 5 additions & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ tikv-jemallocator = { workspace = true, optional = true }
anvil.workspace = true
foundry-test-utils.workspace = true

# zk
era_test_node.workspace = true
jsonrpc-core = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-http-server = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }

mockall = "0.12"
criterion = "0.5"
paste = "1.0"
Expand Down
2 changes: 2 additions & 0 deletions crates/forge/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ mod svm;
mod test_cmd;
mod verify;

mod zksync_node;

mod ext_integration;
104 changes: 103 additions & 1 deletion crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains various tests related to `forge script`.
use crate::constants::TEMPLATE_CONTRACT;
use crate::{constants::TEMPLATE_CONTRACT, zksync_node};
use alloy_primitives::{hex, Address, Bytes};
use anvil::{spawn, NodeConfig};
use foundry_test_utils::{rpc, util::OutputExt, ScriptOutcome, ScriptTester};
Expand Down Expand Up @@ -1451,3 +1451,105 @@ forgetest_async!(can_deploy_library_create2_different_sender, |prj, cmd| {
.assert_nonce_increment(&[(2, 2)])
.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 {
factory_deps: Vec<Vec<u8>>,
}

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

cmd.args(["init", "--force"]).arg(prj.root());
cmd.assert_non_empty_stdout();
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",
]);

assert!(cmd.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);
});
Loading

0 comments on commit a552e6b

Please sign in to comment.