Skip to content

Commit

Permalink
chore: remove JsonAbi import renames (#6737)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jan 9, 2024
1 parent 71d8ea5 commit 0792dc7
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 58 deletions.
8 changes: 4 additions & 4 deletions crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_json_abi::JsonAbi as Abi;
use alloy_json_abi::JsonAbi;
use alloy_primitives::Address;
use eyre::{Result, WrapErr};
use foundry_common::{cli_warn, fs, TestFunctionExt};
Expand Down Expand Up @@ -29,7 +29,7 @@ use yansi::Paint;
pub fn remove_contract(
output: &mut ProjectCompileOutput,
info: &ContractInfo,
) -> Result<(Abi, CompactBytecode, CompactDeployedBytecode)> {
) -> Result<(JsonAbi, CompactBytecode, CompactDeployedBytecode)> {
let contract = if let Some(contract) = output.remove_contract(info) {
contract
} else {
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn get_cached_entry_by_name(
}

/// Returns error if constructor has arguments.
pub fn ensure_clean_constructor(abi: &Abi) -> Result<()> {
pub fn ensure_clean_constructor(abi: &JsonAbi) -> Result<()> {
if let Some(constructor) = &abi.constructor {
if !constructor.inputs.is_empty() {
eyre::bail!("Contract constructor should have no arguments. Add those arguments to `run(...)` instead, and call it with `--sig run(...)`.");
Expand All @@ -117,7 +117,7 @@ pub fn ensure_clean_constructor(abi: &Abi) -> Result<()> {
Ok(())
}

pub fn needs_setup(abi: &Abi) -> bool {
pub fn needs_setup(abi: &JsonAbi) -> bool {
let setup_fns: Vec<_> = abi.functions().filter(|func| func.name.is_setup()).collect();

for setup_fn in setup_fns.iter() {
Expand Down
16 changes: 8 additions & 8 deletions crates/common/src/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Commonly used contract types and functions.

use alloy_json_abi::{Event, Function, JsonAbi as Abi};
use alloy_json_abi::{Event, Function, JsonAbi};
use alloy_primitives::{hex, Address, B256};
use foundry_compilers::{
artifacts::{CompactContractBytecode, ContractBytecodeSome},
Expand All @@ -14,11 +14,11 @@ use std::{
path::PathBuf,
};

type ArtifactWithContractRef<'a> = (&'a ArtifactId, &'a (Abi, Vec<u8>));
type ArtifactWithContractRef<'a> = (&'a ArtifactId, &'a (JsonAbi, Vec<u8>));

/// Wrapper type that maps an artifact to a contract ABI and bytecode.
#[derive(Clone, Default)]
pub struct ContractsByArtifact(pub BTreeMap<ArtifactId, (Abi, Vec<u8>)>);
pub struct ContractsByArtifact(pub BTreeMap<ArtifactId, (JsonAbi, Vec<u8>)>);

impl ContractsByArtifact {
/// Finds a contract which has a similar bytecode as `code`.
Expand All @@ -44,7 +44,7 @@ impl ContractsByArtifact {
}

/// Flattens a group of contracts into maps of all events and functions
pub fn flatten(&self) -> (BTreeMap<[u8; 4], Function>, BTreeMap<B256, Event>, Abi) {
pub fn flatten(&self) -> (BTreeMap<[u8; 4], Function>, BTreeMap<B256, Event>, JsonAbi) {
let flattened_funcs: BTreeMap<[u8; 4], Function> = self
.iter()
.flat_map(|(_name, (abi, _code))| {
Expand All @@ -64,7 +64,7 @@ impl ContractsByArtifact {
.collect();

// We need this for better revert decoding, and want it in abi form
let mut errors_abi = Abi::default();
let mut errors_abi = JsonAbi::default();
self.iter().for_each(|(_name, (abi, _code))| {
abi.errors().for_each(|error| {
let entry =
Expand All @@ -77,7 +77,7 @@ impl ContractsByArtifact {
}

impl Deref for ContractsByArtifact {
type Target = BTreeMap<ArtifactId, (Abi, Vec<u8>)>;
type Target = BTreeMap<ArtifactId, (JsonAbi, Vec<u8>)>;

fn deref(&self) -> &Self::Target {
&self.0
Expand All @@ -91,7 +91,7 @@ impl DerefMut for ContractsByArtifact {
}

/// Wrapper type that maps an address to a contract identifier and contract ABI.
pub type ContractsByAddress = BTreeMap<Address, (String, Abi)>;
pub type ContractsByAddress = BTreeMap<Address, (String, JsonAbi)>;

/// Very simple fuzzy matching of contract bytecode.
///
Expand All @@ -113,7 +113,7 @@ pub fn diff_score(a: &[u8], b: &[u8]) -> f64 {
diff_chars as f64 / cutoff_len as f64
}

/// Flattens the contracts into (`id` -> (`Abi`, `Vec<u8>`)) pairs
/// Flattens the contracts into (`id` -> (`JsonAbi`, `Vec<u8>`)) pairs
pub fn flatten_contracts(
contracts: &BTreeMap<ArtifactId, ContractBytecodeSome>,
deployed_code: bool,
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/evm/src/executors/fuzz/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::executors::{Executor, RawCallResult};
use alloy_dyn_abi::JsonAbiExt;
use alloy_json_abi::{Function, JsonAbi as Abi};
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Bytes, U256};
use eyre::Result;
use foundry_config::FuzzConfig;
Expand Down Expand Up @@ -60,7 +60,7 @@ impl FuzzedExecutor {
func: &Function,
address: Address,
should_fail: bool,
errors: Option<&Abi>,
errors: Option<&JsonAbi>,
) -> FuzzTestResult {
// Stores the first Fuzzcase
let first_case: RefCell<Option<FuzzCase>> = RefCell::default();
Expand Down
12 changes: 6 additions & 6 deletions crates/evm/evm/src/executors/invariant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
inspectors::Fuzzer,
};
use alloy_dyn_abi::DynSolValue;
use alloy_json_abi::JsonAbi as Abi;
use alloy_json_abi::JsonAbi;
use alloy_primitives::{Address, FixedBytes, U256};
use eyre::{eyre, ContextCompat, Result};
use foundry_common::contracts::{ContractsByAddress, ContractsByArtifact};
Expand Down Expand Up @@ -324,7 +324,7 @@ impl<'a> InvariantExecutor<'a> {
pub fn select_contract_artifacts(
&mut self,
invariant_address: Address,
abi: &Abi,
abi: &JsonAbi,
) -> eyre::Result<()> {
// targetArtifactSelectors -> (string, bytes4[])[].
let targeted_abi = self
Expand Down Expand Up @@ -450,7 +450,7 @@ impl<'a> InvariantExecutor<'a> {
pub fn select_contracts_and_senders(
&self,
invariant_address: Address,
abi: &Abi,
abi: &JsonAbi,
) -> eyre::Result<(SenderFilters, TargetedContracts)> {
let [targeted_senders, excluded_senders, selected, excluded] =
["targetSenders", "excludeSenders", "targetContracts", "excludeContracts"].map(
Expand Down Expand Up @@ -497,7 +497,7 @@ impl<'a> InvariantExecutor<'a> {
pub fn target_interfaces(
&self,
invariant_address: Address,
abi: &Abi,
abi: &JsonAbi,
targeted_contracts: &mut TargetedContracts,
) -> eyre::Result<()> {
let interfaces = self.get_list::<(Address, Vec<String>)>(
Expand Down Expand Up @@ -570,7 +570,7 @@ impl<'a> InvariantExecutor<'a> {
pub fn select_selectors(
&self,
address: Address,
abi: &Abi,
abi: &JsonAbi,
targeted_contracts: &mut TargetedContracts,
) -> eyre::Result<()> {
// `targetArtifactSelectors() -> (string, bytes4[])[]`.
Expand Down Expand Up @@ -661,7 +661,7 @@ impl<'a> InvariantExecutor<'a> {
fn get_list<T>(
&self,
address: Address,
abi: &Abi,
abi: &JsonAbi,
method_name: &str,
f: fn(DynSolValue) -> Vec<T>,
) -> Vec<T> {
Expand Down
14 changes: 7 additions & 7 deletions crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::inspectors::{
cheatcodes::BroadcastableTransactions, Cheatcodes, InspectorData, InspectorStack,
};
use alloy_dyn_abi::{DynSolValue, FunctionExt, JsonAbiExt};
use alloy_json_abi::{Function, JsonAbi as Abi};
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Bytes, U256};
use ethers_core::types::Log;
use ethers_signers::LocalWallet;
Expand Down Expand Up @@ -223,7 +223,7 @@ impl Executor {
func: F,
args: T,
value: U256,
abi: Option<&Abi>,
abi: Option<&JsonAbi>,
) -> Result<CallResult, EvmError> {
let func = func.into();
let calldata = Bytes::from(func.abi_encode_input(&args.into())?.to_vec());
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Executor {
func: F,
args: T,
value: U256,
abi: Option<&Abi>,
abi: Option<&JsonAbi>,
) -> Result<CallResult, EvmError> {
let func = func.into();
let calldata = Bytes::from(func.abi_encode_input(&args.into())?.to_vec());
Expand All @@ -276,7 +276,7 @@ impl Executor {
func: F,
args: T,
value: U256,
abi: Option<&Abi>,
abi: Option<&JsonAbi>,
) -> Result<CallResult, EvmError> {
let func = func.into();
let calldata = Bytes::from(func.abi_encode_input(&args.into())?.to_vec());
Expand Down Expand Up @@ -353,7 +353,7 @@ impl Executor {
pub fn deploy_with_env(
&mut self,
env: Env,
abi: Option<&Abi>,
abi: Option<&JsonAbi>,
) -> Result<DeployResult, EvmError> {
debug_assert!(
matches!(env.tx.transact_to, TransactTo::Create(_)),
Expand Down Expand Up @@ -442,7 +442,7 @@ impl Executor {
from: Address,
code: Bytes,
value: U256,
abi: Option<&Abi>,
abi: Option<&JsonAbi>,
) -> Result<DeployResult, EvmError> {
let env = self.build_test_env(from, TransactTo::Create(CreateScheme::Create), code, value);
self.deploy_with_env(env, abi)
Expand Down Expand Up @@ -825,7 +825,7 @@ fn convert_executed_result(
}

fn convert_call_result(
abi: Option<&Abi>,
abi: Option<&JsonAbi>,
func: &Function,
call_result: RawCallResult,
) -> Result<CallResult, EvmError> {
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/fuzz/src/invariant/filters.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_json_abi::{Function, JsonAbi as Abi};
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Selector};
use foundry_compilers::ArtifactId;
use foundry_evm_core::utils::get_function;
Expand All @@ -23,7 +23,7 @@ impl ArtifactFilters {
pub fn get_targeted_functions(
&self,
artifact: &ArtifactId,
abi: &Abi,
abi: &JsonAbi,
) -> eyre::Result<Option<Vec<Function>>> {
if let Some(selectors) = self.targeted.get(&artifact.identifier()) {
let functions = selectors
Expand Down
8 changes: 4 additions & 4 deletions crates/evm/fuzz/src/invariant/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_json_abi::{Function, JsonAbi as Abi};
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Bytes};
use parking_lot::Mutex;
use std::{collections::BTreeMap, sync::Arc};
Expand All @@ -9,7 +9,7 @@ pub use call_override::RandomCallGenerator;
mod filters;
pub use filters::{ArtifactFilters, SenderFilters};

pub type TargetedContracts = BTreeMap<Address, (String, Abi, Vec<Function>)>;
pub type TargetedContracts = BTreeMap<Address, (String, JsonAbi, Vec<Function>)>;
pub type FuzzRunIdentifiedContracts = Arc<Mutex<TargetedContracts>>;

/// (Sender, (TargetContract, Calldata))
Expand All @@ -22,6 +22,6 @@ pub struct InvariantContract<'a> {
pub address: Address,
/// Invariant function present in the test contract.
pub invariant_function: &'a Function,
/// Abi of the test contract.
pub abi: &'a Abi,
/// ABI of the test contract.
pub abi: &'a JsonAbi,
}
9 changes: 6 additions & 3 deletions crates/evm/fuzz/src/strategies/invariants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
invariant::{BasicTxDetails, FuzzRunIdentifiedContracts, SenderFilters},
strategies::{fuzz_calldata, fuzz_calldata_from_state, fuzz_param, EvmFuzzState},
};
use alloy_json_abi::{Function, JsonAbi as Abi};
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Bytes};
use parking_lot::RwLock;
use proptest::prelude::*;
Expand Down Expand Up @@ -119,7 +119,7 @@ fn select_random_sender(
/// Strategy to randomly select a contract from the `contracts` list that has at least 1 function
fn select_random_contract(
contracts: FuzzRunIdentifiedContracts,
) -> impl Strategy<Value = (Address, Abi, Vec<Function>)> {
) -> impl Strategy<Value = (Address, JsonAbi, Vec<Function>)> {
let selectors = any::<prop::sample::Selector>();
selectors.prop_map(move |selector| {
let contracts = contracts.lock();
Expand All @@ -133,7 +133,10 @@ fn select_random_contract(
///
/// If `targeted_functions` is not empty, select one from it. Otherwise, take any
/// of the available abi functions.
fn select_random_function(abi: Abi, targeted_functions: Vec<Function>) -> BoxedStrategy<Function> {
fn select_random_function(
abi: JsonAbi,
targeted_functions: Vec<Function>,
) -> BoxedStrategy<Function> {
let selectors = any::<prop::sample::Selector>();
let possible_funcs: Vec<Function> = abi
.functions()
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
CallTrace, CallTraceArena, DecodedCallData, DecodedCallLog, DecodedCallTrace,
};
use alloy_dyn_abi::{DecodedEvent, DynSolValue, EventExt, FunctionExt, JsonAbiExt};
use alloy_json_abi::{Event, Function, JsonAbi as Abi};
use alloy_json_abi::{Event, Function, JsonAbi};
use alloy_primitives::{Address, Log, Selector, B256};
use foundry_common::{abi::get_indexed_event, fmt::format_token, SELECTOR_LEN};
use foundry_evm_core::{
Expand Down Expand Up @@ -114,7 +114,7 @@ pub struct CallTraceDecoder {
/// All known events.
pub events: BTreeMap<(B256, usize), Vec<Event>>,
/// All known errors.
pub errors: Abi,
pub errors: JsonAbi,
/// A signature identifier for events and functions.
pub signature_identifier: Option<SingleSignaturesIdentifier>,
/// Verbosity level
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/traces/src/identifier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_json_abi::JsonAbi as Abi;
use alloy_json_abi::JsonAbi;
use alloy_primitives::Address;
use foundry_compilers::ArtifactId;
use std::borrow::Cow;
Expand All @@ -23,7 +23,7 @@ pub struct AddressIdentity<'a> {
/// Note: This may be in the format `"<artifact>:<contract>"`.
pub contract: Option<String>,
/// The ABI of the contract at this address
pub abi: Option<Cow<'a, Abi>>,
pub abi: Option<Cow<'a, JsonAbi>>,
/// The artifact ID of the contract, if any.
pub artifact_id: Option<ArtifactId>,
}
Expand Down
10 changes: 5 additions & 5 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{retry::RetryArgs, verify};
use alloy_dyn_abi::{DynSolValue, JsonAbiExt, ResolveSolType};
use alloy_json_abi::{Constructor, JsonAbi as Abi};
use alloy_json_abi::{Constructor, JsonAbi};
use alloy_primitives::{Address, Bytes};
use clap::{Parser, ValueHint};
use ethers_contract::ContractError;
Expand Down Expand Up @@ -204,7 +204,7 @@ impl CreateArgs {
/// Deploys the contract
async fn deploy<M: Middleware + 'static>(
self,
abi: Abi,
abi: JsonAbi,
bin: BytecodeObject,
args: Vec<DynSolValue>,
provider: M,
Expand Down Expand Up @@ -407,7 +407,7 @@ impl<B, M, C> From<Deployer<B, M>> for ContractDeploymentTx<B, M, C> {
pub struct Deployer<B, M> {
/// The deployer's transaction, exposed for overriding the defaults
pub tx: TypedTransaction,
abi: Abi,
abi: JsonAbi,
client: B,
confs: usize,
block: BlockNumber,
Expand Down Expand Up @@ -513,7 +513,7 @@ where
#[derive(Debug)]
pub struct DeploymentTxFactory<B, M> {
client: B,
abi: Abi,
abi: JsonAbi,
bytecode: Bytes,
_m: PhantomData<M>,
}
Expand All @@ -540,7 +540,7 @@ where
/// Creates a factory for deployment of the Contract with bytecode, and the
/// constructor defined in the abi. The client will be used to send any deployment
/// transaction.
pub fn new(abi: Abi, bytecode: Bytes, client: B) -> Self {
pub fn new(abi: JsonAbi, bytecode: Bytes, client: B) -> Self {
Self { client, abi, bytecode, _m: PhantomData }
}

Expand Down
4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/script/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use self::{build::BuildOutput, runner::ScriptRunner};
use super::{build::BuildArgs, retry::RetryArgs};
use alloy_dyn_abi::FunctionExt;
use alloy_json_abi::{Function, InternalType, JsonAbi as Abi};
use alloy_json_abi::{Function, InternalType, JsonAbi};
use alloy_primitives::{Address, Bytes, U256};
use clap::{Parser, ValueHint};
use dialoguer::Confirm;
Expand Down Expand Up @@ -439,7 +439,7 @@ impl ScriptArgs {
/// corresponding function by matching the selector, first 4 bytes in the calldata.
///
/// Note: We assume that the `sig` is already stripped of its prefix, See [`ScriptArgs`]
fn get_method_and_calldata(&self, abi: &Abi) -> Result<(Function, Bytes)> {
fn get_method_and_calldata(&self, abi: &JsonAbi) -> Result<(Function, Bytes)> {
let (func, data) = if let Ok(func) = get_func(&self.sig) {
(
abi.functions().find(|&abi_func| abi_func.selector() == func.selector()).wrap_err(
Expand Down
Loading

0 comments on commit 0792dc7

Please sign in to comment.