From 5e5536af94564eadb4a99a6ac7ca2ab9707edb33 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Thu, 19 Dec 2024 16:04:26 +0100 Subject: [PATCH] use Ext trait pattern --- crates/cheatcodes/src/evm/fork.rs | 4 ++-- crates/cheatcodes/src/inspector.rs | 2 +- crates/cheatcodes/src/strategy.rs | 4 ++-- crates/cheatcodes/src/test.rs | 4 +++- crates/evm/core/src/backend/strategy.rs | 4 ++-- crates/evm/evm/src/executors/strategy.rs | 4 ++-- crates/forge/bin/cmd/test/mod.rs | 1 + crates/script/src/lib.rs | 2 +- crates/strategy/zksync/src/cheatcode.rs | 2 +- 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/cheatcodes/src/evm/fork.rs b/crates/cheatcodes/src/evm/fork.rs index 17bb9bacf..583717a61 100644 --- a/crates/cheatcodes/src/evm/fork.rs +++ b/crates/cheatcodes/src/evm/fork.rs @@ -1,6 +1,6 @@ use crate::{ - json::json_value_to_token, Cheatcode, Cheatcodes, CheatcodesExecutor, CheatsCtxt, DatabaseExt, - Result, Vm::*, + json::json_value_to_token, strategy::CheatcodeInspectorStrategyExt, Cheatcode, Cheatcodes, + CheatcodesExecutor, CheatsCtxt, DatabaseExt, Result, Vm::*, }; use alloy_dyn_abi::DynSolValue; use alloy_primitives::{B256, U256}; diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index af90c7a71..ecb14ce03 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -7,7 +7,7 @@ use crate::{ DealRecord, GasRecord, }, script::{Broadcast, Wallets}, - strategy::CheatcodeInspectorStrategy, + strategy::{CheatcodeInspectorStrategy, CheatcodeInspectorStrategyExt}, test::{ assume::AssumeNoRevert, expect::{self, ExpectedEmit, ExpectedRevert, ExpectedRevertKind}, diff --git a/crates/cheatcodes/src/strategy.rs b/crates/cheatcodes/src/strategy.rs index 6a07dc2b1..4d99e860e 100644 --- a/crates/cheatcodes/src/strategy.rs +++ b/crates/cheatcodes/src/strategy.rs @@ -18,7 +18,7 @@ use crate::{ CheatsConfig, CheatsCtxt, Result, }; -pub trait CheatcodeInspectorStrategy: Debug + Send + Sync + CheatcodeInspectorStrategyExt { +pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { fn name(&self) -> &'static str; fn new_cloned(&self) -> Box; @@ -326,7 +326,7 @@ impl CheatcodeInspectorStrategy for EvmCheatcodeInspectorStrategy { } } -impl CheatcodeInspectorStrategyExt for EvmCheatcodeInspectorStrategy {} +impl<'a> CheatcodeInspectorStrategyExt for dyn CheatcodeInspectorStrategy + 'a {} impl Clone for Box { fn clone(&self) -> Self { diff --git a/crates/cheatcodes/src/test.rs b/crates/cheatcodes/src/test.rs index de3f1eb72..63c2830a0 100644 --- a/crates/cheatcodes/src/test.rs +++ b/crates/cheatcodes/src/test.rs @@ -1,6 +1,8 @@ //! Implementations of [`Testing`](spec::Group::Testing) cheatcodes. -use crate::{Cheatcode, Cheatcodes, CheatsCtxt, Result, Vm::*}; +use crate::{ + strategy::CheatcodeInspectorStrategyExt, Cheatcode, Cheatcodes, CheatsCtxt, Result, Vm::*, +}; use alloy_primitives::Address; use alloy_sol_types::SolValue; use chrono::DateTime; diff --git a/crates/evm/core/src/backend/strategy.rs b/crates/evm/core/src/backend/strategy.rs index 18ebe9e6b..d65fa2a51 100644 --- a/crates/evm/core/src/backend/strategy.rs +++ b/crates/evm/core/src/backend/strategy.rs @@ -11,7 +11,7 @@ pub struct BackendStrategyForkInfo<'a> { pub target_type: ForkType, } -pub trait BackendStrategy: Debug + Send + Sync + BackendStrategyExt { +pub trait BackendStrategy: Debug + Send + Sync { fn name(&self) -> &'static str; fn new_cloned(&self) -> Box; @@ -96,7 +96,7 @@ impl BackendStrategy for EvmBackendStrategy { } } -impl BackendStrategyExt for EvmBackendStrategy {} +impl<'a> BackendStrategyExt for dyn BackendStrategy + 'a {} impl EvmBackendStrategy { /// Merges the state of all `accounts` from the currently active db into the given `fork` diff --git a/crates/evm/evm/src/executors/strategy.rs b/crates/evm/evm/src/executors/strategy.rs index 06919d8ae..c4a0e9c04 100644 --- a/crates/evm/evm/src/executors/strategy.rs +++ b/crates/evm/evm/src/executors/strategy.rs @@ -19,7 +19,7 @@ use revm::{ use super::Executor; -pub trait ExecutorStrategy: Debug + Send + Sync + ExecutorStrategyExt { +pub trait ExecutorStrategy: Debug + Send + Sync { fn name(&self) -> &'static str; fn new_cloned(&self) -> Box; @@ -163,4 +163,4 @@ impl ExecutorStrategy for EvmExecutorStrategy { } } -impl ExecutorStrategyExt for EvmExecutorStrategy {} +impl<'a> ExecutorStrategyExt for dyn ExecutorStrategy + 'a {} diff --git a/crates/forge/bin/cmd/test/mod.rs b/crates/forge/bin/cmd/test/mod.rs index 384504bef..586646e58 100644 --- a/crates/forge/bin/cmd/test/mod.rs +++ b/crates/forge/bin/cmd/test/mod.rs @@ -5,6 +5,7 @@ use clap::{Parser, ValueHint}; use eyre::{Context, OptionExt, Result}; use forge::{ decode::decode_console_logs, + executors::strategy::ExecutorStrategyExt, gas_report::GasReport, multi_runner::matches_contract, result::{SuiteResult, TestOutcome, TestStatus}, diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index c56058bc4..258390269 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -47,7 +47,7 @@ use foundry_config::{ use foundry_evm::{ backend::Backend, constants::DEFAULT_CREATE2_DEPLOYER, - executors::ExecutorBuilder, + executors::{strategy::ExecutorStrategyExt, ExecutorBuilder}, inspectors::{ cheatcodes::{BroadcastableTransactions, Wallets}, CheatsConfig, diff --git a/crates/strategy/zksync/src/cheatcode.rs b/crates/strategy/zksync/src/cheatcode.rs index b29f8a741..51480c338 100644 --- a/crates/strategy/zksync/src/cheatcode.rs +++ b/crates/strategy/zksync/src/cheatcode.rs @@ -18,7 +18,7 @@ use foundry_cheatcodes::{ use foundry_common::TransactionMaybeSigned; use foundry_config::fs_permissions::FsAccessKind; use foundry_evm::{ - backend::{DatabaseError, LocalForkId}, + backend::{strategy::BackendStrategyExt, DatabaseError, LocalForkId}, constants::{DEFAULT_CREATE2_DEPLOYER, DEFAULT_CREATE2_DEPLOYER_CODE}, }; use foundry_evm_core::{