Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Jul 10, 2024
1 parent 233707f commit 1b1e9b6
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 162 deletions.
48 changes: 8 additions & 40 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl Cheatcodes {
tracing::trace!(?address, "ignoring code translation for test contract");
} else {
account.info.code_hash = code_hash;
account.info.code = code.clone();
account.info.code.clone_from(&code);
}
}
}
Expand Down Expand Up @@ -624,7 +624,7 @@ impl Cheatcodes {
tracing::trace!(?address, "ignoring code translation for test contract");
} else {
account.info.code_hash = info.code_hash;
account.info.code = info.code.clone();
account.info.code.clone_from(&info.code);
}
}
}
Expand Down Expand Up @@ -1407,7 +1407,7 @@ impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
persisted_factory_deps: Some(&mut self.persisted_factory_deps),
};
if let Ok(result) = foundry_zksync_core::vm::call::<_, DatabaseError>(call, ecx, ccx) {
self.combined_logs.extend(result.logs.clone().into_iter().map(|log| Some(log)));
self.combined_logs.extend(result.logs.clone().into_iter().map(Some));
//for each log in cloned logs call handle_expect_emit
if !self.expected_emits.is_empty() {
for log in result.logs {
Expand Down Expand Up @@ -1788,7 +1788,7 @@ impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
let mut nonce = account.info.nonce;
let mut call_init_code = call.init_code.clone();

let mut zk_tx = if self.use_zk_vm {
let zk_tx = if self.use_zk_vm {
to = Some(TxKind::Call(CONTRACT_DEPLOYER_ADDRESS.to_address()));
nonce = foundry_zksync_core::nonce(broadcast.new_origin, ecx) as u64;
let contract = self
Expand All @@ -1810,45 +1810,13 @@ impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
);
call_init_code = Bytes::from(create_input);

Some(factory_deps)
Some(ZkTransactionMetadata { factory_deps })
} else {
None
};

let rpc = ecx.db.active_fork_url();
if let Some(factory_deps) = zk_tx {
let mut batched =
foundry_zksync_core::vm::batch_factory_dependencies(factory_deps);
debug!(batches = batched.len(), "splitting factory deps for broadcast");
// the last batch is the final one that does the deployment
zk_tx = batched.pop();

for factory_deps in batched {
self.broadcastable_transactions.push_back(BroadcastableTransaction {
rpc: rpc.clone(),
transaction: TransactionRequest {
from: Some(broadcast.new_origin),
to: Some(TxKind::Call(Address::ZERO)),
value: Some(call.value),
input: TransactionInput::default(),
nonce: Some(nonce),
gas: if is_fixed_gas_limit {
Some(call.gas_limit as u128)
} else {
None
},
..Default::default()
},
zk_tx: Some(ZkTransactionMetadata { factory_deps }),
});

//update nonce for each tx
nonce += 1;
}
}

self.broadcastable_transactions.push_back(BroadcastableTransaction {
rpc: rpc.clone(),
rpc: ecx.db.active_fork_url(),
transaction: TransactionRequest {
from: Some(broadcast.new_origin),
to,
Expand All @@ -1862,7 +1830,7 @@ impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
},
..Default::default()
},
zk_tx: zk_tx.map(|factory_deps| ZkTransactionMetadata { factory_deps }),
zk_tx,
});

let kind = match call.scheme {
Expand Down Expand Up @@ -1930,7 +1898,7 @@ impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
ecx,
ccx,
) {
self.combined_logs.extend(result.logs.clone().into_iter().map(|log| Some(log)));
self.combined_logs.extend(result.logs.clone().into_iter().map(Some));

// for each log in cloned logs call handle_expect_emit
if !self.expected_emits.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/core/src/backend/fork_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub enum ForkType {
impl ForkType {
/// Returns true if type is [ForkType::Zk]
pub fn is_zk(&self) -> bool {
matches!(self, ForkType::Zk)
matches!(self, Self::Zk)
}

/// Returns true if type is [ForkType::Evm]
pub fn is_evm(&self) -> bool {
matches!(self, ForkType::Evm)
matches!(self, Self::Evm)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/evm/fuzz/src/strategies/calldata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod tests {
);

let expected = function.abi_encode_input(&[address_fixture]).unwrap();
let strategy = fuzz_calldata(function, &FuzzFixtures::new(fixtures));
let strategy = fuzz_calldata(function, &FuzzFixtures::new(fixtures), false);
let _ = strategy.prop_map(move |fuzzed| {
assert_eq!(expected, fuzzed);
});
Expand Down
15 changes: 13 additions & 2 deletions crates/evm/fuzz/src/strategies/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ fn fuzz_param_inner(
};

match *param {
DynSolType::Address => value(),
DynSolType::Address => value()
.prop_map(move |value| match value.as_address() {
Some(addr) => {
if no_zksync_reserved_addresses {
DynSolValue::Address(foundry_zksync_core::to_safe_address(addr))
} else {
DynSolValue::Address(addr)
}
}
None => value,
})
.boxed(),
DynSolType::Int(n @ 8..=256) => super::IntStrategy::new(n, fuzz_fixtures)
.prop_map(move |x| DynSolValue::Int(x, n))
.boxed(),
Expand Down Expand Up @@ -139,7 +150,7 @@ pub fn fuzz_param_from_state(
match *param {
DynSolType::Address => value()
.prop_map(move |value| {
let addr = Address::from_word(value.into());
let addr = Address::from_word(value);
if no_zksync_reserved_addresses {
DynSolValue::Address(foundry_zksync_core::to_safe_address(addr))
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/traces/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub fn load_contracts<'a>(
deployments: &HashMap<Address, Bytes>,
) -> ContractsByAddress {
let mut local_identifier = LocalTraceIdentifier::new(known_contracts);
local_identifier.deployments = deployments.clone();
local_identifier.deployments.clone_from(deployments);
let decoder = CallTraceDecoder::new();
let mut contracts = ContractsByAddress::new();
for trace in traces {
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ impl CreateArgs {
let fdep_art =
zk_output.find(abs_path_str, contract_name).unwrap_or_else(|| {
panic!(
"Could not find contract {} at path {} for compilation output",
contract_name, contract_path
"Could not find contract {contract_name} at path {contract_path} for compilation output",
)
});
let fdep_fdeps_map =
Expand Down Expand Up @@ -513,6 +512,7 @@ impl CreateArgs {
}

// Deploys the zk contract
#[allow(clippy::too_many_arguments)]
async fn deploy_zk<P: Provider<T, AnyNetwork>, T: Transport + Clone>(
self,
abi: JsonAbi,
Expand Down
3 changes: 1 addition & 2 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,8 +1547,7 @@ contract DeployScript is Script {

assert!(cmd.stdout_lossy().contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL"));

let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast"))
.into_iter()
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");

Expand Down
9 changes: 1 addition & 8 deletions crates/forge/tests/it/config.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
//! Test config.
use crate::test_helpers::{COMPILED, COMPILED_ZK, EVM_OPTS, PROJECT, TESTDATA};
use forge::{
result::{SuiteResult, TestStatus},
MultiContractRunner, MultiContractRunnerBuilder, TestOptions, TestOptionsBuilder,
};
use foundry_compilers::ProjectPathsConfig;
use foundry_config::{
fs_permissions::PathPermission, Config, FsPermissions, FuzzConfig, FuzzDictionaryConfig,
InvariantConfig, RpcEndpoint, RpcEndpoints,
MultiContractRunner,
};
use foundry_evm::{
decode::decode_console_logs,
revm::primitives::SpecId,
traces::{render_trace_arena, CallTraceDecoderBuilder},
};
use foundry_test_utils::{init_tracing, Filter};
use foundry_zksync_compiler::DualCompiledContracts;
use futures::future::join_all;
use itertools::Itertools;
use std::collections::BTreeMap;
Expand Down
Loading

0 comments on commit 1b1e9b6

Please sign in to comment.