From 25d3ce7ca1eed4a9f1776103185e4221e8fa0a11 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 31 Jul 2023 22:56:28 +0200 Subject: [PATCH 1/8] ci: add weekly cargo update workflow (#5497) --- .github/workflows/dependencies.yml | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/dependencies.yml diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml new file mode 100644 index 000000000000..e731a7a56923 --- /dev/null +++ b/.github/workflows/dependencies.yml @@ -0,0 +1,61 @@ +# Automatically run `cargo update` periodically + +name: Update Dependencies + +on: + schedule: + # Run weekly + - cron: "0 0 * * SUN" + workflow_dispatch: + # Needed so we can run it manually + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: cargo-update + TITLE: "chore(deps): weekly `cargo update`" + BODY: | + Automation to keep dependencies in `Cargo.lock` current. + +
cargo update log +

+ + ```log + $cargo_update_log + ``` + +

+
+ +jobs: + update: + name: Update + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + + - name: cargo update + # Remove first line that always just says "Updating crates.io index" + run: cargo update --color never 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log + + - name: craft commit message and PR body + id: msg + run: | + export cargo_update_log="$(cat cargo_update.log)" + + echo "commit_message<> $GITHUB_OUTPUT + printf "$TITLE\n\n$cargo_update_log\n" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + echo "body<> $GITHUB_OUTPUT + echo "$BODY" | envsubst >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + add-paths: ./Cargo.lock + commit-message: ${{ steps.msg.outputs.commit_message }} + title: ${{ env.TITLE }} + body: ${{ steps.msg.outputs.body }} + branch: ${{ env.BRANCH }} From 9a4bb7f54563d73b23b597098dcaf1e590905e85 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov <62447812+klkvr@users.noreply.github.com> Date: Tue, 1 Aug 2023 04:54:20 +0300 Subject: [PATCH 2/8] Add correct processing for non-existent json-keys (#5511) * Add correct processing for non-existent keys * Fix clippy error * chore: include changes in changelog --------- Co-authored-by: Enrique Ortiz --- CHANGELOG.md | 1 + evm/src/executor/inspector/cheatcodes/ext.rs | 4 +++- testdata/cheats/Json.t.sol | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 106dc496a9e8..2d9a4e1a9266 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,3 +34,4 @@ To use the latest pinned nightly on your CI, modify your Foundry installation st - [precompiles will not be compatible with all cheatcodes](https://github.com/foundry-rs/foundry/pull/4905). - The difficulty and prevrandao cheatcodes now [fail if not used with the correct EVM version](https://github.com/foundry-rs/foundry/pull/4904). - The default EVM version will be Shanghai. If you're using an EVM chain which is not compatible with [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855) you need to change your EVM version. See [Matt Solomon's thread](https://twitter.com/msolomon44/status/1656411871635972096) for more information. +- Non-existent JSON keys are now processed correctly, and `parseJson` returns non-decodable empty bytes if they do not exist. https://github.com/foundry-rs/foundry/pull/5511 diff --git a/evm/src/executor/inspector/cheatcodes/ext.rs b/evm/src/executor/inspector/cheatcodes/ext.rs index 73d9420df0f1..d4871cf01d74 100644 --- a/evm/src/executor/inspector/cheatcodes/ext.rs +++ b/evm/src/executor/inspector/cheatcodes/ext.rs @@ -246,7 +246,9 @@ fn canonicalize_json_key(key: &str) -> String { /// Encodes a vector of [`Token`] into a vector of bytes. fn encode_abi_values(values: Vec) -> Vec { - if values.len() == 1 { + if values.is_empty() { + abi::encode(&[Token::Bytes(Vec::new())]) + } else if values.len() == 1 { abi::encode(&[Token::Bytes(abi::encode(&values))]) } else { abi::encode(&[Token::Bytes(abi::encode(&[Token::Array(values)]))]) diff --git a/testdata/cheats/Json.t.sol b/testdata/cheats/Json.t.sol index b4c350135b63..e19bb37db573 100644 --- a/testdata/cheats/Json.t.sol +++ b/testdata/cheats/Json.t.sol @@ -148,6 +148,17 @@ contract ParseJsonTest is DSTest { string memory decodedData = abi.decode(data, (string)); assertEq("hai", decodedData); } + + function test_nonExistentKey() public { + bytes memory data = vm.parseJson(json, ".thisKeyDoesNotExist"); + assertEq(0, data.length); + + data = vm.parseJson(json, ".this.path.does.n.0.t.exist"); + assertEq(0, data.length); + + data = vm.parseJson("", "."); + assertEq(0, data.length); + } } contract WriteJsonTest is DSTest { From 8d342d33c6662a2a9be114957aeba14eadbc6e41 Mon Sep 17 00:00:00 2001 From: Andrew Athan <24279435+aathan@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:42:19 -0700 Subject: [PATCH 3/8] Pass details on GasTooHigh (#5489) * Pass details on GasTooHigh * Update anvil/src/eth/backend/mem/mod.rs * chore: fmt/clippy --------- Co-authored-by: AA Co-authored-by: evalir --- anvil/src/eth/api.rs | 7 ++++--- anvil/src/eth/backend/mem/mod.rs | 6 ++++-- anvil/src/eth/error.rs | 31 ++++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/anvil/src/eth/api.rs b/anvil/src/eth/api.rs index 02f45dbf24b5..be95b7c2f87d 100644 --- a/anvil/src/eth/api.rs +++ b/anvil/src/eth/api.rs @@ -2053,7 +2053,7 @@ impl EthApi { // Exceptional case: init used too much gas, we need to increase the gas limit and try // again - if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh)) = + if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh(_))) = ethres { // if price or limit was included in the request then we can execute the request @@ -2125,8 +2125,9 @@ impl EthApi { // Exceptional case: init used too much gas, we need to increase the gas limit and try // again - if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh)) = - ethres + if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh( + _, + ))) = ethres { // increase the lowest gas limit lowest_gas_limit = mid_gas_limit; diff --git a/anvil/src/eth/backend/mem/mod.rs b/anvil/src/eth/backend/mem/mod.rs index 1f7e1516c004..e8f9b72bf7a8 100644 --- a/anvil/src/eth/backend/mem/mod.rs +++ b/anvil/src/eth/backend/mem/mod.rs @@ -13,7 +13,7 @@ use crate::{ time::{utc_from_secs, TimeManager}, validate::TransactionValidator, }, - error::{BlockchainError, InvalidTransactionError}, + error::{BlockchainError, ErrDetail, InvalidTransactionError}, fees::{FeeDetails, FeeManager}, macros::node_info, pool::transactions::PoolTransaction, @@ -2180,7 +2180,9 @@ impl TransactionValidator for Backend { // Check gas limit, iff block gas limit is set. if !env.cfg.disable_block_gas_limit && tx.gas_limit() > env.block.gas_limit.into() { warn!(target: "backend", "[{:?}] gas too high", tx.hash()); - return Err(InvalidTransactionError::GasTooHigh) + return Err(InvalidTransactionError::GasTooHigh(ErrDetail { + detail: String::from("tx.gas_limit > env.block.gas_limit"), + })) } // check nonce diff --git a/anvil/src/eth/error.rs b/anvil/src/eth/error.rs index 3dbb0fe7f9e0..c45d20bb4b59 100644 --- a/anvil/src/eth/error.rs +++ b/anvil/src/eth/error.rs @@ -119,6 +119,11 @@ pub enum FeeHistoryError { InvalidBlockRange, } +#[derive(Debug)] +pub struct ErrDetail { + pub detail: String, +} + /// An error due to invalid transaction #[derive(thiserror::Error, Debug)] pub enum InvalidTransactionError { @@ -150,8 +155,8 @@ pub enum InvalidTransactionError { #[error("intrinsic gas too low")] GasTooLow, /// returned if the transaction gas exceeds the limit - #[error("intrinsic gas too high")] - GasTooHigh, + #[error("intrinsic gas too high -- {}",.0.detail)] + GasTooHigh(ErrDetail), /// Thrown to ensure no one is able to specify a transaction with a tip higher than the total /// fee cap. #[error("max priority fee per gas higher than max fee per gas")] @@ -185,8 +190,16 @@ impl From for InvalidTransactionError { InvalidTransactionError::TipAboveFeeCap } InvalidTransaction::GasPriceLessThanBasefee => InvalidTransactionError::FeeCapTooLow, - InvalidTransaction::CallerGasLimitMoreThanBlock => InvalidTransactionError::GasTooHigh, - InvalidTransaction::CallGasCostMoreThanGasLimit => InvalidTransactionError::GasTooHigh, + InvalidTransaction::CallerGasLimitMoreThanBlock => { + InvalidTransactionError::GasTooHigh(ErrDetail { + detail: String::from("CallerGasLimitMoreThanBlock"), + }) + } + InvalidTransaction::CallGasCostMoreThanGasLimit => { + InvalidTransactionError::GasTooHigh(ErrDetail { + detail: String::from("CallGasCostMoreThanGasLimit"), + }) + } InvalidTransaction::RejectCallerWithCode => InvalidTransactionError::SenderNoEOA, InvalidTransaction::LackOfFundForGasLimit { .. } => { InvalidTransactionError::InsufficientFunds @@ -272,7 +285,15 @@ impl ToRpcResponseResult for Result { data: serde_json::to_value(data).ok(), } } - InvalidTransactionError::GasTooLow | InvalidTransactionError::GasTooHigh => { + InvalidTransactionError::GasTooLow => { + // + RpcError { + code: ErrorCode::ServerError(-32000), + message: err.to_string().into(), + data: None, + } + } + InvalidTransactionError::GasTooHigh(_) => { // RpcError { code: ErrorCode::ServerError(-32000), From cf03bb666dd670f3d1d720ee225e26ba86798dc5 Mon Sep 17 00:00:00 2001 From: Rahul Ravindran <10168946+ravindranrahul@users.noreply.github.com> Date: Wed, 2 Aug 2023 00:13:32 +0530 Subject: [PATCH 4/8] feat(`forge`) - Test scaffolding (#5495) * feat: #5466 - Test scaffolding * reafactor: removed return * chore: fmt * refactor: named imports * refactor: std::fs -> foundry_common::fs --------- Co-authored-by: Rahul Ravindran Co-authored-by: Enrique Ortiz --- cli/assets/generated/TestTemplate.t.sol | 13 +++++ cli/src/cmd/forge/generate/mod.rs | 71 +++++++++++++++++++++++++ cli/src/cmd/forge/mod.rs | 1 + cli/src/forge.rs | 5 +- cli/src/opts/forge.rs | 5 +- 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 cli/assets/generated/TestTemplate.t.sol create mode 100644 cli/src/cmd/forge/generate/mod.rs diff --git a/cli/assets/generated/TestTemplate.t.sol b/cli/assets/generated/TestTemplate.t.sol new file mode 100644 index 000000000000..468acba01069 --- /dev/null +++ b/cli/assets/generated/TestTemplate.t.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {Test, console2} from "forge-std/Test.sol"; +import {{contract_name}} from "../src/{contract_name}.sol"; + +contract {contract_name}Test is Test { + {contract_name} public {instance_name}; + + function setUp() public { + {instance_name} = new {contract_name}(); + } +} \ No newline at end of file diff --git a/cli/src/cmd/forge/generate/mod.rs b/cli/src/cmd/forge/generate/mod.rs new file mode 100644 index 000000000000..22929f421e56 --- /dev/null +++ b/cli/src/cmd/forge/generate/mod.rs @@ -0,0 +1,71 @@ +//! generate command + +use clap::{Parser, Subcommand}; +use foundry_common::fs; +use std::path::Path; +use yansi::Paint; + +/// CLI arguments for `forge generate`. +#[derive(Debug, Parser)] +pub struct GenerateArgs { + #[clap(subcommand)] + pub sub: GenerateSubcommands, +} + +#[derive(Debug, Subcommand)] +pub enum GenerateSubcommands { + /// Scaffolds test file for given contract. + Test(GenerateTestArgs), +} + +#[derive(Debug, Parser)] +pub struct GenerateTestArgs { + /// Contract name for test generation. + #[clap(long, short, value_name = "CONTRACT_NAME")] + pub contract_name: String, +} + +impl GenerateTestArgs { + pub fn run(self) -> eyre::Result<()> { + let contract_name = format_identifier(&self.contract_name, true); + let instance_name = format_identifier(&self.contract_name, false); + + // Create the test file content. + let test_content = include_str!("../../../../assets/generated/TestTemplate.t.sol"); + let test_content = test_content + .replace("{contract_name}", &contract_name) + .replace("{instance_name}", &instance_name); + + // Create the test directory if it doesn't exist. + fs::create_dir_all("test")?; + + // Define the test file path + let test_file_path = Path::new("test").join(format!("{}.t.sol", contract_name)); + + // Write the test content to the test file. + fs::write(&test_file_path, test_content)?; + + println!("{} test file: {}", Paint::green("Generated"), test_file_path.to_str().unwrap()); + Ok(()) + } +} + +/// Utility function to convert an identifier to pascal or camel case. +fn format_identifier(input: &str, is_pascal_case: bool) -> String { + let mut result = String::new(); + let mut capitalize_next = is_pascal_case; + + for word in input.split_whitespace() { + if !word.is_empty() { + let (first, rest) = word.split_at(1); + let formatted_word = if capitalize_next { + format!("{}{}", first.to_uppercase(), rest) + } else { + format!("{}{}", first.to_lowercase(), rest) + }; + capitalize_next = true; + result.push_str(&formatted_word); + } + } + result +} diff --git a/cli/src/cmd/forge/mod.rs b/cli/src/cmd/forge/mod.rs index 73e694d8bc33..5a1f508e0441 100644 --- a/cli/src/cmd/forge/mod.rs +++ b/cli/src/cmd/forge/mod.rs @@ -51,6 +51,7 @@ pub mod flatten; pub mod fmt; pub mod fourbyte; pub mod geiger; +pub mod generate; pub mod init; pub mod inspect; pub mod install; diff --git a/cli/src/forge.rs b/cli/src/forge.rs index 22f3cfec43a1..efcabad7dc36 100644 --- a/cli/src/forge.rs +++ b/cli/src/forge.rs @@ -2,7 +2,7 @@ use clap::{CommandFactory, Parser}; use clap_complete::generate; use foundry_cli::{ cmd::{ - forge::{cache::CacheSubcommands, watch}, + forge::{cache::CacheSubcommands, generate::GenerateSubcommands, watch}, Cmd, }, handler, @@ -97,5 +97,8 @@ fn main() -> eyre::Result<()> { } Subcommands::Doc(cmd) => cmd.run(), Subcommands::Selectors { command } => utils::block_on(command.run()), + Subcommands::Generate(cmd) => match cmd.sub { + GenerateSubcommands::Test(cmd) => cmd.run(), + }, } } diff --git a/cli/src/opts/forge.rs b/cli/src/opts/forge.rs index a7adf214f611..391c6b783c1e 100644 --- a/cli/src/opts/forge.rs +++ b/cli/src/opts/forge.rs @@ -9,7 +9,7 @@ use crate::cmd::forge::{ flatten, fmt::FmtArgs, fourbyte::UploadSelectorsArgs, - geiger, + geiger, generate, init::InitArgs, inspect, install::InstallArgs, @@ -163,6 +163,9 @@ pub enum Subcommands { #[clap(subcommand)] command: SelectorsSubcommands, }, + + /// Generate scaffold files. + Generate(generate::GenerateArgs), } // A set of solc compiler settings that can be set via command line arguments, which are intended From ca67d15f4abd46394b324c50e21e66f306a1162d Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 1 Aug 2023 16:12:07 -0400 Subject: [PATCH 5/8] fix(`cheatcodes`): disallow using `vm.prank` after `vm.startPrank` (#5520) * chore: disallow using vm.prank after vm.startprank * chore: rename state single call bool * Update evm/src/executor/inspector/cheatcodes/env.rs Co-authored-by: Matt Solomon --------- Co-authored-by: Matt Solomon --- evm/src/executor/inspector/cheatcodes/env.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/evm/src/executor/inspector/cheatcodes/env.rs b/evm/src/executor/inspector/cheatcodes/env.rs index 0746bd407db3..17cd37e7e9b0 100644 --- a/evm/src/executor/inspector/cheatcodes/env.rs +++ b/evm/src/executor/inspector/cheatcodes/env.rs @@ -161,8 +161,11 @@ fn prank( ) -> Result { let prank = Prank::new(prank_caller, prank_origin, new_caller, new_origin, depth, single_call); - if let Some(Prank { used, .. }) = state.prank { + if let Some(Prank { used, single_call: current_single_call, .. }) = state.prank { ensure!(used, "You cannot overwrite `prank` until it is applied at least once"); + // This case can only fail if the user calls `vm.startPrank` and then `vm.prank` later on. + // This should not be possible without first calling `stopPrank` + ensure!(single_call == current_single_call, "You cannot override an ongoing prank with a single vm.prank. Use vm.startPrank to override the current prank."); } ensure!( From 2f61b85b362caebb9b8295bb572e57335f07d90d Mon Sep 17 00:00:00 2001 From: grandizzy <38490174+grandizzy@users.noreply.github.com> Date: Wed, 2 Aug 2023 07:13:12 -0700 Subject: [PATCH 6/8] Invariant testing: read shrink sequence config when assert invariants that aren't broken yet (#5323) * Read shrink sequence config when assert invariants that aren't broken yet * fmt --------- Co-authored-by: evalir --- evm/src/fuzz/invariant/executor.rs | 5 ++++- evm/src/fuzz/invariant/mod.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/evm/src/fuzz/invariant/executor.rs b/evm/src/fuzz/invariant/executor.rs index 2c4652876762..5530f4cd6123 100644 --- a/evm/src/fuzz/invariant/executor.rs +++ b/evm/src/fuzz/invariant/executor.rs @@ -101,6 +101,7 @@ impl<'a> InvariantExecutor<'a> { &blank_executor.borrow(), &[], &mut failures.borrow_mut(), + self.config.shrink_sequence, ) .ok(), ); @@ -576,7 +577,9 @@ fn can_continue( // Assert invariants IFF the call did not revert and the handlers did not fail. if !call_result.reverted && !handlers_failed { - call_results = assert_invariants(invariant_contract, executor, calldata, failures).ok(); + call_results = + assert_invariants(invariant_contract, executor, calldata, failures, shrink_sequence) + .ok(); if call_results.is_none() { return (false, None) } diff --git a/evm/src/fuzz/invariant/mod.rs b/evm/src/fuzz/invariant/mod.rs index 79e428f87b2b..980abe406efc 100644 --- a/evm/src/fuzz/invariant/mod.rs +++ b/evm/src/fuzz/invariant/mod.rs @@ -42,6 +42,7 @@ pub fn assert_invariants( executor: &Executor, calldata: &[BasicTxDetails], invariant_failures: &mut InvariantFailures, + shrink_sequence: bool, ) -> eyre::Result> { let mut found_case = false; let mut inner_sequence = vec![]; @@ -95,7 +96,7 @@ pub fn assert_invariants( calldata, call_result, &inner_sequence, - true, + shrink_sequence, )), ); found_case = true; From d73eea17ddac86227fbc91d30ecce0169c907150 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Wed, 2 Aug 2023 18:12:44 +0300 Subject: [PATCH 7/8] fix(cast): continue execution after preceding reverted transaction (#5523) * fix(cast): continue execution of preceding transactions after revert * chore: clippy * chore: clippy * chore: fmt * chore: clippy --------- Co-authored-by: Enrique Ortiz --- anvil/src/eth/backend/mem/mod.rs | 1 - cli/src/cmd/cast/run.rs | 14 +++++++++++--- cli/src/cmd/forge/install.rs | 4 ++-- cli/src/cmd/forge/script/broadcast.rs | 8 ++++---- cli/src/cmd/forge/script/cmd.rs | 10 ++-------- cli/src/cmd/forge/script/executor.rs | 9 +++------ evm/src/trace/decoder.rs | 6 +----- forge/src/gas_report.rs | 3 +-- 8 files changed, 24 insertions(+), 31 deletions(-) diff --git a/anvil/src/eth/backend/mem/mod.rs b/anvil/src/eth/backend/mem/mod.rs index e8f9b72bf7a8..d453a75ca2da 100644 --- a/anvil/src/eth/backend/mem/mod.rs +++ b/anvil/src/eth/backend/mem/mod.rs @@ -1192,7 +1192,6 @@ impl Backend { } if let Some(fork) = self.get_fork() { - let filter = filter; return Ok(fork.logs(&filter).await?) } diff --git a/cli/src/cmd/cast/run.rs b/cli/src/cmd/cast/run.rs index 4a7a99846522..45836f6f0040 100644 --- a/cli/src/cmd/cast/run.rs +++ b/cli/src/cmd/cast/run.rs @@ -157,9 +157,17 @@ impl RunArgs { })?; } else { trace!(tx=?tx.hash, "executing previous create transaction"); - executor.deploy_with_env(env.clone(), None).wrap_err_with(|| { - format!("Failed to deploy transaction: {:?}", tx.hash()) - })?; + if let Err(error) = executor.deploy_with_env(env.clone(), None) { + match error { + // Reverted transactions should be skipped + EvmError::Execution(_) => (), + error => { + return Err(error).wrap_err_with(|| { + format!("Failed to deploy transaction: {:?}", tx.hash()) + }) + } + } + } } update_progress!(pb, index); diff --git a/cli/src/cmd/forge/install.rs b/cli/src/cmd/forge/install.rs index 728740b32bae..29b25fbe2cad 100644 --- a/cli/src/cmd/forge/install.rs +++ b/cli/src/cmd/forge/install.rs @@ -402,7 +402,7 @@ impl Installer<'_> { let n = if s.is_empty() { Ok(1) } else { s.parse() }; // match user input, 0 indicates skipping and use original tag match n { - Ok(i) if i == 0 => return Ok(tag.into()), + Ok(0) => return Ok(tag.into()), Ok(i) if (1..=n_candidates).contains(&i) => { let c = &candidates[i]; println!("[{i}] {c} selected"); @@ -470,7 +470,7 @@ impl Installer<'_> { // match user input, 0 indicates skipping and use original tag match input.parse::() { - Ok(i) if i == 0 => Ok(Some(tag.into())), + Ok(0) => Ok(Some(tag.into())), Ok(i) if (1..=n_candidates).contains(&i) => { let c = &candidates[i]; println!("[{i}] {c} selected"); diff --git a/cli/src/cmd/forge/script/broadcast.rs b/cli/src/cmd/forge/script/broadcast.rs index 320eeb308ec9..462f3d72e849 100644 --- a/cli/src/cmd/forge/script/broadcast.rs +++ b/cli/src/cmd/forge/script/broadcast.rs @@ -263,7 +263,7 @@ impl ScriptArgs { &self, mut result: ScriptResult, libraries: Libraries, - decoder: &mut CallTraceDecoder, + decoder: &CallTraceDecoder, mut script_config: ScriptConfig, verify: VerifyBundle, ) -> Result<()> { @@ -360,7 +360,7 @@ impl ScriptArgs { txs: BroadcastableTransactions, script_result: &ScriptResult, script_config: &mut ScriptConfig, - decoder: &mut CallTraceDecoder, + decoder: &CallTraceDecoder, known_contracts: &ContractsByArtifact, ) -> Result> { if !txs.is_empty() { @@ -391,8 +391,8 @@ impl ScriptArgs { async fn fills_transactions_with_gas( &self, txs: BroadcastableTransactions, - script_config: &mut ScriptConfig, - decoder: &mut CallTraceDecoder, + script_config: &ScriptConfig, + decoder: &CallTraceDecoder, known_contracts: &ContractsByArtifact, ) -> Result> { let gas_filled_txs = if self.skip_simulation { diff --git a/cli/src/cmd/forge/script/cmd.rs b/cli/src/cmd/forge/script/cmd.rs index 2b5dd924b77c..df447a12a60a 100644 --- a/cli/src/cmd/forge/script/cmd.rs +++ b/cli/src/cmd/forge/script/cmd.rs @@ -119,14 +119,8 @@ impl ScriptArgs { verify.known_contracts = flatten_contracts(&highlevel_known_contracts, false); self.check_contract_sizes(&result, &highlevel_known_contracts)?; - self.handle_broadcastable_transactions( - result, - libraries, - &mut decoder, - script_config, - verify, - ) - .await + self.handle_broadcastable_transactions(result, libraries, &decoder, script_config, verify) + .await } // In case there are libraries to be deployed, it makes sure that these are added to the list of diff --git a/cli/src/cmd/forge/script/executor.rs b/cli/src/cmd/forge/script/executor.rs index c803a8d37201..974ce9b516bd 100644 --- a/cli/src/cmd/forge/script/executor.rs +++ b/cli/src/cmd/forge/script/executor.rs @@ -95,8 +95,8 @@ impl ScriptArgs { pub async fn onchain_simulation( &self, transactions: BroadcastableTransactions, - script_config: &mut ScriptConfig, - decoder: &mut CallTraceDecoder, + script_config: &ScriptConfig, + decoder: &CallTraceDecoder, contracts: &ContractsByArtifact, ) -> eyre::Result> { trace!(target: "script", "executing onchain simulation"); @@ -247,10 +247,7 @@ impl ScriptArgs { } /// Build the multiple runners from different forks. - async fn build_runners( - &self, - script_config: &mut ScriptConfig, - ) -> HashMap { + async fn build_runners(&self, script_config: &ScriptConfig) -> HashMap { let sender = script_config.evm_opts.sender; if !shell::verbosity().is_silent() { diff --git a/evm/src/trace/decoder.rs b/evm/src/trace/decoder.rs index db90cd3c0002..f8e8ae651a1c 100644 --- a/evm/src/trace/decoder.rs +++ b/evm/src/trace/decoder.rs @@ -202,11 +202,7 @@ impl CallTraceDecoder { // Flatten errors from all ABIs abi.errors().for_each(|error| { - let entry = self - .errors - .errors - .entry(error.name.clone()) - .or_insert_with(Default::default); + let entry = self.errors.errors.entry(error.name.clone()).or_default(); entry.push(error.clone()); }); diff --git a/forge/src/gas_report.rs b/forge/src/gas_report.rs index 9ac5eae695e2..d610a19190a6 100644 --- a/forge/src/gas_report.rs +++ b/forge/src/gas_report.rs @@ -69,8 +69,7 @@ impl GasReport { (!self.ignore.contains(&contract_name) && self.report_for.is_empty()) || (self.report_for.contains(&contract_name)); if report_contract { - let contract_report = - self.contracts.entry(name.to_string()).or_insert_with(Default::default); + let contract_report = self.contracts.entry(name.to_string()).or_default(); match &trace.data { RawOrDecodedCall::Raw(bytes) if trace.created() => { From e05b9c75b4501d5880764948b61db787f3dd7fe0 Mon Sep 17 00:00:00 2001 From: Andrew Athan <24279435+aathan@users.noreply.github.com> Date: Wed, 2 Aug 2023 09:04:31 -0700 Subject: [PATCH 8/8] logs member name changed to logger when referring to LogCollector inspector (#5498) * logs to logger when referring to LogCollector inspector * missing file * chore: rename to log collector --------- Co-authored-by: AA Co-authored-by: Enrique Ortiz --- anvil/src/eth/backend/mem/inspector.rs | 8 ++++---- evm/src/executor/inspector/mod.rs | 2 +- evm/src/executor/inspector/stack.rs | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/anvil/src/eth/backend/mem/inspector.rs b/anvil/src/eth/backend/mem/inspector.rs index d515b945c699..17f123125787 100644 --- a/anvil/src/eth/backend/mem/inspector.rs +++ b/anvil/src/eth/backend/mem/inspector.rs @@ -23,7 +23,7 @@ pub struct Inspector { pub gas: Option>>, pub tracer: Option, /// collects all `console.sol` logs - pub logs: LogCollector, + pub log_collector: LogCollector, } // === impl Inspector === @@ -33,7 +33,7 @@ impl Inspector { /// /// This will log all `console.sol` logs pub fn print_logs(&self) { - print_logs(&self.logs.logs) + print_logs(&self.log_collector.logs) } /// Configures the `Tracer` [`revm::Inspector`] @@ -99,7 +99,7 @@ impl revm::Inspector for Inspector { [ &mut self.gas.as_deref().map(|gas| gas.borrow_mut()), &mut self.tracer, - Some(&mut self.logs) + Some(&mut self.log_collector) ], { inspector.log(evm_data, address, topics, data); @@ -135,7 +135,7 @@ impl revm::Inspector for Inspector { [ &mut self.gas.as_deref().map(|gas| gas.borrow_mut()), &mut self.tracer, - Some(&mut self.logs) + Some(&mut self.log_collector) ], { inspector.call(data, call, is_static); diff --git a/evm/src/executor/inspector/mod.rs b/evm/src/executor/inspector/mod.rs index 74ab7da036d0..f4e5dd8c5acb 100644 --- a/evm/src/executor/inspector/mod.rs +++ b/evm/src/executor/inspector/mod.rs @@ -75,7 +75,7 @@ impl InspectorStackConfig { /// See also [`revm::Evm::inspect_ref`] and [`revm::Evm::commit_ref`] pub fn stack(&self) -> InspectorStack { let mut stack = - InspectorStack { logs: Some(LogCollector::default()), ..Default::default() }; + InspectorStack { log_collector: Some(LogCollector::default()), ..Default::default() }; stack.cheatcodes = self.create_cheatcodes(); if let Some(ref mut cheatcodes) = stack.cheatcodes { diff --git a/evm/src/executor/inspector/stack.rs b/evm/src/executor/inspector/stack.rs index 898ca459737f..2a3763ce5392 100644 --- a/evm/src/executor/inspector/stack.rs +++ b/evm/src/executor/inspector/stack.rs @@ -52,7 +52,7 @@ pub struct InspectorData { #[derive(Default)] pub struct InspectorStack { pub tracer: Option, - pub logs: Option, + pub log_collector: Option, pub cheatcodes: Option, pub gas: Option>>, pub debugger: Option, @@ -65,7 +65,7 @@ pub struct InspectorStack { impl InspectorStack { pub fn collect_inspector_states(self) -> InspectorData { InspectorData { - logs: self.logs.map(|logs| logs.logs).unwrap_or_default(), + logs: self.log_collector.map(|logs| logs.logs).unwrap_or_default(), labels: self .cheatcodes .as_ref() @@ -102,7 +102,7 @@ impl InspectorStack { &mut self.debugger, &mut self.tracer, &mut self.coverage, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer ], @@ -147,7 +147,7 @@ where &mut self.debugger, &mut self.coverage, &mut self.tracer, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer ], @@ -178,7 +178,7 @@ where &mut self.debugger, &mut self.tracer, &mut self.coverage, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer ], @@ -204,7 +204,7 @@ where ) { call_inspectors!( inspector, - [&mut self.tracer, &mut self.logs, &mut self.cheatcodes, &mut self.printer], + [&mut self.tracer, &mut self.log_collector, &mut self.cheatcodes, &mut self.printer], { inspector.log(evm_data, address, topics, data); } @@ -224,7 +224,7 @@ where &mut self.gas.as_deref().map(|gas| gas.borrow_mut()), &mut self.debugger, &mut self.tracer, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer, &mut self.chisel_state @@ -256,7 +256,7 @@ where &mut self.debugger, &mut self.tracer, &mut self.coverage, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer ], @@ -308,7 +308,7 @@ where &mut self.debugger, &mut self.tracer, &mut self.coverage, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer ], @@ -341,7 +341,7 @@ where &mut self.debugger, &mut self.tracer, &mut self.coverage, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer ], @@ -370,7 +370,7 @@ where [ &mut self.debugger, &mut self.tracer, - &mut self.logs, + &mut self.log_collector, &mut self.cheatcodes, &mut self.printer, &mut self.chisel_state