From f0d420ee60eb90402b09f4e3d142a933d18d1d99 Mon Sep 17 00:00:00 2001 From: Francesco Dainese Date: Wed, 27 Nov 2024 13:36:32 +0100 Subject: [PATCH] chore: fmt --- crates/cast/tests/cli/main.rs | 275 ++++++++++++++--------------- crates/cli/src/utils/cmd.rs | 10 +- crates/evm/core/src/backend/mod.rs | 2 +- crates/forge/bin/cmd/create.rs | 5 +- crates/zksync/core/src/lib.rs | 4 +- 5 files changed, 142 insertions(+), 154 deletions(-) diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index e2dd5b0bc..e99670c63 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -1414,37 +1414,32 @@ casttest!(block_number_hash, |_prj, cmd| { assert_eq!(s.trim().parse::().unwrap(), 1, "{s}") }); -casttest!( - send_eip7702, - async | _prj, - cmd | { - let (_api, handle) = anvil::spawn( - NodeConfig::test().with_hardfork(Some(EthereumHardfork::PragueEOF.into())), - ) - .await; - let endpoint = handle.http_endpoint(); - - cmd.args([ - "send", - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "--auth", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - "--private-key", - "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", - "--rpc-url", - &endpoint, - ]) - .assert_success(); +casttest!(send_eip7702, async |_prj, cmd| { + let (_api, handle) = + anvil::spawn(NodeConfig::test().with_hardfork(Some(EthereumHardfork::PragueEOF.into()))) + .await; + let endpoint = handle.http_endpoint(); - cmd.cast_fuse() - .args(["code", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "--rpc-url", &endpoint]) - .assert_success() - .stdout_eq(str![[r#" + cmd.args([ + "send", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "--auth", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "--private-key", + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", + "--rpc-url", + &endpoint, + ]) + .assert_success(); + + cmd.cast_fuse() + .args(["code", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "--rpc-url", &endpoint]) + .assert_success() + .stdout_eq(str![[r#" 0xef010070997970c51812dc3a010c7d01b50e0d17dc79c8 "#]]); - } -); +}); casttest!(hash_message, |_prj, cmd| { cmd.args(["hash-message", "hello"]).assert_success().stdout_eq(str![[r#" @@ -1607,67 +1602,64 @@ casttest!(fetch_artifact_from_etherscan, |_prj, cmd| { "#]]); }); -casttest!( - zk_cast_using_paymaster, - async | prj, - cmd | { - util::initialize(prj.root()); +casttest!(zk_cast_using_paymaster, async |prj, cmd| { + util::initialize(prj.root()); - let node = ZkSyncNode::start(); - let url = node.url(); + let node = ZkSyncNode::start(); + let url = node.url(); - let (addr, private_key) = ZkSyncNode::rich_wallets() - .next() - .map(|(addr, pk, _)| (addr, pk)) - .expect("No rich wallets available"); + let (addr, private_key) = ZkSyncNode::rich_wallets() + .next() + .map(|(addr, pk, _)| (addr, pk)) + .expect("No rich wallets available"); - // Deploy paymaster - cmd.args([ + // Deploy paymaster + cmd.args([ + "rpc", + "hardhat_setCode", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + PAYMASTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Deploy counter + cmd.cast_fuse() + .args([ "rpc", "hardhat_setCode", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + COUNTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Fund the paymaster + cmd.cast_fuse() + .args([ + "send", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - PAYMASTER_BYTECODE, + "0x", + "--value", + "0.1ether", + "--private-key", + private_key, "--rpc-url", &url, ]) .assert_success(); - // Deploy counter - cmd.cast_fuse() - .args([ - "rpc", - "hardhat_setCode", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - COUNTER_BYTECODE, - "--rpc-url", - &url, - ]) - .assert_success(); - - // Fund the paymaster - cmd.cast_fuse() - .args([ - "send", - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "0x", - "--value", - "0.1ether", - "--private-key", - private_key, - "--rpc-url", - &url, - ]) - .assert_success(); - - let balance_before = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); - - // Interact with the counter using the paymaster - cmd.cast_fuse().args([ + let balance_before = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + // Interact with the counter using the paymaster + cmd.cast_fuse().args([ "send", "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "increment()", @@ -1682,71 +1674,66 @@ casttest!( ]) .assert_success(); - let balance_after = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); + let balance_after = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); - assert_eq!(balance_after, balance_before); - } -); - -casttest!( - zk_cast_without_paymaster, - async | prj, - cmd | { - util::initialize(prj.root()); - - let node = ZkSyncNode::start(); - let url = node.url(); - - let (addr, private_key) = ZkSyncNode::rich_wallets() - .next() - .map(|(addr, pk, _)| (addr, pk)) - .expect("No rich wallets available"); - - // Deploy counter - cmd.cast_fuse() - .args([ - "rpc", - "hardhat_setCode", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - COUNTER_BYTECODE, - "--rpc-url", - &url, - ]) - .assert_success(); - - let balance_before = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); - - cmd.cast_fuse() - .args([ - "send", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - "increment()", - "--private-key", - private_key, - "--rpc-url", - &url, - "--gas-price", - "1000000000000002", - ]) - .assert_success(); - - let balance_after = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); - - assert!(balance_after != balance_before); - } -); + assert_eq!(balance_after, balance_before); +}); + +casttest!(zk_cast_without_paymaster, async |prj, cmd| { + util::initialize(prj.root()); + + let node = ZkSyncNode::start(); + let url = node.url(); + + let (addr, private_key) = ZkSyncNode::rich_wallets() + .next() + .map(|(addr, pk, _)| (addr, pk)) + .expect("No rich wallets available"); + + // Deploy counter + cmd.cast_fuse() + .args([ + "rpc", + "hardhat_setCode", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + COUNTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + let balance_before = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + cmd.cast_fuse() + .args([ + "send", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "increment()", + "--private-key", + private_key, + "--rpc-url", + &url, + "--gas-price", + "1000000000000002", + ]) + .assert_success(); + + let balance_after = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + assert!(balance_after != balance_before); +}); diff --git a/crates/cli/src/utils/cmd.rs b/crates/cli/src/utils/cmd.rs index 959fe6888..c2d1ed41e 100644 --- a/crates/cli/src/utils/cmd.rs +++ b/crates/cli/src/utils/cmd.rs @@ -7,8 +7,7 @@ use foundry_compilers::{ cache::{CacheEntry, CompilerCache}, utils::read_json_file, zksync::artifact_output::zk::ZkContractArtifact, - Artifact, ProjectCompileOutput, - ArtifactId + Artifact, ArtifactId, ProjectCompileOutput, }; use foundry_config::{error::ExtractConfigError, figment::Figment, Chain, Config, NamedChain}; use foundry_debugger::Debugger; @@ -92,9 +91,7 @@ pub fn remove_zk_contract( } }) else { let mut err = format!("could not find artifact: `{name}`"); - if let Some(suggestion) = - super::did_you_mean(name, other).pop() - { + if let Some(suggestion) = super::did_you_mean(name, other).pop() { if suggestion != name { err = format!( r#"{err} @@ -106,7 +103,8 @@ pub fn remove_zk_contract( eyre::bail!(err) }; - let contract = output.remove(id.source.as_ref(), &id.name).expect("contract found to exist in zk output"); + let contract = + output.remove(id.source.as_ref(), &id.name).expect("contract found to exist in zk output"); Ok((contract, id)) } diff --git a/crates/evm/core/src/backend/mod.rs b/crates/evm/core/src/backend/mod.rs index 1a9ace23a..82502bf52 100644 --- a/crates/evm/core/src/backend/mod.rs +++ b/crates/evm/core/src/backend/mod.rs @@ -9,9 +9,9 @@ use crate::{ }; use alloy_consensus::Transaction as TransactionTrait; use alloy_genesis::GenesisAccount; +use alloy_network::{AnyRpcBlock, AnyTxEnvelope, TransactionResponse}; use alloy_primitives::{keccak256, map::HashMap, uint, Address, B256, U256}; use alloy_rpc_types::{BlockNumberOrTag, Transaction, TransactionRequest}; -use alloy_network::{AnyRpcBlock, AnyTxEnvelope, TransactionResponse}; use eyre::Context; use foundry_common::{is_known_system_sender, SYSTEM_TRANSACTION_TYPE}; pub use foundry_fork_db::{cache::BlockchainDbMeta, BlockchainDb, SharedBackend}; diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 771e2fea5..c919ed7f1 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -22,7 +22,7 @@ use foundry_common::{ }; use foundry_compilers::{ artifacts::BytecodeObject, info::ContractInfo, utils::canonicalize, - zksync::artifact_output::zk::ZkContractArtifact, ArtifactId + zksync::artifact_output::zk::ZkContractArtifact, ArtifactId, }; use foundry_config::{ figment::{ @@ -153,7 +153,8 @@ impl CreateArgs { let zk_compiler = ProjectCompiler::new().files([target_path.clone()]); let mut zk_output = zk_compiler.zksync_compile(&zk_project)?; - let (artifact, id) = remove_zk_contract(&mut zk_output, &target_path, &self.contract.name)?; + let (artifact, id) = + remove_zk_contract(&mut zk_output, &target_path, &self.contract.name)?; let ZkContractArtifact { bytecode, hash, factory_dependencies, abi, .. } = artifact; diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index e03fbad72..9a8fcaa85 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -19,7 +19,9 @@ pub mod vm; pub mod state; use alloy_network::{AnyNetwork, TxSigner}; -use alloy_primitives::{address, hex, keccak256, Address, Bytes, PrimitiveSignature, U256 as rU256}; +use alloy_primitives::{ + address, hex, keccak256, Address, Bytes, PrimitiveSignature, U256 as rU256, +}; use alloy_provider::Provider; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields;